-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
executable file
·140 lines (123 loc) · 4.69 KB
/
setup.py
File metadata and controls
executable file
·140 lines (123 loc) · 4.69 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import io
import os
import re
from glob import glob
from os.path import basename
from os.path import dirname
from os.path import join
from os.path import relpath
from os.path import splitext
from typing import Set, Any, List, Dict
from setuptools import Extension
from setuptools import find_packages
from setuptools import setup
from setuptools.dist import Distribution
from pathlib import Path
from Cython.Build import cythonize
try:
# Allow installing package without any Cython available. This
# assumes you are going to include the .c files in your sdist.
import Cython
except ImportError:
Cython = None
class BinaryDistribution(Distribution):
"""Distribution which almost always forces a binary package with platform name"""
def has_ext_modules(self):
return super().has_ext_modules() or not os.environ.get('SETUPPY_ALLOW_PURE')
def get_property(prop, packages_path: str, packages: List[str]) -> Set[Any]:
"""
Searches and returns a property from all packages __init__.py files
:param prop: property searched
:param packages_path: root path of packages to search into
:param packages: array of packages paths
:return: an set of values
"""
results = set()
namespace: Dict[str, Any] = {}
for package in packages:
init_file = open(Path(packages_path, package, "__init__.py")).read()
exec(init_file, namespace)
if prop in namespace:
results.add(namespace[prop])
return results
def get_requirements(file_path: str, no_precise_version: bool = False) -> List[str]:
_requirements = []
try:
with open(file_path, "rt") as r:
for line in r.readlines():
package = line.strip()
if not package or package.startswith("#"):
continue
if no_precise_version:
package = package.split("==")[0]
_requirements.append(package)
except FileExistsError:
pass
return _requirements
def read(*names, **kwargs):
with io.open(
join(dirname(__file__), *names), encoding=kwargs.get('encoding', 'utf8')
) as fh:
return fh.read()
project_name = "cymorton"
github_home = "https://github.com/decitre"
if __name__ == '__main__':
_packages_path = "src"
_packages = find_packages(where=_packages_path)
main_package_path = {
Path(_packages_path, *package.split("."))
for package in _packages
if package.endswith(project_name)
}.pop()
version = get_property("__version__", _packages_path, _packages).pop()
requirements = ["click"]
requirements.extend(get_requirements("requirements.txt", no_precise_version=True))
requirements_test = get_requirements("requirements_test.txt")
ext_modules = [
Extension(
splitext(relpath(path, 'src').replace(os.sep, '.'))[0],
sources=[path],
include_dirs=[dirname(path)],
)
for root, _, _ in os.walk('src')
for path in glob(join(root, '*.pyx'))
]
setup(
name=project_name,
version=version,
license='MIT',
description='A morton code codec in c++/cython',
long_description=re.compile(
'^.. start-badges.*^.. end-badges', re.M | re.S
).sub('', read('README.rst')),
author='Emmanuel Decitre',
url=f'{github_home}/python-{project_name}',
packages=find_packages(_packages_path),
package_dir={'': _packages_path},
py_modules=[splitext(basename(path))[0] for path in glob('src/*.py')],
include_package_data=True,
zip_safe=False,
classifiers=[
# complete classifier list: http://pypi.python.org/pypi?%3Aaction=list_classifiers
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Cython',
'Programming Language :: Python :: Implementation :: CPython',
],
project_urls={
'Issue Tracker': f'{github_home}/python-{project_name}/issues',
},
keywords=["morton", "z-curve"],
python_requires='>=3.6',
install_requires=requirements,
extras_require={"dev": requirements_test},
setup_requires=['Cython'],
entry_points={'console_scripts': [f'{project_name} = {project_name}.cli:main']},
ext_modules=cythonize(ext_modules, language_level="3"),
distclass=BinaryDistribution,
)