'Pre-release version number in mixed python/rust project with maturin

I am working on a mixed Rust/Python project being build with maturin. I am having trouble figuring out how I can specify a pre-release version that can than be installed by pip.

The start of my Cargo.toml is

[package]
version = "0.0.1-test.1"

When I do maturin build --release, it creates my_project-0.0.1_test.1-cp39-cp39-macosx_10_7_x86_64.whl. Note that 0.0.1-test.1 in the version was changed to 0.0.1_test.1 in the name of the wheel file. (The dash became an underscore.)

If I publish this to my Nexus server and try to install it in a separate project, pip gives an error:

$ pip install  my_project==0.0.1_test.1
Looking in indexes: ...
ERROR: Could not find a version that satisfies the requirement my_project==0.0.1_test.1 (from versions: 0.0.1-test.1, 0.0.1.dev1)

If I try it with a dash instead of an underscore:

pip install  py_mod_query_builder==0.0.1-test.1
Looking in indexes: ...
ERROR: Exception:
<stack trace>
pip._vendor.packaging.version.InvalidVersion: Invalid version: '0.0.1-test.1'

If I change the version in Cargo.toml to 0.0.1_troy.1, then Cargo fails to parse the build file:

$ maturin build --release
🍹 Building a mixed python/rust project
💥 maturin failed
  Caused by: Cargo metadata failed. Do you have cargo in your PATH?
  Caused by: Error during execution of `cargo metadata`: error: failed to parse manifest at `/Users/me/my-project/Cargo.toml`

Caused by:
  unexpected character '_' after patch version number for key `package.version`

I did have some success with pip install path/to/my_project*.whl. However, that is difficult to incorporate into building a docker image. The wheel is outside the project with the Dockerfile, so docker will not be able to find it without jumping through a bunch of hoops, while downloading it from the server during the docker build is simple, but fails due to the dash/underscore problem.

Additionally, while both projects are being developed, I would like the CI pipeline for the development branch to use the pre-release version. Getting access to the wheel file (without having pip download it) is nearly impossible in that situation.

It seems that Cargo insists on the format being #.#.#-string and pip insists on it being #.#.#_string. Is there a way to make both of them happy?

Versions:

  • Installing project
    • pip 22.1
    • python 3.9.12
  • Building project
    • pip 20.0.4
    • python 3.9.12
    • maturin 0.8.3
    • rustc 1.56.1 (59eed8a2a 2021-11-01)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source