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

No such file or directory: 'flake8' #771

Open
jedie opened this issue Nov 14, 2024 · 2 comments
Open

No such file or directory: 'flake8' #771

jedie opened this issue Nov 14, 2024 · 2 comments

Comments

@jedie
Copy link
Contributor

jedie commented Nov 14, 2024

Darker didn't find flake8... It's installed in .venv, but raised this error:

DEBUG:darkgraylib.git:[~/cookiecutter_templates/generated_templates/make-uv-python/your_cool_package]$ git rev-parse --show-toplevel
DEBUG:darkgraylib.git:[~/cookiecutter_templates]$ git worktree add --quiet --force --force /tmp/tmp3z1cls2w/baseline-revision/cookiecutter_templates origin/main
DEBUG:darkgraylib.git:[~/cookiecutter_templates]$ git rev-parse origin/main
DEBUG:graylint.linting:[/tmp/tmp3z1cls2w/baseline-revision/cookiecutter_templates]$ flake8
Traceback (most recent call last):
  File "~/cookiecutter_templates/generated_templates/make-uv-python/your_cool_package/.venv/bin/darker", line 8, in <module>
    sys.exit(main_with_error_handling())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/cookiecutter_templates/generated_templates/make-uv-python/your_cool_package/.venv/lib/python3.12/site-packages/darker/__main__.py", line 633, in main_with_error_handling
    return main()
           ^^^^^^
  File "~/cookiecutter_templates/generated_templates/make-uv-python/your_cool_package/.venv/lib/python3.12/site-packages/darker/__main__.py", line 614, in main
    linter_failures_on_modified_lines = run_linters(
                                        ^^^^^^^^^^^^
  File "~/cookiecutter_templates/generated_templates/make-uv-python/your_cool_package/.venv/lib/python3.12/site-packages/graylint/linting.py", line 434, in run_linters
    baseline = _get_messages_from_linters_for_baseline(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/cookiecutter_templates/generated_templates/make-uv-python/your_cool_package/.venv/lib/python3.12/site-packages/graylint/linting.py", line 573, in _get_messages_from_linters_for_baseline
    result = _get_messages_from_linters(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/cookiecutter_templates/generated_templates/make-uv-python/your_cool_package/.venv/lib/python3.12/site-packages/graylint/linting.py", line 484, in _get_messages_from_linters
    for message_location, message in run_linter(cmdline, root, paths, env).items():
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/cookiecutter_templates/generated_templates/make-uv-python/your_cool_package/.venv/lib/python3.12/site-packages/graylint/linting.py", line 361, in run_linter
    with _check_linter_output(cmdline, root, paths, env) as linter_stdout:
  File "/usr/lib/python3.12/contextlib.py", line 137, in __enter__
    return next(self.gen)
           ^^^^^^^^^^^^^^
  File "~/cookiecutter_templates/generated_templates/make-uv-python/your_cool_package/.venv/lib/python3.12/site-packages/graylint/linting.py", line 322, in _check_linter_output
    with Popen(  # nosec
         ^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.12/subprocess.py", line 1955, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'flake8'

...

~/repos/cookiecutter_templates/generated_templates/make-uv-python/your_cool_package$ .venv/bin/flake8 --version
7.1.1 (flake8-bugbear: 24.10.31, mccabe: 0.7.0, pycodestyle: 2.12.1, pyflakes: 3.2.0) CPython 3.12.3 on Linux

Version info:

.venv/bin/uv pip freeze
...
darker==2.1.1
...
flake8==7.1.1
flake8-bugbear==24.10.31
flynt==1.0.1
graylint==1.1.1
...
pip==24.3.1
...
uv==0.5.1
...

I add a pp(locales()) into graylint.linting._check_linter_output() just before the Popen() call, looks like:

{'cmdline': 'flake8',
 'root': PosixPath('/tmp/tmpunxe_xsq/baseline-revision/cookiecutter_templates'),
 'paths': {PosixPath('generated_templates/make-uv-python/your_cool_package/.venv/bin')},
 'env': {'SHELL': '/bin/bash',
        ...
         'PWD': '/home/jens/repos/cookiecutter_templates/generated_templates/make-uv-python/your_cool_package/.venv/bin',
        ...
         'PATH': '/home/jens/.local/bin:/home/jens/.local/bin:/home/jens/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin',
        ...
         'OLDPWD': '/home/jens/repos/cookiecutter_templates/generated_templates/make-uv-python/your_cool_package',
         '_': './darker',
         'GRAYLINT_ORIG_REPO': '/home/jens/repos/cookiecutter_templates',
         'GRAYLINT_REV_COMMIT': 'ff48b81'},
 'cmdline_parts': ['flake8'],
 'existing_path_strs': [],
 'cmdline_and_paths': ['flake8']}
@akaihola
Copy link
Owner

akaihola commented Nov 16, 2024

Hi @jedie, thanks for the report!

I didn't yet succeed to reproduce, could you advise?

uv venv
. .venv/bin/activate
uv pip install darker==2.1.1 flake8==7.1.1
darker --diff --lint=flake8 ~/mypackage/src

The above commands succeed, and these packages are installed in .venv:

$ uv pip freeze
...
darker==2.1.1
...
flake8==7.1.1
graylint==1.1.1
...

I also tried

  • without activating the virtualenv and running .venv/bin/darker instead
  • using python -m venv .venv and .venv/bin/pip install uv, and then using .venv/bin/uv instead of my global uv instance.

Still succeeds in both cases.

@akaihola
Copy link
Owner

Looking at items from your pp(locals()) output:

{'root': PosixPath('/tmp/tmpunxe_xsq/baseline-revision/cookiecutter_templates'),
 'paths': {PosixPath('generated_templates/make-uv-python/your_cool_package/.venv/bin')},

it seems the only .py files Darker has found are in your .../.venv/bin directory.

 'env': {
     'PWD': '/home/jens/repos/cookiecutter_templates/generated_templates/make-uv-python/your_cool_package/.venv/bin',

Graylint likes to cd into the deepest common parent directory of found .py files, so .../.venv/bin in this case...

     'PATH': '/home/jens/.local/bin:/home/jens/.local/bin:/home/jens/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin',

...and for some reason your that .../.venv/bin directory of your virtualenv has disappeared from the system path.

Do you get the same behavior if you

  • run graylint --lint=flake8 (or whatever your original Darker command line was) directly, or
  • run Darker in a real project repository with .py files also outside .venv, or
  • place .venv outside your project repository instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants