Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow valid version specifier when specifying Black version in pyproject.toml #4406

Open
nattiechan opened this issue Jul 19, 2024 · 2 comments
Labels
T: enhancement New feature or request

Comments

@nattiechan
Copy link

Is your feature request related to a problem? Please describe.

This could be a user error, and if so, please let me know how to achieve the desired result :)

The documentation states that if we use version in the GitHub (GH) action workflow, valid version specifier per Python packaging standards can be used. This means we can do:

- uses: psf/black@stable
  with:
    options: "--check --verbose"
    src: "./src"
    version: ">= 23.4"

However, if we have a pyproject.toml file for other configurations in addition to version and wish GH action to use the same configuration for checks, we have to use tool.black.required-version field because as I discovered through trial and error, version in GH version workflow and use_pyproject are mutually exclusive.

> Run psf/black@stable
> Run # Even when black fails, do not close the shell
Error: 'with.version' and 'with.use_pyproject' inputs are mutually exclusive.

Error: Process completed with exit code 1.

And when I tried to do required-version: >=24.3 in pyproject.toml, I encountered the following issue on GH actions:

> Run psf/black@stable
> Run # Even when black fails, do not close the shell
Error: Failed to install Black.
Installing black[colorama]==>=24.3...
ERROR: Could not find a version that satisfies the requirement black[colorama]==>=24.3 (from versions: 18.3a0, 18.3a1, 18.3a2, 18.3a3, 18.3a4, 18.4a0, 18.4a1, 18.4a2, 18.4a3, 18.4a4, 18.5b0, 18.5b1, 18.6b0, 18.6b1, 18.6b2, 18.6b3, 18.6b4, 18.9b0, 19.3b0, 19.10b0, 20.8b0, 20.8b1, 21.4b0, 21.4b1, 21.4b2, 21.5b0, 21.5b1, 21.5b2, 21.6b0, 21.7b0, 21.8b0, 21.9b0, 21.10b0, 21.11b0, 21.11b1, 21.12b0, 22.1.0, 22.3.0, 22.6.0, 22.8.0, 22.10.0, 22.12.0, 23.1a1, 23.1.0, 23.3.0, 23.7.0, 23.9.0, 23.9.1, 23.10.0, 23.10.1, 23.11.0, 23.12.0, 23.12.1, 24.1a1, 24.1.0, 24.1.1, 24.2.0, 24.3.0, 24.4.0, 24.4.1, 24.4.2)
ERROR: No matching distribution found for black[colorama]==>=24.3

Notice:  A new release of pip available: 22.3 -> 24.1.2
Notice:  To update, run: python -m pip install --upgrade pip
Error: Process completed with exit code 1.

The use-case here is that I would like to have a way to define a more relaxed version requirement for black in pyproject.toml, so we can have the same functionality and options as the version option in the GH actions workflow.

Describe the solution you'd like

Allow valid version specifier when specifying Black version in pyproject.toml, so the syntax will be equivalent to the version in GH actions workflow.

I will admit that I have not looked into the codebase to determine how difficult the enhancement is. If this suggestion is accepted I would be happy to look into it.

Describe alternatives you've considered

We resolved the issue by downgrading the required version in pyproject.toml to 23.4.0 for now.

Additional context

How we discovered this was that the readme for the black repo states that the latest is 24.4.2. We set up our GH actions workflow to use 24.4.2 but only recently discovered that the release version of the VS code black formatted extension still uses 23.4.0.

Screenshot 2024-07-19 at 2 13 00 PM

This causes issues locally as the stated required version in pyproject.toml file is not the same as the VS code extension.

The pre-release version, as of July 19th, 2024, uses 24.4.2.

Screenshot 2024-07-19 at 2 31 11 PM

I understand that as the new release comes out, this should not be an issue as the extension will support slightly older versions. However, this feels like a bit of inconsistency and would be very nice to have equivalent notations between the 2 fields.

@nattiechan nattiechan added the T: enhancement New feature or request label Jul 19, 2024
@hauntsaninja
Copy link
Collaborator

required-version doesn't take a specifier, but you could do something like required-version = "24" and I think it will work

and required_version != __version__.split(".")[0]

@nattiechan
Copy link
Author

I tried changing required-version to "24" and this is the output from GitHub actions

Run psf/black@stable
Run # Even when black fails, do not close the shell
Error: Failed to install Black.
Installing black[colorama]==24...
ERROR: Could not find a version that satisfies the requirement black[colorama]==24 (from versions: 18.3a0, 18.3a1, 18.3a2, 18.3a3, 18.3a4, 18.4a0, 18.4a1, 18.4a2, 18.4a3, 18.4a4, 18.5b0, 18.5b1, 18.6b0, 18.6b1, 18.6b2, 18.6b3, 18.6b4, 18.9b0, 19.3b0, 19.10b0, 20.8b0, 20.8b1, 21.4b0, 21.4b1, 21.4b2, 21.5b0, 21.5b1, 21.5b2, 21.6b0, 21.7b0, 21.8b0, 21.9b0, 21.10b0, 21.11b0, 21.11b1, 21.12b0, 22.1.0, 22.3.0, 22.6.0, 22.8.0, 22.10.0, 22.12.0, 23.1a1, 23.1.0, 23.3.0, 23.7.0, 23.9.0, 23.9.1, 23.10.0, 23.10.1, 23.11.0, 23.12.0, 23.12.1, 24.1a1, 24.1.0, 24.1.1, 24.2.0, 24.3.0, 24.4.0, 24.4.1, 24.4.2)
ERROR: No matching distribution found for black[colorama]==24

Notice:  A new release of pip available: 22.3 -> 24.1.2
Notice:  To update, run: python -m pip install --upgrade pip
Error: Process completed with exit code 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants