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

pip-compile fails, if package pre-commit is in requirements #1657

Closed
hofrob opened this issue Jul 28, 2022 · 5 comments
Closed

pip-compile fails, if package pre-commit is in requirements #1657

hofrob opened this issue Jul 28, 2022 · 5 comments
Labels
bug Something is not working

Comments

@hofrob
Copy link

hofrob commented Jul 28, 2022

This may sound odd, but it was the only way to reproduce this bug. When using the latest pip-tools (6.8.0), any pip-compile command fails as long as the package pre-commit is installed alongside. So this may be a problem with this 3rd party package. But it worked before and the bug was introduced somewhere between pip-tools 6.6.2 and 6.8.0 (edit: introduced in 6.7.0).

Sorry for this weird description. I tried to boil it down to a more digestible description. It was quite confusing to figure this out.

Environment Versions

  1. OS: Ubuntu 22.04 (Linux 5.15.0-41-generic #44-Ubuntu SMP Wed Jun 22 14:20:53 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux)
  2. Python version: 3.10.4
  3. pip version: 22.0.2
  4. pip-tools version: 6.8.0

Steps to replicate

Example repo: https://github.com/hofrob/test-pip-tools-upgrade

  1. check out the repo
  2. create a virtual env: python -m venv venv
  3. activate venv: . venv/bin/activate
  4. install packages: pip install -r requirements.txt (it's only pip-tools and pre-commit plus dependencies)
  5. run pip-compile -o requirements.txt
  6. or pip-compile --upgrade --quiet
  7. or pip-compile --upgrade-package pip-tools --quiet

Expected result

pip-compile does not produce output and does not change the requirements file.

Actual result

$ pip-compile -o requirements.txt
Requirement already satisfied: setuptools>=40.8.0 in /usr/local/lib/python3.10/dist-packages (from -r /tmp/build-reqs-f
vosl3ot.txt (line 1)) (63.2.0)
Collecting wheel
  Using cached wheel-0.37.1-py2.py3-none-any.whl (35 kB)
Installing collected packages: wheel
ERROR: Could not install packages due to an OSError: [Errno 13] Permission denied: '/usr/local/lib/python3.10/dist-pack
ages/wheel'
Consider using the `--user` option or check the permissions.

--- Logging error ---
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/pip/_internal/utils/logging.py", line 177, in emit
    self.console.print(renderable, overflow="ignore", crop=False, style=style)
  File "/usr/local/lib/python3.10/dist-packages/pip/_vendor/rich/console.py", line 1752, in print
    extend(render(renderable, render_options))
  File "/usr/local/lib/python3.10/dist-packages/pip/_vendor/rich/console.py", line 1390, in render
    for render_output in iter_render:
  File "/usr/local/lib/python3.10/dist-packages/pip/_internal/utils/logging.py", line 134, in __rich_console__
    for line in lines:
  File "/usr/local/lib/python3.10/dist-packages/pip/_vendor/rich/segment.py", line 245, in split_lines
    for segment in segments:
  File "/usr/local/lib/python3.10/dist-packages/pip/_vendor/rich/console.py", line 1368, in render
    renderable = rich_cast(renderable)
  File "/usr/local/lib/python3.10/dist-packages/pip/_vendor/rich/protocol.py", line 36, in rich_cast
    renderable = cast_method()
  File "/usr/local/lib/python3.10/dist-packages/pip/_internal/self_outdated_check.py", line 130, in __rich__
    pip_cmd = get_best_invocation_for_this_pip()
  File "/usr/local/lib/python3.10/dist-packages/pip/_internal/utils/entrypoints.py", line 58, in get_best_invocation_fo
r_this_pip
    if found_executable and os.path.samefile(
  File "/usr/lib/python3.10/genericpath.py", line 101, in samefile
    s2 = os.stat(f2)
FileNotFoundError: [Errno 2] No such file or directory: '/usr/bin/pip'
Call stack:
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.10/dist-packages/pip/__main__.py", line 31, in <module>
    sys.exit(_main())
  File "/usr/local/lib/python3.10/dist-packages/pip/_internal/cli/main.py", line 70, in main
    return command.main(cmd_args)
  File "/usr/local/lib/python3.10/dist-packages/pip/_internal/cli/base_command.py", line 101, in main
    return self._main(args)
  File "/usr/local/lib/python3.10/dist-packages/pip/_internal/cli/base_command.py", line 223, in _main
    self.handle_pip_version_check(options)
  File "/usr/local/lib/python3.10/dist-packages/pip/_internal/cli/req_command.py", line 148, in handle_pip_version_chec
k
    pip_self_version_check(session, options)
  File "/usr/local/lib/python3.10/dist-packages/pip/_internal/self_outdated_check.py", line 237, in pip_self_version_ch
eck
    logger.info("[present-rich] %s", upgrade_prompt)
  File "/usr/lib/python3.10/logging/__init__.py", line 1477, in info
    self._log(INFO, msg, args, **kwargs)
  File "/usr/lib/python3.10/logging/__init__.py", line 1624, in _log
    self.handle(record)
  File "/usr/lib/python3.10/logging/__init__.py", line 1634, in handle
    self.callHandlers(record)
  File "/usr/lib/python3.10/logging/__init__.py", line 1696, in callHandlers
    hdlr.handle(record)
  File "/usr/lib/python3.10/logging/__init__.py", line 968, in handle
    self.emit(record)
  File "/usr/local/lib/python3.10/dist-packages/pip/_internal/utils/logging.py", line 179, in emit
    self.handleError(record)
Message: '[present-rich] %s'
Arguments: (UpgradePrompt(old='22.1.2', new='22.2.1'),)
Traceback (most recent call last):
  File "/home/[USERNAME]/test-pip-tools-upgrade/venv/bin/pip-compile", line 8, in <module>
    sys.exit(cli())
  File "/home/[USERNAME]/test-pip-tools-upgrade/venv/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/[USERNAME]/test-pip-tools-upgrade/venv/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/[USERNAME]/test-pip-tools-upgrade/venv/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/[USERNAME]/test-pip-tools-upgrade/venv/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/[USERNAME]/test-pip-tools-upgrade/venv/lib/python3.10/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/[USERNAME]/test-pip-tools-upgrade/venv/lib/python3.10/site-packages/piptools/scripts/compile.py", line 421, in cli
    metadata = project_wheel_metadata(
  File "/home/[USERNAME]/test-pip-tools-upgrade/venv/lib/python3.10/site-packages/build/util.py", line 53, in project_wheel_metadata
    env.install(builder.build_system_requires)
  File "/home/[USERNAME]/test-pip-tools-upgrade/venv/lib/python3.10/site-packages/build/env.py", line 215, in install
    _subprocess(cmd)
  File "/home/[USERNAME]/test-pip-tools-upgrade/venv/lib/python3.10/site-packages/build/env.py", line 80, in _subprocess
    raise e
  File "/home/[USERNAME]/test-pip-tools-upgrade/venv/lib/python3.10/site-packages/build/env.py", line 77, in _subprocess
    subprocess.run(cmd, check=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  File "/usr/lib/python3.10/subprocess.py", line 524, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/tmp/build-env-cuwvmpr1/local/bin/python', '-Im', 'pip', 'install', '--use-pe
p517', '--no-warn-script-location', '-r', '/tmp/build-reqs-fvosl3ot.txt']' returned non-zero exit status 1.

By stepping back one commit and running pip-sync, I could verify that this worked before.

  1. git reset --hard HEAD^
  2. pip-sync
  3. run any of the above pip-compile commands
@elizeubarbosaabreu
Copy link

Eu adicionei --no-cache-dir ao final do comando e funcionou...

@hofrob
Copy link
Author

hofrob commented Jul 29, 2022

pip-tools 6.7.0 is also affected. Last working version is 6.6.2.

@tatiana-tam
Copy link

The same thing happened to me.
I just uninstalled and installed the pip. The old version was installed, I have upgraded and it already works.
Hope you can fix it :)

@atugushev atugushev added the bug Something is not working label Aug 6, 2022
@hofrob
Copy link
Author

hofrob commented Aug 14, 2022

# uninstall pip
sudo pip uninstall pip
# install pip through apt
sudo apt install python3-pip
# upgrade pip to the latest version
python3 -m pip install --user --upgrade pip

Fixed this, thx @tatiana-tam.

@hofrob
Copy link
Author

hofrob commented Aug 15, 2022

I was not able to reproduce this on a fresh Ubuntu 22.04 VM.

@hofrob hofrob closed this as completed Aug 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is not working
Projects
None yet
Development

No branches or pull requests

4 participants