Merge pull request #463 from pganssle/tweak_tox_config

Fix PEP 517 build issues in test extensions
This commit is contained in:
Yuji Kanagawa 2019-04-26 14:25:40 +09:00 committed by GitHub
commit 8399916ea9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 93 additions and 7 deletions

View file

@ -0,0 +1,2 @@
include pyproject.toml Cargo.toml
recursive-include src *

View file

@ -1,2 +1,3 @@
[build-system]
requires = ["setuptools", "wheel", "setuptools_rust>=0.10.2"]
requires = ["setuptools", "wheel", "setuptools_rust>=0.10.2", "toml"]
build-backend = "setuptools.build_meta"

View file

@ -1,8 +1,10 @@
import os
import sys
import platform
from setuptools import setup
from setuptools.command.test import test as TestCommand
from setuptools.command.sdist import sdist as SdistCommand
from setuptools_rust import RustExtension
@ -18,6 +20,41 @@ class PyTest(TestCommand):
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():
# For now each Cfg Py_3_X flag is interpreted as "at least 3.X"
version = sys.version_info[0:2]
@ -70,5 +107,8 @@ setup(
tests_require=tests_require,
include_package_data=True,
zip_safe=False,
cmdclass=dict(test=PyTest),
cmdclass={
'test': PyTest,
'sdist': CargoModifiedSdist,
},
)

View file

@ -3,11 +3,11 @@ envlist = py35,
py36,
py37,
pypy35
minversion = 2.9.0
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}

View file

@ -0,0 +1,2 @@
include pyproject.toml Cargo.toml
recursive-include src *

View file

@ -1,2 +1,3 @@
[build-system]
requires = ["setuptools", "wheel", "setuptools-rust"]
requires = ["setuptools", "wheel", "setuptools-rust", "toml"]
build-backend = "setuptools.build_meta"

View file

@ -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,
},
)

View file

@ -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}