mirror of https://github.com/explosion/spaCy.git
Include git commit in package and model meta (#5694)
* Include git commit in package and model meta * Rewrite to read file in setup * Fix file handle
This commit is contained in:
parent
2bd78c39e3
commit
971826a96d
|
@ -70,6 +70,7 @@ Pipfile.lock
|
|||
*.egg
|
||||
.eggs
|
||||
MANIFEST
|
||||
spacy/git_info.py
|
||||
|
||||
# Temporary files
|
||||
*.~*
|
||||
|
|
|
@ -6,3 +6,4 @@ include bin/spacy
|
|||
include pyproject.toml
|
||||
recursive-exclude spacy/lang *.json
|
||||
recursive-include spacy/lang *.json.gz
|
||||
recursive-include licenses *
|
||||
|
|
51
setup.py
51
setup.py
|
@ -118,6 +118,55 @@ def is_source_release(path):
|
|||
return os.path.exists(os.path.join(path, "PKG-INFO"))
|
||||
|
||||
|
||||
# Include the git version in the build (adapted from NumPy)
|
||||
# Copyright (c) 2005-2020, NumPy Developers.
|
||||
# BSD 3-Clause license, see licenses/3rd_party_licenses.txt
|
||||
def write_git_info_py(filename="spacy/git_info.py"):
|
||||
def _minimal_ext_cmd(cmd):
|
||||
# construct minimal environment
|
||||
env = {}
|
||||
for k in ["SYSTEMROOT", "PATH", "HOME"]:
|
||||
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.check_output(cmd, stderr=subprocess.STDOUT, env=env)
|
||||
return out
|
||||
|
||||
git_version = "Unknown"
|
||||
if os.path.exists(".git"):
|
||||
try:
|
||||
out = _minimal_ext_cmd(["git", "rev-parse", "--short", "HEAD"])
|
||||
git_version = out.strip().decode("ascii")
|
||||
except:
|
||||
pass
|
||||
elif os.path.exists(filename):
|
||||
# must be a source distribution, use existing version file
|
||||
try:
|
||||
a = open(filename, "r")
|
||||
lines = a.readlines()
|
||||
git_version = lines[-1].split('"')[1]
|
||||
except:
|
||||
pass
|
||||
finally:
|
||||
a.close()
|
||||
|
||||
text = """# THIS FILE IS GENERATED FROM SPACY SETUP.PY
|
||||
#
|
||||
GIT_VERSION = "%(git_version)s"
|
||||
"""
|
||||
a = open(filename, "w")
|
||||
try:
|
||||
a.write(
|
||||
text % {"git_version": git_version,}
|
||||
)
|
||||
finally:
|
||||
a.close()
|
||||
|
||||
|
||||
def clean(path):
|
||||
for name in MOD_NAMES:
|
||||
name = name.replace(".", "/")
|
||||
|
@ -140,6 +189,8 @@ def chdir(new_dir):
|
|||
|
||||
|
||||
def setup_package():
|
||||
write_git_info_py()
|
||||
|
||||
root = os.path.abspath(os.path.dirname(__file__))
|
||||
|
||||
if len(sys.argv) > 1 and sys.argv[1] == "clean":
|
||||
|
|
|
@ -34,6 +34,7 @@ from .lang.tag_map import TAG_MAP
|
|||
from .tokens import Doc
|
||||
from .lang.lex_attrs import LEX_ATTRS, is_stop
|
||||
from .errors import Errors, Warnings
|
||||
from .git_info import GIT_VERSION
|
||||
from . import util
|
||||
from . import about
|
||||
|
||||
|
@ -206,6 +207,7 @@ class Language(object):
|
|||
self._meta.setdefault("email", "")
|
||||
self._meta.setdefault("url", "")
|
||||
self._meta.setdefault("license", "")
|
||||
self._meta.setdefault("spacy_git_version", GIT_VERSION)
|
||||
self._meta["vectors"] = {
|
||||
"width": self.vocab.vectors_length,
|
||||
"vectors": len(self.vocab.vectors),
|
||||
|
|
Loading…
Reference in New Issue