-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsetup.py
108 lines (87 loc) · 3.13 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
105
106
107
108
import sys
import pathlib
import os
import subprocess
from setuptools.command.sdist import sdist
from setuptools.command.install import install
# from pybind11 import get_cmake_dir
from pybind11.setup_helpers import Pybind11Extension, build_ext
# from setuptools import setup
# the directory containing this file
HERE = pathlib.Path(__file__).parent
# the text of the README file
README = (HERE / "README.md").read_text()
__version__ = "0.3.5"
try:
from skbuild import setup
except ImportError:
print(
"Please update pip, you need pip 10 or greater,\n"
" or you need to install the PEP 518 requirements in pyproject.toml yourself",
file=sys.stderr,
)
raise
ext_modules = [
Pybind11Extension(
"_hamming_codec",
["src/python/module.cpp"],
include_dirs=["src/cpp"],
# Example: passing in the version to the compiled code
define_macros=[("VERSION_INFO", __version__), ("BUILD_PYTHON", "on")],
),
]
def check_submodules():
"""verify that the submodules are checked out and clean
use `git submodule update --init`; on failure
"""
if not os.path.exists(".git"):
return
with open(".gitmodules") as f:
for line in f:
if "path" in line:
p = line.split("=")[-1].strip()
if not os.path.exists(p):
raise ValueError("Submodule {} missing".format(p))
proc = subprocess.Popen(["git", "submodule", "status"], stdout=subprocess.PIPE)
status, _ = proc.communicate()
status = status.decode("ascii", "replace")
for line in status.splitlines():
if line.startswith("-") or line.startswith("+"):
raise ValueError("Submodule not clean: {}".format(line))
class SdistChecker(sdist):
""" check submodules on sdist to prevent incomplete tarballs """
def run(self):
check_submodules()
sdist.run(self)
class InstallChecker(install):
""" check submodules on install to prevent failed installs """
def run(self):
check_submodules()
install.run(self)
cmake_compiler_defines = f"-DBUILD_PYTHON=on -DVERSION_INFO={__version__}"
print(f"cmake compiler defines = {cmake_compiler_defines}")
setup(
name="hamming_codec",
version=__version__,
description="Simple encode/decode utilities for bit-error correcting Hamming codes",
long_description=README,
long_description_content_type="text/markdown",
url="https://github.com/dantrim/hamming-codec",
author="Daniel Joseph Antrim",
author_email="[email protected]",
license="MIT",
classifiers=[
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
],
package_dir={"": "src/python"},
packages=["hamming_codec", "cli"],
install_requires=["typer"],
ext_modules=ext_modules,
cmake_args=["-DBUILD_PYTHON=on"],
cmake_install_dir="src/python/hamming_codec",
entry_points={"console_scripts": ["hamming=cli:cli.app"]},
cmdclass={"build_ext": build_ext, "install": InstallChecker, "sdist": SdistChecker},
include_package_data=True,
)