Add custom sdist command to modify Cargo.toml
This enables PEP 517 builds from an sdist, and should fix `tox` builds using `pip >= 19.0`. This does not fix pip installing the directory; pinning to `pip < 19.0` is still the best strategy for that.
This commit is contained in:
parent
7e8616de33
commit
c3fee87dee
2
examples/rustapi_module/MANIFEST.in
Normal file
2
examples/rustapi_module/MANIFEST.in
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
include pyproject.toml Cargo.toml
|
||||||
|
recursive-include src *
|
|
@ -1,2 +1,2 @@
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["setuptools", "wheel", "setuptools_rust>=0.10.2"]
|
requires = ["setuptools", "wheel", "setuptools_rust>=0.10.2", "toml"]
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
import platform
|
import platform
|
||||||
|
|
||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
from setuptools.command.test import test as TestCommand
|
from setuptools.command.test import test as TestCommand
|
||||||
|
from setuptools.command.sdist import sdist as SdistCommand
|
||||||
from setuptools_rust import RustExtension
|
from setuptools_rust import RustExtension
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,6 +20,41 @@ class PyTest(TestCommand):
|
||||||
raise SystemExit(errno)
|
raise SystemExit(errno)
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
def get_py_version_cfgs():
|
def get_py_version_cfgs():
|
||||||
# For now each Cfg Py_3_X flag is interpreted as "at least 3.X"
|
# For now each Cfg Py_3_X flag is interpreted as "at least 3.X"
|
||||||
version = sys.version_info[0:2]
|
version = sys.version_info[0:2]
|
||||||
|
@ -70,5 +107,8 @@ setup(
|
||||||
tests_require=tests_require,
|
tests_require=tests_require,
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
cmdclass=dict(test=PyTest),
|
cmdclass={
|
||||||
|
'test': PyTest,
|
||||||
|
'sdist': CargoModifiedSdist,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue