tox-dev / pyproject-fmt

MIT License
167 stars 27 forks source link

Exception on `~=` version specifiers #215

Closed not7cd closed 4 months ago

not7cd commented 4 months ago

For a minimal pyproject.toml and pyproject-fmt (2.0.3):

[project]
name = "package"
version = "1.0.0"
dependencies = ["dependency~=1.0.0", "foo~=1.2.3"]

I'm getting an exception:

thread '<unnamed>' panicked at rust/src/helpers/pep508.rs:85:44:
called `Result::unwrap()` on an `Err` value: Pep508Error { message: String("The ~= operator requires at least two segments in the release version"), start: 10, len: 3, input: "dependency~=1" }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
  File "*snip*/.local/bin/pyproject-fmt", line 10, in <module>
    sys.exit(run())
             ^^^^^
  File "*snip*/pipx/venvs/pyproject-fmt/lib/python3.12/site-packages/pyproject_fmt/__main__.py", line 71, in run
    results = [_handle_one(config) for config in configs]
               ^^^^^^^^^^^^^^^^^^^
  File "*snip*/pipx/venvs/pyproject-fmt/lib/python3.12/site-packages/pyproject_fmt/__main__.py", line 38, in _handle_one
    formatted = format_toml(config.toml, config.settings)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pyo3_runtime.PanicException: called `Result::unwrap()` on an `Err` value: Pep508Error { message: String("The ~= operator requires at least two segments in the release version"), start: 10, len: 3, input: "dependency~=1" }

It seems that during parsing, version specifier ~=1.0.0 is parsed as ~=1.

not7cd commented 4 months ago

This has been fixed in 2.0.4 (released yesterday).