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

Error in github actions when using use_pyproject: true #4367

Open
Nao-Y1996 opened this issue May 18, 2024 · 2 comments
Open

Error in github actions when using use_pyproject: true #4367

Nao-Y1996 opened this issue May 18, 2024 · 2 comments
Labels
T: bug Something isn't working

Comments

@Nao-Y1996
Copy link

Describe the bug

black in github actions failed when we set use_pyproject: true
this way is discribed in here

To Reproduce

my .github/workflows/black.yml was like bellow.

name: Lint
on: [push, pull_request]
jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: psf/black@stable
        with:
          options: "--check --verbose"
          src: "."
          jupyter: false
          use_pyproject: true

and pyproject.toml was like bellow, so black is latest version.

[tool.poetry.group.dev.dependencies]
pytest = "^8.2.0"
notebook = "^7.2.0"
black = "^24.4.2"

The resulting error is lie this.
image

The yml description should be as documented, am I missing something?

when I give up to use use_pyproject: true and use version: "~= 24.4.2", no error occurred.

name: Lint

on: [push, pull_request]

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: psf/black@stable
        with:
          options: "--check --verbose"
          src: "."
          jupyter: false
          version: "~= 24.4.2"  # same as the version in pyproject.toml

Environment

  • Black's version: 24.4.2
  • OS and Python version:

Additional context

@Nao-Y1996 Nao-Y1996 added the T: bug Something isn't working label May 18, 2024
@bobwhitelock
Copy link

I ran into the same issue, but I think it's not actually a bug as the action is operating as documented, though it is a bit of a gotcha when using this with Poetry.

The docs say: "To read the version from the pyproject.toml file instead, set use_pyproject to true. This will first look into the tool.black.required-version field, then the project.dependencies array and finally the project.optional-dependencies table."

The first suggestion is a Black-specific location, and then the other 2 are standard pyproject.toml locations as described in https://peps.python.org/pep-0621/. The issue is Poetry does not follow PEP 621 (yet - see python-poetry/roadmap#3), and so it stores its dependencies in different locations - tool.poetry.dependencies and similar, and so the Black action cannot use the Poetry-specified version without redundancy.

If you add

[tool.black]
required-version = "24.4.2"

to your pyproject.toml file instead then use_pyproject will work as described.

Longer term the solution might be to note this gotcha in the docs, for Black to pick up on the Poetry syntax as well, and/or to just wait for Poetry to follow PEP 621.

@JelleZijlstra
Copy link
Collaborator

Thanks @bobwhitelock!

I don't think Black should attempt to parse the Poetry-specific section in pyproject.toml. However, I would support adding a note in the docs to address this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants