Skip to content

Commit

Permalink
Merge pull request #97 from sinoroc/make-chameleon-optional
Browse files Browse the repository at this point in the history
Make chameleon optional
  • Loading branch information
wichert authored Nov 10, 2019
2 parents b7f8326 + f4f9bde commit bbd5eb7
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ python:
- "3.7"
- pypy
install:
- pip install -e '.[tests]'
- pip install -e '.[tests,chameleonextractor]'
script: py.test tests
12 changes: 7 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
install_requires = [
'setuptools',
'polib',
'Chameleon',
]

tests_require = [
Expand Down Expand Up @@ -65,7 +64,10 @@ def run_tests(self):
zip_safe=True,
install_requires=install_requires,
tests_require=tests_require,
extras_require={'tests': tests_require},
extras_require={
'tests': tests_require,
'chameleonextractor': ['Chameleon'],
},
cmdclass={'test': PyTest},
entry_points='''
[console_scripts]
Expand All @@ -74,9 +76,9 @@ def run_tests(self):
[lingua.extractors]
python = lingua.extractors.python:PythonExtractor
chameleon = lingua.extractors.xml:ChameleonExtractor
xml = lingua.extractors.xml:ChameleonExtractor
zope = lingua.extractors.xml:ZopeExtractor
chameleon = lingua.extractors.xml:ChameleonExtractor [chameleonextractor]
xml = lingua.extractors.xml:ChameleonExtractor [chameleonextractor]
zope = lingua.extractors.xml:ZopeExtractor [chameleonextractor]
zcml = lingua.extractors.zcml:ZCMLExtractor
'''
)
21 changes: 14 additions & 7 deletions src/lingua/extractors/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import print_function
from pkg_resources import DistributionNotFound
from pkg_resources import working_set
import abc
import collections
Expand Down Expand Up @@ -149,10 +150,16 @@ def __call__(self, filename, options, fileobj=None, lineno=0):

def register_extractors():
for entry_point in working_set.iter_entry_points('lingua.extractors'):
extractor = entry_point.load(require=True)
if not issubclass(extractor, Extractor):
raise ValueError(
u'Registered extractor must derive from ``Extractor``')
EXTRACTORS[entry_point.name] = extractor()
for extension in extractor.extensions:
EXTENSIONS[extension] = entry_point.name
try:
extractor = entry_point.load(require=True)
except DistributionNotFound:
# skip this entry point since at least one required dependency can
# not be found
extractor = None
if extractor:
if not issubclass(extractor, Extractor):
raise ValueError(
u'Registered extractor must derive from ``Extractor``')
EXTRACTORS[entry_point.name] = extractor()
for extension in extractor.extensions:
EXTENSIONS[extension] = entry_point.name
19 changes: 13 additions & 6 deletions src/lingua/extractors/babel.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from pkg_resources import DistributionNotFound
from pkg_resources import working_set
from .python import KEYWORDS
from .python import parse_keyword
Expand Down Expand Up @@ -48,9 +49,15 @@ def __call__(self, filename, options, fileobj=None, firstline=0):
def register_babel_plugins():
for entry_point in working_set.iter_entry_points('babel.extractors'):
name = entry_point.name
extractor = entry_point.load(require=True)
cls = type('BabelExtractor_%s' % name,
(BabelExtractor, object),
{'extractor': staticmethod(extractor),
'__doc__': extractor.__doc__.splitlines()[0]})
EXTRACTORS['babel-%s' % name] = cls()
try:
extractor = entry_point.load(require=True)
except DistributionNotFound:
# skip this entry point since at least one required dependency can
# not be found
extractor = None
if extractor:
cls = type('BabelExtractor_%s' % name,
(BabelExtractor, object),
{'extractor': staticmethod(extractor),
'__doc__': extractor.__doc__.splitlines()[0]})
EXTRACTORS['babel-%s' % name] = cls()

0 comments on commit bbd5eb7

Please sign in to comment.