allennlp
/
setup.py
107 строк · 3.6 Кб
1from collections import defaultdict
2from setuptools import find_packages, setup
3
4# PEP0440 compatible formatted version, see:
5# https://www.python.org/dev/peps/pep-0440/
6#
7# release markers:
8# X.Y
9# X.Y.Z # For bugfix releases
10#
11# pre-release markers:
12# X.YaN # Alpha release
13# X.YbN # Beta release
14# X.YrcN # Release Candidate
15# X.Y # Final release
16
17
18def parse_requirements_file(path, allowed_extras: set = None, include_all_extra: bool = True):
19requirements = []
20extras = defaultdict(list)
21with open(path) as requirements_file:
22import re
23
24def fix_url_dependencies(req: str) -> str:
25"""Pip and setuptools disagree about how URL dependencies should be handled."""
26m = re.match(
27r"^(git\+)?(https|ssh)://(git@)?github\.com/([\w-]+)/(?P<name>[\w-]+)\.git", req
28)
29if m is None:
30return req
31else:
32return f"{m.group('name')} @ {req}"
33
34for line in requirements_file:
35line = line.strip()
36if line.startswith("#") or len(line) <= 0:
37continue
38req, *needed_by = line.split("# needed by:")
39req = fix_url_dependencies(req.strip())
40if needed_by:
41for extra in needed_by[0].strip().split(","):
42extra = extra.strip()
43if allowed_extras is not None and extra not in allowed_extras:
44raise ValueError(f"invalid extra '{extra}' in {path}")
45extras[extra].append(req)
46if include_all_extra and req not in extras["all"]:
47extras["all"].append(req)
48else:
49requirements.append(req)
50return requirements, extras
51
52
53integrations = {"checklist"}
54
55# Load requirements.
56install_requirements, extras = parse_requirements_file(
57"requirements.txt", allowed_extras=integrations
58)
59dev_requirements, dev_extras = parse_requirements_file(
60"dev-requirements.txt", allowed_extras={"examples"}, include_all_extra=False
61)
62extras["dev"] = dev_requirements
63extras.update(dev_extras)
64
65# version.py defines the VERSION and VERSION_SHORT variables.
66# We use exec here so we don't import allennlp whilst setting up.
67VERSION = {} # type: ignore
68with open("allennlp/version.py", "r") as version_file:
69exec(version_file.read(), VERSION)
70
71setup(
72name="allennlp",
73version=VERSION["VERSION"],
74description="An open-source NLP research library, built on PyTorch.",
75long_description=open("README.md", encoding="utf-8").read(),
76long_description_content_type="text/markdown",
77classifiers=[
78"Intended Audience :: Science/Research",
79"Development Status :: 3 - Alpha",
80"License :: OSI Approved :: Apache Software License",
81"Programming Language :: Python :: 3",
82"Topic :: Scientific/Engineering :: Artificial Intelligence",
83],
84keywords="allennlp NLP deep learning machine reading",
85url="https://github.com/allenai/allennlp",
86author="Allen Institute for Artificial Intelligence",
87author_email="allennlp@allenai.org",
88license="Apache",
89packages=find_packages(
90exclude=[
91"*.tests",
92"*.tests.*",
93"tests.*",
94"tests",
95"test_fixtures",
96"test_fixtures.*",
97"benchmarks",
98"benchmarks.*",
99]
100),
101install_requires=install_requirements,
102extras_require=extras,
103entry_points={"console_scripts": ["allennlp=allennlp.__main__:run"]},
104include_package_data=True,
105python_requires=">=3.7.1",
106zip_safe=False,
107)
108