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

[BUG] pyproject.toml file not found #249

Closed
thatlittleboy opened this issue Jan 5, 2025 · 11 comments
Closed

[BUG] pyproject.toml file not found #249

thatlittleboy opened this issue Jan 5, 2025 · 11 comments
Labels
bug Something isn't working

Comments

@thatlittleboy
Copy link

Describe the bug A clear and concise description of what the bug is.

I'm getting an error when running pycln using pre-commit:

FileNotFoundError: [Errno 2] No such file or directory: '/Users/xxxx/.cache/pre-commit/reposmuty_h8/py_env-python3/lib/python3.10/site-packages/pyproject.toml'

Though it's important to note that this doesn't happen if I install pre-commit using pipx or (pip in its own virtual environment).

To Reproduce Steps to reproduce the behavior:

  1. Some minimal setup for pre-commit + pycln:

    python -m venv venv
    venv/bin/python -m pip install pre-commit
    touch a.py  # need a file for pycln to work on
    git init  # git repo is needed for pre-commit to work
    git add a.py
    
    cat <<EOF > .pre-commit-config.yaml
    repos:
     - repo: https://github.com/hadialqattan/pycln
       rev: v2.4.0
       hooks:
         - id: pycln
    EOF
    
    venv/bin/pre-commit install --install-hooks
  2. Run Pycln via pre-commit:

    $ venv/bin/pre-commit run --all-files pycln
  3. Error traceback:

    pycln....................................................................Failed
    - hook id: pycln
    - exit code: 1
    
    Traceback (most recent call last):
      File "/Users/xxx/.cache/pre-commit/repoj86vpxl5/py_env-python3/bin/pycln", line 5, in <module>
        from pycln.cli import app
      File "/Users/xxx/.cache/pre-commit/repoj86vpxl5/py_env-python3/lib/python3.10/site-packages/pycln/__init__.py", line 25, in <module>
        with tokenize.open(PYPROJECT_PATH) as toml_f:
      File "/Users/xxx/.pyenv/versions/3.10.13/lib/python3.10/tokenize.py", line 394, in open
        buffer = _builtin_open(filename, 'rb')
    FileNotFoundError: [Errno 2] No such file or directory: '/Users/xxx/.cache/pre-commit/repoj86vpxl5/py_env-python3/lib/python3.10/site-packages/pyproject.toml'

Expected behavior:

  1. Description: No errors to occur with pre-commit. pre-commit is the de-facto way of running tools like pycln, so I expect this to work in general.

Environment (please complete the following informations):

  • Python Version: python 3.10
  • Pycln Version: 2.4.0 (same error happens with 2.3.0)
  • Precommit version: 4.0.1 (same error happens with 3.8.0)
  • OS Type: MacOS Sonoma

Additional context Add any other context about the problem here.

I debugged the issue abit. Taking a look at the error message, it seems that it is trying to look for pycln's pyproject.toml file inside the site_packages directory, which I thought was a bit weird.

But then if I install pycln using pipx, and take a look at the environment set up there:

$ pipx environment --value PIPX_HOME
/Users/xxx/Library/Application Support/pipx
$ ls -l "/Users/xxx/Library/Application Support/pipx/venvs/pycln/lib/python3.10/site-packages/"
...
pycln
pycln-2.4.0.dist-info
...
pyproject.toml

pycln's pyprojet.toml appears in the site-packages, which is why it works when installed via pipx.

Is there an issue with the installation here or it's expected to be be polluting the site-packages directory with pycln's own pyproject.toml? seems like an off-by-one directory bug...?

@thatlittleboy thatlittleboy added the bug Something isn't working label Jan 5, 2025
@thatlittleboy
Copy link
Author

I see this is a duplicate of #228.. can you fix this issue please? @hadialqattan

@or150
Copy link
Contributor

or150 commented Jan 5, 2025

Hi,

Opened a PR that should fix this: #250

@florian-sattler
Copy link

Does anyone know a workaround for pre-commit in CI?

Also: Why does this start failing now? There didn't seem to be any changes in this repo or in our pre-commit config. I'm perplexed.

@aannara
Copy link

aannara commented Jan 6, 2025

I am also getting the same error in a GitHub workflow which has pycln==v2.2.2 in the .pre-commit-config.yaml file.

I am surprised about why I am getting this error today when I have been using this same config for more than an year.
Can someone explain the why of the issue once it is debugged please?

@damian-broniowski
Copy link

damian-broniowski commented Jan 6, 2025

+1
Same issue running v2.4.0 issue started a couple of days ago. No configuration changes so a bit weird

@aleksandrgordienko
Copy link

+1

1 similar comment
@annie4ka99
Copy link

+1

@hadialqattan
Copy link
Owner

sorry for being late, please use v2.5.0 as it has the fix; thanks to @or150 .

@aannara
Copy link

aannara commented Jan 7, 2025

sorry for being late, please use v2.5.0 as it has the fix; thanks to @or150 .

@or150 or @hadialqattan can you please help me understand how did previous versions fail in CI? How does a bug enter an existing version of the project without config changes?

@hadialqattan
Copy link
Owner

sorry for being late, please use v2.5.0 as it has the fix; thanks to @or150 .

@or150 or @hadialqattan can you please help me understand how did previous versions fail in CI? How does a bug enter an existing version of the project without config changes?

It doesn't unless your CI system uses the latest version of Poetry (poetry-core v2).

@aannara
Copy link

aannara commented Jan 8, 2025

sorry for being late, please use v2.5.0 as it has the fix; thanks to @or150 .

@or150 or @hadialqattan can you please help me understand how did previous versions fail in CI? How does a bug enter an existing version of the project without config changes?

It doesn't unless your CI system uses the latest version of Poetry (poetry-core v2).

I am using poetry version 1.5.1 which uses poetry-core version 1.6.1 as per GitHub release. So I don't think this is the case for me.
Unless below line in my pyproject.toml forces poetry-core v2 (I don't think that's the case):

[build-system]
requires = [
    "poetry-core",
]

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

No branches or pull requests

8 participants