-
Notifications
You must be signed in to change notification settings - Fork 11
/
setup.py
88 lines (75 loc) · 2.84 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# encoding: utf8
import re
from collections import defaultdict
from setuptools import setup
def _cut_version_number_from_requirement(req):
return req.split()[0]
def read_metadata(metadata_str):
"""
Find __"meta"__ in init file.
"""
with open("./cgp/__init__.py", "r") as f:
meta_match = re.search(fr"^__{metadata_str}__ = ['\"]([^'\"]*)['\"]", f.read(), re.M)
if meta_match:
return meta_match.group(1)
raise RuntimeError(f"Unable to find __{metadata_str}__ string.")
def read_requirements():
requirements = []
with open("./requirements.txt") as f:
for req in f:
req = req.replace("\n", " ")
requirements.append(req)
return requirements
def read_extra_requirements():
extra_requirements = defaultdict(lambda: [])
collect_key = None
collect_keys = []
with open("./extra-requirements.txt") as f:
for req in f:
req = req.replace("\n", " ")
if req.startswith("#"): # new block in requirements file
collect_key = req.split(" ")[1]
collect_keys.append(collect_key)
continue
# We only list extra dependencies required for using the
# library as individual options, not dev or doc
# dependencies
if collect_key == "extra":
extra_requirements[_cut_version_number_from_requirement(req)] = [req]
extra_requirements[collect_key].append(req)
# Collect all requirements into the 'all' key
for key in collect_keys:
extra_requirements["all"] += extra_requirements[key]
return extra_requirements
def read_long_description():
with open("README.rst", "r") as f:
descr = f.read()
ind = descr.find(".. long-description-end")
return descr[:ind]
setup(
name="hal-cgp",
version=read_metadata("version"),
maintainer=read_metadata("maintainer"),
author=read_metadata("author"),
description=(read_metadata("description")),
license=read_metadata("license"),
keywords=["cartesian genetic programming", "evolutionary algorithm", "symbolic regression"],
url=read_metadata("url"),
python_requires=">=3.6, <4",
install_requires=read_requirements(),
extras_require=read_extra_requirements(),
packages=["cgp", "cgp.ea", "cgp.local_search"],
long_description=read_long_description(),
long_description_content_type="text/x-rst",
classifiers=[
"Development Status :: 4 - Beta",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Topic :: Scientific/Engineering",
"Typing :: Typed",
],
)