2019-04-24 15:02:58 +00:00
|
|
|
import os
|
2017-07-23 05:32:18 +00:00
|
|
|
import sys
|
|
|
|
|
|
|
|
from setuptools import setup
|
|
|
|
from setuptools.command.test import test as TestCommand
|
2019-04-24 15:02:58 +00:00
|
|
|
from setuptools.command.sdist import sdist as SdistCommand
|
2017-07-23 05:32:18 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
from setuptools_rust import RustExtension
|
|
|
|
except ImportError:
|
|
|
|
import subprocess
|
2018-07-30 20:52:22 +00:00
|
|
|
|
|
|
|
errno = subprocess.call([sys.executable, "-m", "pip", "install", "setuptools-rust"])
|
2017-07-23 05:32:18 +00:00
|
|
|
if errno:
|
|
|
|
print("Please install setuptools-rust package")
|
|
|
|
raise SystemExit(errno)
|
|
|
|
else:
|
|
|
|
from setuptools_rust import RustExtension
|
|
|
|
|
|
|
|
|
2019-04-24 15:02:58 +00:00
|
|
|
class CargoModifiedSdist(SdistCommand):
|
|
|
|
"""Modifies Cargo.toml to use an absolute rather than a relative path
|
|
|
|
|
|
|
|
The current implementation of PEP 517 in pip always does builds in an
|
|
|
|
isolated temporary directory. This causes problems with the build, because
|
|
|
|
Cargo.toml necessarily refers to the current version of pyo3 by a relative
|
|
|
|
path.
|
|
|
|
|
|
|
|
Since these sdists are never meant to be used for anything other than
|
|
|
|
tox / pip installs, at sdist build time, we will modify the Cargo.toml
|
|
|
|
in the sdist archive to include an *absolute* path to pyo3.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def make_release_tree(self, base_dir, files):
|
|
|
|
"""Stages the files to be included in archives"""
|
|
|
|
super().make_release_tree(base_dir, files)
|
|
|
|
|
|
|
|
import toml
|
2019-09-05 23:16:09 +00:00
|
|
|
|
2019-04-24 15:02:58 +00:00
|
|
|
# Cargo.toml is now staged and ready to be modified
|
2019-09-05 23:16:09 +00:00
|
|
|
cargo_loc = os.path.join(base_dir, "Cargo.toml")
|
2019-04-24 15:02:58 +00:00
|
|
|
assert os.path.exists(cargo_loc)
|
|
|
|
|
2019-09-05 23:16:09 +00:00
|
|
|
with open(cargo_loc, "r") as f:
|
2019-04-24 15:02:58 +00:00
|
|
|
cargo_toml = toml.load(f)
|
|
|
|
|
2019-09-05 23:16:09 +00:00
|
|
|
rel_pyo3_path = cargo_toml["dependencies"]["pyo3"]["path"]
|
2019-04-24 15:02:58 +00:00
|
|
|
base_path = os.path.dirname(__file__)
|
|
|
|
abs_pyo3_path = os.path.abspath(os.path.join(base_path, rel_pyo3_path))
|
|
|
|
|
2019-09-05 23:16:09 +00:00
|
|
|
cargo_toml["dependencies"]["pyo3"]["path"] = abs_pyo3_path
|
2019-04-24 15:02:58 +00:00
|
|
|
|
2019-09-05 23:16:09 +00:00
|
|
|
with open(cargo_loc, "w") as f:
|
2019-04-24 15:02:58 +00:00
|
|
|
toml.dump(cargo_toml, f)
|
|
|
|
|
|
|
|
|
2017-07-23 05:32:18 +00:00
|
|
|
class PyTest(TestCommand):
|
|
|
|
user_options = []
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
self.run_command("test_rust")
|
|
|
|
|
|
|
|
import subprocess
|
2018-07-30 20:52:22 +00:00
|
|
|
|
2018-10-09 14:24:36 +00:00
|
|
|
subprocess.check_call(["pytest", "tests"])
|
2017-07-23 05:32:18 +00:00
|
|
|
|
|
|
|
|
2018-07-30 20:52:22 +00:00
|
|
|
setup_requires = ["setuptools-rust>=0.10.1", "wheel"]
|
2017-07-23 05:32:18 +00:00
|
|
|
install_requires = []
|
2018-07-30 20:52:22 +00:00
|
|
|
tests_require = install_requires + ["pytest", "pytest-benchmark"]
|
2017-07-23 05:32:18 +00:00
|
|
|
|
|
|
|
setup(
|
2018-07-30 20:52:22 +00:00
|
|
|
name="word-count",
|
|
|
|
version="0.1.0",
|
2017-07-23 05:32:18 +00:00
|
|
|
classifiers=[
|
2018-07-30 20:52:22 +00:00
|
|
|
"License :: OSI Approved :: MIT License",
|
|
|
|
"Development Status :: 3 - Alpha",
|
|
|
|
"Intended Audience :: Developers",
|
|
|
|
"Programming Language :: Python",
|
|
|
|
"Programming Language :: Rust",
|
|
|
|
"Operating System :: POSIX",
|
|
|
|
"Operating System :: MacOS :: MacOS X",
|
2017-07-23 05:32:18 +00:00
|
|
|
],
|
2018-07-30 20:52:22 +00:00
|
|
|
packages=["word_count"],
|
2020-06-05 14:16:29 +00:00
|
|
|
rust_extensions=[RustExtension("word_count.word_count", "Cargo.toml", debug=False)],
|
2017-07-23 05:32:18 +00:00
|
|
|
install_requires=install_requires,
|
|
|
|
tests_require=tests_require,
|
|
|
|
setup_requires=setup_requires,
|
|
|
|
include_package_data=True,
|
|
|
|
zip_safe=False,
|
2019-09-05 23:16:09 +00:00
|
|
|
cmdclass={"test": PyTest, "sdist": CargoModifiedSdist},
|
2017-07-23 05:32:18 +00:00
|
|
|
)
|