Updating project name in maturin build

181 views Asked by At

I recently asked about how to have a CI pipeline create a wheel from a branch that could be selectively used by downstream projects. The best answer was to have it publish a wheel for my-project-branch-name instead of my-project. I have it set up so that is publishes that wheel, but pip is refusing to install it in a Linux container.

$ pip install my-project-branch-name
ERROR: Could not find a version that satisfies the requirement my-project-branch-name (from versions: 4.1.0-dev1671830602.p71777, 4.1.0-dev1671840599.p71778, 4.1.0-dev1672248459.p71870)
ERROR: No matching distribution found for my-project-branch-name

It is clearly finding the project and versions that would seem to match, but not installing them.

my-project is a mixed Rust/python project using maturin and pyo3. The project name appears in several places:

pyproject.toml

[project]
name = 'my-project'

[build-system]
requires = ["maturin >= 0.12"]
build-backend = "maturin"

<other configuration>

Cargo.toml

[package]
name = "my-project"

[lib]
name = "my_project"
crate-type = ["cdylib"]

<other config>

src/lib.rs

<imports>

#[pymodule]
fn my_project(_py: Python<'_>, m: &PyModule) -> PyResult<()> { ... }

The python source is in my_project/ and various python files do from my_project.x import Y. The downstream module also has similar imports.

I suspect the problem is that somewhere, I need to change a my-project to my-project-branch-name. Unfortunately, there are several places to do this and finding the right combination by trial and error will be difficult.

Does anyone know which places need the project name changed?

Alternatively, does anyone know how to get pip to display more information about why it is rejecting the wheels it does find?

Additional info

I have tried pip install --verbose my-project-branch-name and it does provide more output, but nothing to indicate why it is failing to install a wheel.

I manually modified the name in pyproject.toml and published a macOS wheel. That I can install via pip install my-project-branch-name.

If I manually download the linux wheel and start a Docker container, pip install my_project_branch_name*.whl successfully installs it. And I can use the classes in the wheel. I even see output from the rust code.

I want to avoid renaming the python modules, so that the downstream project can still use import my_project. Changing the dependencies is a minor change, but changing all of the imports makes it too complicated for this to be useful.

I am using Python 3.11.

1

There are 1 answers

0
Troy Daniels On

It turns out that editing the name in pyproject.toml is sufficient. The problem was that I was creating an invalid version.

4.1.0-dev1671830602.p71777

is invalid but

4.1.0-dev1671830602+p71777

is valid. (Note the plus or dot before the p.)

It does not appear to be possible to get pip to complain about this (even with -vv if you try pip install my-project (or the equivalent in a config file).

However, if you try

pip install my-project==4.1.0-dev1671830602.p71777

you will get an InvalidVersion error.

Downloading the wheel (but not with pip download) and running pip install path/to/wheel.whl works because in that case, pip does not try to infer a version from the name. I'm pretty sure you could rename the file README.txt and pip would successfully install it.