Skip to content

Commit

Permalink
Merge pull request #8 from zopefoundation/martian-ignore
Browse files Browse the repository at this point in the history
Add an ignore directive.
  • Loading branch information
thefunny42 authored May 9, 2018
2 parents 0602a84 + b6753ad commit 7092898
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
10 changes: 8 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ CHANGES
1.2 (unreleased)
================

- Nothing changed yet.
- Add a new directive ``martian.ignore()`` to explicitly not grok
something in a module::

class Example:
pass

martian.ignore('Example')


1.1 (2018-01-25)
Expand All @@ -13,7 +19,7 @@ CHANGES
- Bypass bootstrap, add coverage to tox

- Fix ``inspect.getargspec()`` deprecation in python3


1.0 (2017-10-19)
================
Expand Down
1 change: 1 addition & 0 deletions src/martian/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
from martian.directive import (
validateText, validateInterface, validateClass, validateInterfaceOrClass)
from martian.martiandirective import component, directive, priority, baseclass
from martian.martiandirective import ignore
from martian.context import GetDefaultComponentFactory
6 changes: 4 additions & 2 deletions src/martian/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def _grokker_sort_key(args):
"""
grokker, name, obj = args
return priority.bind().get(grokker)

class ModuleGrokker(MultiGrokkerBase):

def __init__(self, grokker=None, prepare=None, finalize=None):
Expand Down Expand Up @@ -90,9 +90,11 @@ def grokkers(self, name, module):
for t in grokker.grokkers(name, module):
yield t

ignores = getattr(module, 'martian.martiandirective.ignore', [])

# try to grok everything in module
for name in dir(module):
if '.' in name:
if '.' in name or name in ignores:
# This must be a module-level variable that couldn't
# have been set by the developer. It must have been a
# module-level directive.
Expand Down
8 changes: 7 additions & 1 deletion src/martian/martiandirective.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

from martian.directive import (Directive, MultipleTimesDirective,
MarkerDirective, validateClass,
CLASS, ONCE, ONCE_NOBASE)
CLASS, MODULE, ONCE, ONCE_NOBASE, MULTIPLE)
from martian.error import GrokImportError


class component(Directive):
scope = CLASS
store = ONCE
Expand Down Expand Up @@ -43,3 +44,8 @@ class instead.
"""
scope = CLASS
store = ONCE_NOBASE


class ignore(Directive):
scope = MODULE
store = MULTIPLE

0 comments on commit 7092898

Please sign in to comment.