From 1fdaebc1b255c2b11f6c721b706c3d45f4fada1b Mon Sep 17 00:00:00 2001 From: messense Date: Sat, 20 May 2023 12:38:05 +0800 Subject: [PATCH] Add PEP 517 `config_settings` support Replaces `MATURIN_PEP517_ARGS` environment variable with `--config-settings build-args=`. --- Changelog.md | 6 ++++-- maturin/__init__.py | 20 ++++++++++++++----- test-crates/cffi-mixed/pyproject.toml | 2 +- test-crates/cffi-pure/pyproject.toml | 2 +- test-crates/hello-world/pyproject.toml | 2 +- .../lib_with_disallowed_lib/pyproject.toml | 2 +- test-crates/lib_with_path_dep/pyproject.toml | 2 +- test-crates/license-test/pyproject.toml | 2 +- test-crates/pyo3-ffi-pure/pyproject.toml | 2 +- .../pyo3-mixed-include-exclude/pyproject.toml | 2 +- .../pyo3-mixed-py-subdir/pyproject.toml | 2 +- test-crates/pyo3-mixed-src/pyproject.toml | 2 +- .../pyo3-mixed-submodule/pyproject.toml | 2 +- test-crates/pyo3-mixed/pyproject.toml | 2 +- test-crates/pyo3-pure/pyproject.toml | 2 +- .../sdist_with_path_dep/pyproject.toml | 2 +- .../sdist_with_target_path_dep/pyproject.toml | 2 +- test-crates/uniffi-mixed/pyproject.toml | 2 +- test-crates/uniffi-pure/pyproject.toml | 2 +- test-crates/with-data/pyproject.toml | 2 +- .../python/pyproject.toml | 2 +- test-crates/workspace/py/pyproject.toml | 2 +- .../workspace_with_path_dep/pyproject.toml | 2 +- 23 files changed, 40 insertions(+), 28 deletions(-) diff --git a/Changelog.md b/Changelog.md index 25bdac14d..47ce21625 100644 --- a/Changelog.md +++ b/Changelog.md @@ -11,8 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [0.15.2] - 2023-05-16 - * When determining the python module name, use pyproject.toml `project.name` over Cargo.toml `package.name` in [#1608](https://github.com/PyO3/maturin/pull/1608) - * Fix rewriting `dev-dependencies` in sdist in [#1610](https://github.com/PyO3/maturin/pull/1610) +* When determining the python module name, use pyproject.toml `project.name` over Cargo.toml `package.name` in [#1608](https://github.com/PyO3/maturin/pull/1608) +* Fix rewriting `dev-dependencies` in sdist in [#1610](https://github.com/PyO3/maturin/pull/1610) +* Add PEP 517 `config_settings` support in [#1619](https://github.com/PyO3/maturin/pull/1619), + deprecate `MATURIN_PEP517_ARGS` in favor of the new `build-args` config setting. ## [0.15.1] - 2023-05-07 diff --git a/maturin/__init__.py b/maturin/__init__.py index 95e31c945..715ea7496 100644 --- a/maturin/__init__.py +++ b/maturin/__init__.py @@ -32,9 +32,19 @@ def get_config() -> Dict[str, str]: return pyproject_toml.get("tool", {}).get("maturin", {}) -def get_maturin_pep517_args() -> list[str]: - args = shlex.split(os.getenv("MATURIN_PEP517_ARGS", "")) - return args +def get_maturin_pep517_args( + config_settings: Mapping[str, Any] | None = None +) -> list[str]: + build_args = config_settings.get("build-args") if config_settings else None + if build_args is None: + args = os.getenv("MATURIN_PEP517_ARGS", "") + if args: + print( + f"'MATURIN_PEP517_ARGS' is deprecated, use `--config-settings build-args='{args}'` instead." + ) + else: + args = build_args + return shlex.split(args) def _additional_pep517_args() -> list[str]: @@ -68,7 +78,7 @@ def _build_wheel( if editable: command.append("--editable") - pep517_args = get_maturin_pep517_args() + pep517_args = get_maturin_pep517_args(config_settings) if pep517_args: command.extend(pep517_args) @@ -185,7 +195,7 @@ def prepare_metadata_for_build_wheel( sys.executable, ] command.extend(_additional_pep517_args()) - pep517_args = get_maturin_pep517_args() + pep517_args = get_maturin_pep517_args(config_settings) if pep517_args: command.extend(pep517_args) diff --git a/test-crates/cffi-mixed/pyproject.toml b/test-crates/cffi-mixed/pyproject.toml index 6c4d09597..d85bc7c65 100644 --- a/test-crates/cffi-mixed/pyproject.toml +++ b/test-crates/cffi-mixed/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["maturin>=0.14,<0.15"] +requires = ["maturin>=0.15,<0.16"] build-backend = "maturin" [project] diff --git a/test-crates/cffi-pure/pyproject.toml b/test-crates/cffi-pure/pyproject.toml index 3ba6723ac..459e5b1af 100644 --- a/test-crates/cffi-pure/pyproject.toml +++ b/test-crates/cffi-pure/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["maturin>=0.14,<0.15"] +requires = ["maturin>=0.15,<0.16"] build-backend = "maturin" [project] diff --git a/test-crates/hello-world/pyproject.toml b/test-crates/hello-world/pyproject.toml index cd8509ab2..fafa810fd 100644 --- a/test-crates/hello-world/pyproject.toml +++ b/test-crates/hello-world/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["maturin>=0.14,<0.15"] +requires = ["maturin>=0.15,<0.16"] build-backend = "maturin" [tool.maturin] diff --git a/test-crates/lib_with_disallowed_lib/pyproject.toml b/test-crates/lib_with_disallowed_lib/pyproject.toml index 50dd4f373..0a5cfde15 100644 --- a/test-crates/lib_with_disallowed_lib/pyproject.toml +++ b/test-crates/lib_with_disallowed_lib/pyproject.toml @@ -1,3 +1,3 @@ [build-system] -requires = ["maturin>=0.14,<0.15"] +requires = ["maturin>=0.15,<0.16"] build-backend = "maturin" diff --git a/test-crates/lib_with_path_dep/pyproject.toml b/test-crates/lib_with_path_dep/pyproject.toml index 50dd4f373..0a5cfde15 100644 --- a/test-crates/lib_with_path_dep/pyproject.toml +++ b/test-crates/lib_with_path_dep/pyproject.toml @@ -1,3 +1,3 @@ [build-system] -requires = ["maturin>=0.14,<0.15"] +requires = ["maturin>=0.15,<0.16"] build-backend = "maturin" diff --git a/test-crates/license-test/pyproject.toml b/test-crates/license-test/pyproject.toml index e4e09b62f..5ea2cc0e9 100644 --- a/test-crates/license-test/pyproject.toml +++ b/test-crates/license-test/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["maturin>=0.14,<0.15"] +requires = ["maturin>=0.15,<0.16"] build-backend = "maturin" [project] diff --git a/test-crates/pyo3-ffi-pure/pyproject.toml b/test-crates/pyo3-ffi-pure/pyproject.toml index 516d51370..8a3bd9e94 100644 --- a/test-crates/pyo3-ffi-pure/pyproject.toml +++ b/test-crates/pyo3-ffi-pure/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["maturin>=0.14,<0.15"] +requires = ["maturin>=0.15,<0.16"] build-backend = "maturin" [project] diff --git a/test-crates/pyo3-mixed-include-exclude/pyproject.toml b/test-crates/pyo3-mixed-include-exclude/pyproject.toml index d1d596b79..18e97f1cf 100644 --- a/test-crates/pyo3-mixed-include-exclude/pyproject.toml +++ b/test-crates/pyo3-mixed-include-exclude/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["maturin>=0.14,<0.15"] +requires = ["maturin>=0.15,<0.16"] build-backend = "maturin" [project] diff --git a/test-crates/pyo3-mixed-py-subdir/pyproject.toml b/test-crates/pyo3-mixed-py-subdir/pyproject.toml index 0f11e634b..fe4bb6135 100644 --- a/test-crates/pyo3-mixed-py-subdir/pyproject.toml +++ b/test-crates/pyo3-mixed-py-subdir/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["maturin>=0.14,<0.15"] +requires = ["maturin>=0.15,<0.16"] build-backend = "maturin" [project] diff --git a/test-crates/pyo3-mixed-src/pyproject.toml b/test-crates/pyo3-mixed-src/pyproject.toml index 4294e0c07..41dd5a6e1 100644 --- a/test-crates/pyo3-mixed-src/pyproject.toml +++ b/test-crates/pyo3-mixed-src/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["maturin>=0.14,<0.15"] +requires = ["maturin>=0.15,<0.16"] build-backend = "maturin" [project] diff --git a/test-crates/pyo3-mixed-submodule/pyproject.toml b/test-crates/pyo3-mixed-submodule/pyproject.toml index be3882d7b..f3e530137 100644 --- a/test-crates/pyo3-mixed-submodule/pyproject.toml +++ b/test-crates/pyo3-mixed-submodule/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["maturin>=0.14,<0.15"] +requires = ["maturin>=0.15,<0.16"] build-backend = "maturin" [project] diff --git a/test-crates/pyo3-mixed/pyproject.toml b/test-crates/pyo3-mixed/pyproject.toml index 921fa44f7..8bb5783a8 100644 --- a/test-crates/pyo3-mixed/pyproject.toml +++ b/test-crates/pyo3-mixed/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["maturin>=0.14,<0.15"] +requires = ["maturin>=0.15,<0.16"] build-backend = "maturin" [project] diff --git a/test-crates/pyo3-pure/pyproject.toml b/test-crates/pyo3-pure/pyproject.toml index c91540e7f..24d3d8af5 100644 --- a/test-crates/pyo3-pure/pyproject.toml +++ b/test-crates/pyo3-pure/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["maturin>=0.14,<0.15"] +requires = ["maturin>=0.15,<0.16"] build-backend = "maturin" [tool.maturin] diff --git a/test-crates/sdist_with_path_dep/pyproject.toml b/test-crates/sdist_with_path_dep/pyproject.toml index 50dd4f373..0a5cfde15 100644 --- a/test-crates/sdist_with_path_dep/pyproject.toml +++ b/test-crates/sdist_with_path_dep/pyproject.toml @@ -1,3 +1,3 @@ [build-system] -requires = ["maturin>=0.14,<0.15"] +requires = ["maturin>=0.15,<0.16"] build-backend = "maturin" diff --git a/test-crates/sdist_with_target_path_dep/pyproject.toml b/test-crates/sdist_with_target_path_dep/pyproject.toml index 50dd4f373..0a5cfde15 100644 --- a/test-crates/sdist_with_target_path_dep/pyproject.toml +++ b/test-crates/sdist_with_target_path_dep/pyproject.toml @@ -1,3 +1,3 @@ [build-system] -requires = ["maturin>=0.14,<0.15"] +requires = ["maturin>=0.15,<0.16"] build-backend = "maturin" diff --git a/test-crates/uniffi-mixed/pyproject.toml b/test-crates/uniffi-mixed/pyproject.toml index 2a85827c3..fde26cf34 100644 --- a/test-crates/uniffi-mixed/pyproject.toml +++ b/test-crates/uniffi-mixed/pyproject.toml @@ -1,3 +1,3 @@ [build-system] -requires = ["maturin>=0.14,<0.15"] +requires = ["maturin>=0.15,<0.16"] build-backend = "maturin" \ No newline at end of file diff --git a/test-crates/uniffi-pure/pyproject.toml b/test-crates/uniffi-pure/pyproject.toml index 2a85827c3..fde26cf34 100644 --- a/test-crates/uniffi-pure/pyproject.toml +++ b/test-crates/uniffi-pure/pyproject.toml @@ -1,3 +1,3 @@ [build-system] -requires = ["maturin>=0.14,<0.15"] +requires = ["maturin>=0.15,<0.16"] build-backend = "maturin" \ No newline at end of file diff --git a/test-crates/with-data/pyproject.toml b/test-crates/with-data/pyproject.toml index a643585d0..2e79399a1 100644 --- a/test-crates/with-data/pyproject.toml +++ b/test-crates/with-data/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["maturin>=0.14,<0.15"] +requires = ["maturin>=0.15,<0.16"] build-backend = "maturin" [project] diff --git a/test-crates/workspace-inheritance/python/pyproject.toml b/test-crates/workspace-inheritance/python/pyproject.toml index 50dd4f373..0a5cfde15 100644 --- a/test-crates/workspace-inheritance/python/pyproject.toml +++ b/test-crates/workspace-inheritance/python/pyproject.toml @@ -1,3 +1,3 @@ [build-system] -requires = ["maturin>=0.14,<0.15"] +requires = ["maturin>=0.15,<0.16"] build-backend = "maturin" diff --git a/test-crates/workspace/py/pyproject.toml b/test-crates/workspace/py/pyproject.toml index 50dd4f373..0a5cfde15 100644 --- a/test-crates/workspace/py/pyproject.toml +++ b/test-crates/workspace/py/pyproject.toml @@ -1,3 +1,3 @@ [build-system] -requires = ["maturin>=0.14,<0.15"] +requires = ["maturin>=0.15,<0.16"] build-backend = "maturin" diff --git a/test-crates/workspace_with_path_dep/pyproject.toml b/test-crates/workspace_with_path_dep/pyproject.toml index b79c30ced..a36eb149c 100644 --- a/test-crates/workspace_with_path_dep/pyproject.toml +++ b/test-crates/workspace_with_path_dep/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["maturin>=0.14,<0.15"] +requires = ["maturin>=0.15,<0.16"] build-backend = "maturin" [tool.maturin]