diff --git a/examples/word-count/MANIFEST.in b/examples/word-count/MANIFEST.in new file mode 100644 index 00000000..becccf7b --- /dev/null +++ b/examples/word-count/MANIFEST.in @@ -0,0 +1,2 @@ +include pyproject.toml Cargo.toml +recursive-include src * diff --git a/examples/word-count/pyproject.toml b/examples/word-count/pyproject.toml index 31ffe048..0b05068f 100644 --- a/examples/word-count/pyproject.toml +++ b/examples/word-count/pyproject.toml @@ -1,2 +1,3 @@ [build-system] -requires = ["setuptools", "wheel", "setuptools-rust"] +requires = ["setuptools", "wheel", "setuptools-rust", "toml"] +build-backend = "setuptools.build_meta" diff --git a/examples/word-count/setup.py b/examples/word-count/setup.py index 99fe7cc3..153637f7 100644 --- a/examples/word-count/setup.py +++ b/examples/word-count/setup.py @@ -1,7 +1,9 @@ +import os import sys from setuptools import setup from setuptools.command.test import test as TestCommand +from setuptools.command.sdist import sdist as SdistCommand try: from setuptools_rust import RustExtension @@ -16,6 +18,41 @@ except ImportError: from setuptools_rust import RustExtension +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 + # Cargo.toml is now staged and ready to be modified + cargo_loc = os.path.join(base_dir, 'Cargo.toml') + assert os.path.exists(cargo_loc) + + with open(cargo_loc, 'r') as f: + cargo_toml = toml.load(f) + + rel_pyo3_path = cargo_toml['dependencies']['pyo3']['path'] + base_path = os.path.dirname(__file__) + abs_pyo3_path = os.path.abspath(os.path.join(base_path, rel_pyo3_path)) + + cargo_toml['dependencies']['pyo3']['path'] = abs_pyo3_path + + with open(cargo_loc, 'w') as f: + toml.dump(cargo_toml, f) + + class PyTest(TestCommand): user_options = [] @@ -50,5 +87,8 @@ setup( setup_requires=setup_requires, include_package_data=True, zip_safe=False, - cmdclass=dict(test=PyTest), + cmdclass={ + 'test': PyTest, + 'sdist': CargoModifiedSdist, + }, ) diff --git a/examples/word-count/tox.ini b/examples/word-count/tox.ini index ebc22945..586fb41a 100644 --- a/examples/word-count/tox.ini +++ b/examples/word-count/tox.ini @@ -5,9 +5,9 @@ envlist = py35, pypy35 minversion = 3.4.0 skip_missing_interpreters = true +isolated_build = true [testenv] description = Run the unit tests under {basepython} deps = -rrequirements-dev.txt -usedevelop = True commands = pytest {posargs}