-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathsetup.py
104 lines (82 loc) · 3.65 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import os
import pathlib
import sys
import subprocess
import typing
# The relative path of the source code to the setup file
source_directory = 'esl'
try:
# Attempt to load skbuild, which is necessary to build this python package
from skbuild import setup
except ImportError:
error_message = 'Please update pip, you need pip 10 or greater, or install the skbuild package, or install the ' \
'PEP 518 requirements in pyproject.toml '
print(error_message, file=sys.stderr)
raise ImportError(error_message)
def read_version():
"""
Reads the library version number from the unified version files, esl/version
:return: Version tuple, in (major, minor, patch) format.
"""
try:
with open(f"{source_directory}/version", "r") as source_version:
lines = source_version.readlines()
version = []
for line in lines:
if "ESL_VERSION_" in line:
number = int(line.split(";")[0].split('=')[1].strip())
version.append(number)
return tuple(version)
except:
raise ValueError(f"Can not read {source_directory}/version file.")
def read_commit() -> typing.Optional[str]:
"""
Gets a commit identifier, so that it can be added to the library version
:return:
"""
try:
return subprocess.check_output(["git", "rev-parse", "--short", "HEAD"]).strip().decode()
except subprocess.CalledProcessError:
# likely git not installed, or not authorized to use
return None
def get_packages():
"""
Walks the source directory to find python modules. A module has an __init__.py file in the directory.
:return: A dictionary mapping package names to subdirectories, e.g. {'esl.simulation': 'esl/simulation'}
"""
packages = dict()
for subdirectory, dirs, files in os.walk(source_directory):
for file in files:
entry = subdirectory + os.sep + file
if entry.endswith("__init__.py"):
packages[subdirectory.replace('/', '.')] = subdirectory
return packages
packages = get_packages()
# disabled for now
commit = None # read_commit()
# Set up the package, together with metadata that will be visible on package repositories such as Pypi
setup(
name = 'eslpy',
version = '.'.join(map(str, read_version())) + ('' if commit is None else '-' + commit),
description = 'Python package for the Economic Simulation Library (https://github.com/INET-Complexity/ESL/)',
# This loads the README file in a way that allows repositories such as Pypi to render the readme using markdown
long_description = (pathlib.Path(__file__).parent / "README.md").read_text(),
long_description_content_type="text/markdown",
author = 'Maarten P. Scholl et al.',
author_email = 'maarten.scholl@cs.ox.ac.uk',
url = "https://www.inet.ox.ac.uk/",
classifiers = [ 'Development Status :: 3 - Alpha',
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python',
'Programming Language :: C++',
'Topic :: Scientific/Engineering',
'Intended Audience :: Science/Research',
],
license = 'Apache License 2.0',
packages = list(packages.keys()),
package_dir = packages,
package_data = { '' : []
, source_directory: ['version']
},
cmake_install_dir = 'esl'
)