Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into title_directive_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
trollfot committed Apr 6, 2020
2 parents 7b18b5e + d3d7d5e commit 4bae046
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 8 deletions.
9 changes: 8 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
CHANGES
*******

1.4 (unreleased)
1.5 (unreleased)
================

- Nothing changed yet.


1.4 (2020-02-23)
================

- Check for ``builtins`` (Python 3) everywhere that we check for
``__builtin__`` (Python 2).


1.3.post1 (2019-03-14)
======================

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def read(*rnames):

setup(
name='martian',
version='1.4.dev0',
version='1.5.dev0',
url='https://github.com/zopefoundation/martian',
author='Grok project',
author_email='grok-dev@zope.org',
Expand Down
10 changes: 5 additions & 5 deletions src/martian/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,11 @@ def getAnnotation(self, key, default):

def module_info_from_dotted_name(
dotted_name, exclude_filter=None, ignore_nonsource=True):
if dotted_name == '__builtin__':
# in case of the use of individually grokking something during a
# test the dotted_name being passed in could be __builtin__
# in this case we return a special ModuleInfo that just
# implements enough interface to work
if dotted_name in {'__builtin__', 'builtins'}:
# In case of the use of individually grokking something during a
# test the dotted_name being passed in could be __builtin__ (Python
# 2) or builtins (Python 3). In this case we return a special
# ModuleInfo that just implements enough interface to work.
return BuiltinModuleInfo()
module = resolve(dotted_name)
return ModuleInfo(module.__file__, dotted_name, exclude_filter,
Expand Down
32 changes: 32 additions & 0 deletions src/martian/scan.rst
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,35 @@ However, if ``ignore_nonsource=False`` is passed to
<ModuleInfo object for 'martian.tests.withpyconly.subpackage'>]
>>> # rename back to normal name
>>> os.rename(os.path.join(d, 'foo.py_aside'), os.path.join(d, 'foo.py'))

The built-in module
-------------------

We might be asked to grok the built-in module (``__builtin__`` on Python 2,
or ``builtins`` on Python 3). For example, this can happen when grokking a
component defined in a doctest using ``grokcore.component``. The built-in
module doesn't have a file, so we can't do things in the usual way; instead,
we return a special object implementing just enough of the ``IModuleInfo``
interface to work.

>>> import sys
>>> module_info = module_info_from_dotted_name(
... 'builtins' if sys.version_info[0] >= 3 else '__builtin__')

>>> module_info.getModule()
<martian.scan.BuiltinDummyModule object at ...>

>>> module_info.isPackage()
False

>>> module_info.getSubModuleInfos()
[]

>>> print(module_info.getSubModuleInfo('anything'))
None

>>> print(module_info.getResourcePath('anything'))
None

>>> module_info.getAnnotation('grok.foobar', 42)
42
2 changes: 1 addition & 1 deletion src/martian/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def fake_import(fake_module):
__module__ = obj.__module__
except AttributeError:
pass
if __module__ is None or __module__ == '__builtin__':
if __module__ is None or __module__ in {'__builtin__', 'builtins'}:
try:
obj.__module__ = module.__name__
except AttributeError:
Expand Down

0 comments on commit 4bae046

Please sign in to comment.