mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-24 17:06:29 +03:00
add about.py, adapt setup.py
This commit is contained in:
parent
f8a8f97d25
commit
211913d689
97
setup.py
97
setup.py
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
from __future__ import division, print_function
|
from __future__ import print_function
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
|
@ -14,14 +14,6 @@ except ImportError:
|
||||||
from distutils.core import Extension, setup
|
from distutils.core import Extension, setup
|
||||||
|
|
||||||
|
|
||||||
MAJOR = 0
|
|
||||||
MINOR = 100
|
|
||||||
MICRO = 0
|
|
||||||
ISRELEASE = False
|
|
||||||
VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO)
|
|
||||||
DEFAULT_MODEL = 'en_default==1.0.4'
|
|
||||||
|
|
||||||
|
|
||||||
PACKAGES = [
|
PACKAGES = [
|
||||||
'spacy',
|
'spacy',
|
||||||
'spacy.tokens',
|
'spacy.tokens',
|
||||||
|
@ -104,75 +96,6 @@ class build_ext_subclass(build_ext, build_ext_options):
|
||||||
build_ext.build_extensions(self)
|
build_ext.build_extensions(self)
|
||||||
|
|
||||||
|
|
||||||
# Return the git revision as a string
|
|
||||||
def git_version():
|
|
||||||
def _minimal_ext_cmd(cmd):
|
|
||||||
# construct minimal environment
|
|
||||||
env = {}
|
|
||||||
for k in ['SYSTEMROOT', 'PATH']:
|
|
||||||
v = os.environ.get(k)
|
|
||||||
if v is not None:
|
|
||||||
env[k] = v
|
|
||||||
# LANGUAGE is used on win32
|
|
||||||
env['LANGUAGE'] = 'C'
|
|
||||||
env['LANG'] = 'C'
|
|
||||||
env['LC_ALL'] = 'C'
|
|
||||||
out = subprocess.Popen(cmd, stdout = subprocess.PIPE, env=env).communicate()[0]
|
|
||||||
return out
|
|
||||||
|
|
||||||
try:
|
|
||||||
out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD'])
|
|
||||||
GIT_REVISION = out.strip().decode('ascii')
|
|
||||||
except OSError:
|
|
||||||
GIT_REVISION = 'Unknown'
|
|
||||||
|
|
||||||
return GIT_REVISION
|
|
||||||
|
|
||||||
|
|
||||||
def get_version_info():
|
|
||||||
# Adding the git rev number needs to be done inside write_version_py(),
|
|
||||||
# otherwise the import of spacy.about messes up the build under Python 3.
|
|
||||||
FULLVERSION = VERSION
|
|
||||||
if os.path.exists('.git'):
|
|
||||||
GIT_REVISION = git_version()
|
|
||||||
elif os.path.exists(os.path.join('spacy', 'about.py')):
|
|
||||||
# must be a source distribution, use existing version file
|
|
||||||
try:
|
|
||||||
from spacy.about import git_revision as GIT_REVISION
|
|
||||||
except ImportError:
|
|
||||||
raise ImportError('Unable to import git_revision. Try removing '
|
|
||||||
'spacy/about.py and the build directory '
|
|
||||||
'before building.')
|
|
||||||
else:
|
|
||||||
GIT_REVISION = 'Unknown'
|
|
||||||
|
|
||||||
if not ISRELEASE:
|
|
||||||
FULLVERSION += '.dev0+' + GIT_REVISION[:7]
|
|
||||||
|
|
||||||
return FULLVERSION, GIT_REVISION
|
|
||||||
|
|
||||||
|
|
||||||
def write_version(path):
|
|
||||||
cnt = """# THIS FILE IS GENERATED FROM SPACY SETUP.PY
|
|
||||||
short_version = '%(version)s'
|
|
||||||
version = '%(version)s'
|
|
||||||
full_version = '%(full_version)s'
|
|
||||||
git_revision = '%(git_revision)s'
|
|
||||||
release = %(isrelease)s
|
|
||||||
default_model = '%(default_model)s'
|
|
||||||
if not release:
|
|
||||||
version = full_version
|
|
||||||
"""
|
|
||||||
FULLVERSION, GIT_REVISION = get_version_info()
|
|
||||||
|
|
||||||
with open(path, 'w') as f:
|
|
||||||
f.write(cnt % {'version': VERSION,
|
|
||||||
'full_version' : FULLVERSION,
|
|
||||||
'git_revision' : GIT_REVISION,
|
|
||||||
'isrelease': str(ISRELEASE),
|
|
||||||
'default_model': DEFAULT_MODEL})
|
|
||||||
|
|
||||||
|
|
||||||
def generate_cython(root, source):
|
def generate_cython(root, source):
|
||||||
print('Cythonizing sources')
|
print('Cythonizing sources')
|
||||||
p = subprocess.call([sys.executable,
|
p = subprocess.call([sys.executable,
|
||||||
|
@ -244,7 +167,9 @@ def setup_package():
|
||||||
return clean(root)
|
return clean(root)
|
||||||
|
|
||||||
with chdir(root):
|
with chdir(root):
|
||||||
write_version(os.path.join(root, 'spacy', 'about.py'))
|
about = {}
|
||||||
|
with open(os.path.join(root, "spacy", "about.py")) as f:
|
||||||
|
exec(f.read(), about)
|
||||||
|
|
||||||
include_dirs = [
|
include_dirs = [
|
||||||
get_python_inc(plat_specific=True),
|
get_python_inc(plat_specific=True),
|
||||||
|
@ -262,16 +187,16 @@ def setup_package():
|
||||||
prepare_includes(root)
|
prepare_includes(root)
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='spacy',
|
name=about['__name__'],
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
packages=PACKAGES,
|
packages=PACKAGES,
|
||||||
package_data={'': ['*.pyx', '*.pxd']},
|
package_data={'': ['*.pyx', '*.pxd']},
|
||||||
description='Industrial-strength NLP',
|
description=about['__summary__'],
|
||||||
author='Matthew Honnibal',
|
author=about['__author__'],
|
||||||
author_email='matt@spacy.io',
|
author_email=about['__email__'],
|
||||||
version=VERSION,
|
version=about['__version__'],
|
||||||
url='https://spacy.io',
|
url=about['__uri__'],
|
||||||
license='MIT',
|
license=about['__license__'],
|
||||||
ext_modules=ext_modules,
|
ext_modules=ext_modules,
|
||||||
install_requires=['numpy', 'murmurhash>=0.26,<0.27', 'cymem>=1.30,<1.31', 'preshed>=0.46.1,<0.47',
|
install_requires=['numpy', 'murmurhash>=0.26,<0.27', 'cymem>=1.30,<1.31', 'preshed>=0.46.1,<0.47',
|
||||||
'thinc>=4.2.0,<4.3.0', 'text_unidecode', 'plac', 'six',
|
'thinc>=4.2.0,<4.3.0', 'text_unidecode', 'plac', 'six',
|
||||||
|
|
14
spacy/about.py
Normal file
14
spacy/about.py
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
# inspired from:
|
||||||
|
|
||||||
|
# https://python-packaging-user-guide.readthedocs.org/en/latest/single_source_version/
|
||||||
|
# https://github.com/pypa/warehouse/blob/master/warehouse/__about__.py
|
||||||
|
|
||||||
|
__name__ = 'spacy'
|
||||||
|
__version__ = '0.100.0'
|
||||||
|
__summary__ = 'Industrial-strength NLP'
|
||||||
|
__uri__ = 'https://spacy.io'
|
||||||
|
__author__ = 'Matthew Honnibal'
|
||||||
|
__email__ = 'matt@spacy.io'
|
||||||
|
__license__ = 'MIT'
|
||||||
|
__release__ = False
|
||||||
|
__default_model__ = 'en_default==1.0.4'
|
|
@ -42,12 +42,12 @@ def main(data_size='all', force=False):
|
||||||
path = os.path.dirname(os.path.abspath(__file__))
|
path = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
if force:
|
if force:
|
||||||
sputnik.purge('spacy', about.short_version)
|
sputnik.purge(about.__name__, about.__version__)
|
||||||
|
|
||||||
package = sputnik.install('spacy', about.short_version, about.default_model)
|
package = sputnik.install(about.__name__, about.__version__, about.__default_model__)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
sputnik.package('spacy', about.short_version, about.default_model)
|
sputnik.package(about.__name__, about.__version__, about.__default_model__)
|
||||||
except PackageNotFoundException, CompatiblePackageNotFoundException:
|
except PackageNotFoundException, CompatiblePackageNotFoundException:
|
||||||
print("Model failed to install. Please run 'python -m "
|
print("Model failed to install. Please run 'python -m "
|
||||||
"spacy.en.download --force'.", file=sys.stderr)
|
"spacy.en.download --force'.", file=sys.stderr)
|
||||||
|
|
|
@ -19,7 +19,6 @@ from . import orth
|
||||||
from .syntax.ner import BiluoPushDown
|
from .syntax.ner import BiluoPushDown
|
||||||
from .syntax.arc_eager import ArcEager
|
from .syntax.arc_eager import ArcEager
|
||||||
|
|
||||||
from . import about
|
|
||||||
from . import util
|
from . import util
|
||||||
from .attrs import TAG, DEP, ENT_IOB, ENT_TYPE, HEAD
|
from .attrs import TAG, DEP, ENT_IOB, ENT_TYPE, HEAD
|
||||||
|
|
||||||
|
@ -193,7 +192,7 @@ class Language(object):
|
||||||
via = data_dir
|
via = data_dir
|
||||||
|
|
||||||
if via is None:
|
if via is None:
|
||||||
package = util.get_package_by_name(about.default_model)
|
package = util.get_package_by_name()
|
||||||
else:
|
else:
|
||||||
package = util.get_package(via)
|
package = util.get_package(via)
|
||||||
|
|
||||||
|
|
|
@ -20,9 +20,10 @@ def get_package(via=None):
|
||||||
return DirPackage(via)
|
return DirPackage(via)
|
||||||
|
|
||||||
|
|
||||||
def get_package_by_name(name, via=None):
|
def get_package_by_name(name=None, via=None):
|
||||||
try:
|
try:
|
||||||
return sputnik.package('spacy', about.short_version, name, data_path=via)
|
return sputnik.package(about.__name__, about.__version__,
|
||||||
|
name or about.__default_model__, data_path=via)
|
||||||
except PackageNotFoundException as e:
|
except PackageNotFoundException as e:
|
||||||
raise RuntimeError("Model not installed. Please run 'python -m "
|
raise RuntimeError("Model not installed. Please run 'python -m "
|
||||||
"spacy.en.download' to install latest compatible "
|
"spacy.en.download' to install latest compatible "
|
||||||
|
|
Loading…
Reference in New Issue
Block a user