Skip to content

Commit

Permalink
upgrade to latest maturin. Fixed failing tests added added debug tools
Browse files Browse the repository at this point in the history
  • Loading branch information
mbway committed Nov 30, 2024
1 parent d0f9c93 commit 6c48ac7
Show file tree
Hide file tree
Showing 20 changed files with 195 additions and 115 deletions.
10 changes: 6 additions & 4 deletions src/maturin_import_hook/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,12 @@ def _main() -> None:
install.add_argument(
"--user",
action="store_true",
help="whether to install into usercustomize.py instead of sitecustomize.py. "
"Note that usercustomize.py is shared between virtualenvs of the same interpreter version and is not loaded "
"unless the virtualenv is created with the `--system-site-packages` argument. Use `site info` to check "
"whether usercustomize.py is loaded the current interpreter.",
help=(
"whether to install into usercustomize.py instead of sitecustomize.py. "
"Note that usercustomize.py is shared between virtualenvs of the same interpreter version and is "
"not loaded unless the virtualenv is created with the `--system-site-packages` argument. "
"Use `site info` to check whether usercustomize.py is loaded the current interpreter."
),
)

uninstall = site_sub_actions.add_parser(
Expand Down
14 changes: 12 additions & 2 deletions src/maturin_import_hook/_resolve_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def all_path_dependencies(self) -> list[Path]:
def _find_all_path_dependencies(immediate_path_dependencies: list[Path]) -> list[Path]:
if not immediate_path_dependencies:
return []
all_path_dependencies = set()
all_path_dependencies: set[Path] = set()
to_search = immediate_path_dependencies.copy()
while to_search:
dependency_project_dir = to_search.pop()
Expand Down Expand Up @@ -170,6 +170,9 @@ def _resolve_project(project_dir: Path) -> MaturinProject:
msg = "no pyproject.toml found"
raise _ProjectResolveError(msg)
pyproject = _TomlFile.load(pyproject_path)
if not _is_valid_pyproject(pyproject):
msg = "pyproject.toml is invalid (does not have required fields)"
raise _ProjectResolveError(msg)

manifest_path = find_cargo_manifest(project_dir)
if manifest_path is None:
Expand Down Expand Up @@ -203,6 +206,13 @@ def _resolve_project(project_dir: Path) -> MaturinProject:
)


def _is_valid_pyproject(pyproject: _TomlFile) -> bool:
"""in maturin serde is used to load into a `PyProjectToml` struct.
This function should match whether the toml would parse correctly"""
# it should be sufficient to check the required fields rather than match the serde parsing logic exactly
return pyproject.get_value(["build-system", "requires"], list) is not None


def _resolve_rust_module(python_dir: Path, module_name: str) -> tuple[Path, Path, str]:
"""This follows the same logic as project_layout.rs (ProjectLayout::determine).
Expand Down Expand Up @@ -244,7 +254,7 @@ def _resolve_module_name(pyproject: _TomlFile, cargo: _TomlFile) -> Optional[str


def _get_immediate_path_dependencies(manifest_dir_path: Path, cargo: _TomlFile) -> list[Path]:
path_dependencies = []
path_dependencies: list[Path] = []
for dependency in cargo.get_value_or_default(["dependencies"], dict, {}).values():
if isinstance(dependency, dict):
relative_path: Any = dependency.get("path", None)
Expand Down
2 changes: 2 additions & 0 deletions src/maturin_import_hook/project_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ def find_spec(
logger.info('rebuilt and loaded package "%s" in %.3fs', package_name, duration)
else:
logger.debug('loaded package "%s" in %.3fs', package_name, duration)
elif logger.isEnabledFor(logging.DEBUG):
logger.debug('%s did not find "%s"', type(self).__name__, package_name)
return spec

def _handle_reload(self, package_name: str, spec: ModuleSpec) -> ModuleSpec:
Expand Down
2 changes: 2 additions & 0 deletions src/maturin_import_hook/rust_file_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ def find_spec(
logger.info('rebuilt and loaded module "%s" in %.3fs', fullname, duration)
else:
logger.debug('loaded module "%s" in %.3fs', fullname, duration)
elif logger.isEnabledFor(logging.DEBUG):
logger.debug('%s did not find "%s"', type(self).__name__, fullname)

return spec

Expand Down
2 changes: 1 addition & 1 deletion tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ To update maturin:
- update the submodule to the maturin commit you want to update to
- re-run the `package_resolver` to update `resolved.json` (see `package_resolver/README.md` for instructions)
- update `requirements.txt` to match the packages and versions installed by the maturin ci
(see `pip install` commands in `maturin/.github/workflows/test.yml`)
(see `pip` and `uv` commands in `maturin/.github/workflows/test.yml`)
- check the `uniffi` package version listed in the `Cargo.toml` of any of the `uniffi-*`
test crates and update `uniffi-bindgen` in `requirements.txt` to match.
- check that no crates have been added to `test-crates` that should be excluded from the import hook tests.
Expand Down
2 changes: 1 addition & 1 deletion tests/maturin
Submodule maturin updated 97 files
+0 −45 .github/workflows/delete-comments.yml
+1 −1 .github/workflows/downstream.yml
+0 −47 .github/workflows/lint.yml
+0 −9 .github/workflows/release.yml
+148 −191 .github/workflows/test.yml
+1 −1 .github/workflows/update-auditwheel.yml
+3 −3 .pre-commit-config.yaml
+410 −179 Cargo.lock
+6 −5 Cargo.toml
+11 −0 Changelog.md
+9 −9 Dockerfile
+0 −51 ci/build_deb.sh
+3 −0 deny.toml
+ guide/src/assets/sponsors/prefect.png
+4 −4 guide/src/bindings.md
+1 −2 guide/src/contributing.md
+1 −1 guide/src/import_hook.md
+6 −0 guide/src/index.md
+6 −6 guide/src/tutorial.md
+1 −1 src/auditwheel/audit.rs
+3 −9 src/build_context.rs
+146 −48 src/build_options.rs
+316 −64 src/ci.rs
+1 −0 src/cross_compile.rs
+6 −1 src/develop.rs
+38 −6 src/main.rs
+2 −2 src/metadata.rs
+39 −15 src/module_writer.rs
+127 −29 src/python_interpreter/config.rs
+1 −0 src/python_interpreter/get_interpreter_metadata.py
+41 −32 src/python_interpreter/mod.rs
+39 −17 src/source_distribution.rs
+13 −1 src/target.rs
+1 −1 src/templates/Cargo.toml.j2
+1,039 −0 sysconfig/cpython-gnu-3.12.txt
+10 −10 test-crates/lib_with_disallowed_lib/Cargo.lock
+1 −1 test-crates/lib_with_disallowed_lib/Cargo.toml
+1 −2 test-crates/lib_with_path_dep/Cargo.toml
+4 −129 test-crates/lib_with_path_dep/src/lib.rs
+10 −10 test-crates/pyo3-abi3-without-version/Cargo.lock
+1 −1 test-crates/pyo3-abi3-without-version/Cargo.toml
+10 −10 test-crates/pyo3-bin/Cargo.lock
+1 −1 test-crates/pyo3-bin/Cargo.toml
+1 −1 test-crates/pyo3-bin/src/main.rs
+10 −10 test-crates/pyo3-feature/Cargo.lock
+1 −1 test-crates/pyo3-feature/Cargo.toml
+10 −10 test-crates/pyo3-mixed-implicit/Cargo.lock
+1 −1 test-crates/pyo3-mixed-implicit/Cargo.toml
+10 −10 test-crates/pyo3-mixed-include-exclude/Cargo.lock
+1 −1 test-crates/pyo3-mixed-include-exclude/Cargo.toml
+10 −10 test-crates/pyo3-mixed-py-subdir/Cargo.lock
+1 −1 test-crates/pyo3-mixed-py-subdir/Cargo.toml
+10 −10 test-crates/pyo3-mixed-src/rust/Cargo.lock
+1 −1 test-crates/pyo3-mixed-src/rust/Cargo.toml
+10 −10 test-crates/pyo3-mixed-submodule/Cargo.lock
+1 −1 test-crates/pyo3-mixed-submodule/Cargo.toml
+10 −10 test-crates/pyo3-mixed-with-path-dep/Cargo.lock
+1 −1 test-crates/pyo3-mixed-with-path-dep/Cargo.toml
+10 −10 test-crates/pyo3-mixed-workspace/rust/Cargo.lock
+1 −1 test-crates/pyo3-mixed-workspace/rust/python/pyo3-mixed-workspace-py/Cargo.toml
+10 −10 test-crates/pyo3-mixed/Cargo.lock
+1 −1 test-crates/pyo3-mixed/Cargo.toml
+1 −1 test-crates/pyo3-mixed/src/lib.rs
+6 −6 test-crates/pyo3-no-extension-module/Cargo.lock
+1 −1 test-crates/pyo3-no-extension-module/Cargo.toml
+10 −10 test-crates/pyo3-pure/Cargo.lock
+1 −1 test-crates/pyo3-pure/Cargo.toml
+10 −10 test-crates/readme-duplication/Cargo.lock
+1 −1 test-crates/readme-duplication/readme-py/Cargo.toml
+87 −6 test-crates/sdist_with_path_dep/Cargo.lock
+1 −2 test-crates/sdist_with_path_dep/Cargo.toml
+4 −129 test-crates/sdist_with_path_dep/src/lib.rs
+87 −6 test-crates/sdist_with_target_path_dep/Cargo.lock
+1 −2 test-crates/sdist_with_target_path_dep/Cargo.toml
+4 −129 test-crates/sdist_with_target_path_dep/src/lib.rs
+10 −10 test-crates/workspace-inheritance/Cargo.lock
+1 −1 test-crates/workspace-inheritance/python/Cargo.toml
+176 −0 test-crates/workspace-inverted-order/Cargo.lock
+17 −0 test-crates/workspace-inverted-order/Cargo.toml
+3 −0 test-crates/workspace-inverted-order/README.md
+6 −0 test-crates/workspace-inverted-order/check_installed/check_installed.py
+13 −0 test-crates/workspace-inverted-order/path-dep-with-root/Cargo.toml
+1 −0 test-crates/workspace-inverted-order/path-dep-with-root/README.md
+8 −0 test-crates/workspace-inverted-order/path-dep-with-root/pyproject.toml
+12 −0 test-crates/workspace-inverted-order/path-dep-with-root/src/lib.rs
+2 −0 test-crates/workspace-inverted-order/pyproject.toml
+1 −0 test-crates/workspace-inverted-order/src/lib.rs
+10 −10 test-crates/workspace_with_path_dep/Cargo.lock
+1 −1 test-crates/workspace_with_path_dep/python/Cargo.toml
+3 −0 tests/cmd/generate-ci.stdout
+22 −4 tests/common/errors.rs
+96 −32 tests/common/integration.rs
+10 −4 tests/common/mod.rs
+49 −8 tests/common/other.rs
+1 −3 tests/manylinux_compliant.sh
+2 −4 tests/manylinux_incompliant.sh
+25 −12 tests/run.rs
77 changes: 32 additions & 45 deletions tests/package_resolver/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/package_resolver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
publish = false

[dependencies]
anyhow = "1.0.79"
anyhow = "1.0.93"
maturin = { path = "../maturin" }
serde = { version = "1.0.195", features = ["derive"] }
serde_json = "1.0.111"
serde_json = "1.0.133"
13 changes: 11 additions & 2 deletions tests/package_resolver/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn resolve_package(project_root: &Path) -> Result<Value> {
let _cwd = TemporaryChdir::chdir(&project_root)?;

let build_options: BuildOptions = Default::default();
let build_context = build_options.into_build_context(false, false, false)?;
let build_context = build_options.into_build_context().build()?;
let extension_module_dir = if build_context.project_layout.python_module.is_some() {
Some(relative_path(
&build_context.project_layout.rust_module,
Expand Down Expand Up @@ -74,7 +74,16 @@ fn resolve_all_packages(test_crates_dir: &Path) -> Result<Value> {
for path in entries {
if path.join("pyproject.toml").exists() {
let project_name = path.file_name().unwrap().to_str().unwrap().to_owned();
resolved_packages.insert(project_name, resolve_package(&path).unwrap_or(Value::Null));
println!("resolve '{}'", project_name);
match resolve_package(&path) {
Ok(value) => {
resolved_packages.insert(project_name, value);
}
Err(err) => {
println!("resolve failed with: {:?}", err);
resolved_packages.insert(project_name, Value::Null);
}
}
}
}
Ok(Value::Object(resolved_packages))
Expand Down
2 changes: 1 addition & 1 deletion tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-e ..
uv
maturin==1.7.4
maturin==1.7.6
pytest
junit2html
uniffi-bindgen==0.28.0
Expand Down
3 changes: 2 additions & 1 deletion tests/resolved.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"commit": "aebadedec43a92a1ba0fe94980c84f37122aa5b3",
"commit": "d896c62f31ded33adca2f58819913e29b7950299",
"crates": {
"cffi-mixed": {
"cargo_manifest_path": "Cargo.toml",
Expand Down Expand Up @@ -155,6 +155,7 @@
"python_dir": ".",
"python_module": null
},
"workspace-inverted-order": null,
"wrong-python-source": {
"cargo_manifest_path": "Cargo.toml",
"extension_module_dir": null,
Expand Down
Loading

0 comments on commit 6c48ac7

Please sign in to comment.