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 logs overwrite each other when using reinstall-all #1132

Closed
corneliusroemer opened this issue Dec 3, 2023 · 12 comments · Fixed by #1365
Closed

Error logs overwrite each other when using reinstall-all #1132

corneliusroemer opened this issue Dec 3, 2023 · 12 comments · Fixed by #1365
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@corneliusroemer
Copy link

corneliusroemer commented Dec 3, 2023

Describe the bug

When running pipx reinstall-all --python "python3.12" and getting error logs from multiple reinstallations, the logs are overwritten.

Each reinstallation should get its own log path, or logs should be appended to and not overwritten.

How to reproduce

  1. Run a command that errors for multiple installations, e.g (via When upgrading package to Python 3.12: Fatal error: TypeError: rmtree() got an unexpected keyword argument 'onexc' #1090)
pipx install visidata pycowsay --python "3.11"
pipx reinstall-all --python "3.12"
  1. Check out the error logs for earlier errors, i.e. /Users/USERNAME/.local/pipx/logs/cmd_2023-12-03_14.10.06_pip_errors.log

Expected behavior

The logs are appended to, rather than overwritten.

Details

This is the terminal output I get:

 pipx reinstall-all --python "python3.12"
uninstalled parquet-cli! ✨ 🌟 ✨
Fatal error from pip prevented installation. Full pip output in file:
    /Users/corneliusromer/.local/pipx/logs/cmd_2023-12-03_14.10.06_pip_errors.log

pip seemed to fail to build package:
    six>=1.5

Some possibly relevant errors from pip install:
    TypeError: rmtree() got an unexpected keyword argument 'onexc'

Error installing parquet-cli.
uninstalled hatch! ✨ 🌟 ✨
Fatal error from pip prevented installation. Full pip output in file:
    /Users/corneliusromer/.local/pipx/logs/cmd_2023-12-03_14.10.06_pip_errors.log

pip seemed to fail to build package:
    more-itertools

Some possibly relevant errors from pip install:
    TypeError: rmtree() got an unexpected keyword argument 'onexc'

Error installing hatch.
uninstalled pycowsay! ✨ 🌟 ✨
Fatal error from pip prevented installation. Full pip output in file:
    /Users/corneliusromer/.local/pipx/logs/cmd_2023-12-03_14.10.06_pip_errors.log

pip seemed to fail to build package:
    pycowsay

Some possibly relevant errors from pip install:
    TypeError: rmtree() got an unexpected keyword argument 'onexc'

Error installing pycowsay.
uninstalled chatGPT! ✨ 🌟 ✨
Fatal error from pip prevented installation. Full pip output in file:
    /Users/corneliusromer/.local/pipx/logs/cmd_2023-12-03_14.10.06_pip_errors.log

pip seemed to fail to build package:
    git+https://github.com/mmabrouk/chatgpt-wrapper

Some possibly relevant errors from pip install:
    TypeError: rmtree() got an unexpected keyword argument 'onexc'

Error installing chatGPT from spec 'git+https://github.com/mmabrouk/chatgpt-wrapper'.
uninstalled datasette! ✨ 🌟 ✨
Fatal error from pip prevented installation. Full pip output in file:
    /Users/corneliusromer/.local/pipx/logs/cmd_2023-12-03_14.10.06_pip_errors.log

pip seemed to fail to build package:
    MarkupSafe>=2.0

Some possibly relevant errors from pip install:
    TypeError: rmtree() got an unexpected keyword argument 'onexc'

Error installing datasette.
The following package(s) failed to reinstall: parquet-cli, hatch, pycowsay, chatgpt, datasette

Note that all the error file paths are the same: /Users/corneliusromer/.local/pipx/logs/cmd_2023-12-03_14.10.06_pip_errors.log

When I open that file, I see only error output from the last command invoked, earlier error logs are overwritten.

@corneliusroemer
Copy link
Author

The bug seems to be here, where 'w' is given as the mode rather than append:

with pip_error_file.open("w", encoding="utf-8") as pip_error_fh:

corneliusroemer added a commit to corneliusroemer/pipx that referenced this issue Dec 3, 2023
Resolves pypa#1132 

An alternative would be to create new log files for each pip invocation, but this would require deeper changes. Appending seems like a decent solution as a first fix.
@chrysle chrysle added the bug Something isn't working label Dec 17, 2023
@chrysle chrysle added the good first issue Good for newcomers label Jan 12, 2024
@huxuan
Copy link
Member

huxuan commented Apr 9, 2024

Hi @gaborbernat and @chrysle,

I am interested in this issue, but may I ask if there is any package like weblate that will fail when installed with pipx? I tried to search on the Internet and even asked ChatGPT but did not find any candidates.

BTW, it is needed to write test cases.

@chrysle
Copy link
Contributor

chrysle commented Apr 9, 2024

Hi @huxuan,

thanks for taking interest in this!

I am interested in this issue, but may I ask if there is any package like weblate that will fail when installed with pipx?

Could you explain how you want to achieve multiple error messages in one process by this, as install will stop once it encounters one error?

@huxuan
Copy link
Member

huxuan commented Apr 10, 2024

Hi @chrysle

Could you explain how you want to achieve multiple error messages in one process by this, as install will stop once it encounters one error?

If I understand correctly, the error log overridden problem only happen when there are multiple error messages. As mentioned in the comment here, I am trying to reach the same situation.

Maybe I am going in the wrong direction, any clues on how to fix this issue?

@chrysle
Copy link
Contributor

chrysle commented Apr 13, 2024

The problem here seems to be pipx's strict error handling with install and install-all. Given that reinstall-all doesn't interrupt its operation when it detects an installation failure, probably install-all should do the same? Then, one could mock a pipx metadata JSON file, installing multiple packages that fail (say, next to weblate==4.3.1, for example dotenv==0.0.5).

@huxuan
Copy link
Member

huxuan commented Apr 13, 2024

The problem here seems to be pipx's strict error handling with install and install-all. Given that reinstall-all doesn't interrupt its operation when it detects an installation failure, probably install-all should do the same? Then, one could mock a pipx metadata JSON file, installing multiple packages that fail (say, next to weblate==4.3.1, for example dotenv==0.0.5).

So you mean we should change the strategy for error log? Maybe something like the virtual environment problems, which is gathered first and output after everything is finished?

@chrysle
Copy link
Contributor

chrysle commented Apr 13, 2024

So you mean we should change the strategy for error log? Maybe something like the virtual environment problems, which is gathered first and output after everything is finished?

Like reinstall-all does it, yes:

if len(failed) > 0:
raise PipxError(f"The following package(s) failed to reinstall: {', '.join(failed)}")

@huxuan
Copy link
Member

huxuan commented Apr 14, 2024

Thanks for the clarification, I will try to submit a pull request then.

@huxuan
Copy link
Member

huxuan commented Apr 16, 2024

Hi @chrysle, I created a pull request [1] as discussed, but I realized that it may not be the same problem as this issue.

Maybe a scenario for this issue is a new Python version is released but more than one tool have not support it yet. At this time pipx reinstall-all --python <new_python> will fail, but the error log only show one package instead of all of the failed packages.

And the root cause of this problem is that the subprocess_post_check_handle_pip_error() [2] function which writes the log file will only be invoked in the install_package()[3] (install_unmanaged_packages() is only for pipx run) of the pipx.venv module. So it would be a shared problem for all batch operations.

[1] #1348
[2]

def subprocess_post_check_handle_pip_error(

[3]
subprocess_post_check_handle_pip_error(pip_process)

@chrysle
Copy link
Contributor

chrysle commented Apr 16, 2024

Maybe a scenario for this issue is a new Python version is released but more than one tool have not support it yet. At this time pipx reinstall-all --python <new_python> will fail, but the error log only show one package instead of all of the failed packages.

Yes, this is the core issue.

And the root cause of this problem is that the subprocess_post_check_handle_pip_error() [2] function which writes the log file will only be invoked in the install_package()[3] (install_unmanaged_packages() is only for pipx run) of the pipx.venv module. So it would be a shared problem for all batch operations.

I can't follow you, exactly... Yes, said function will only be called if an error is encountered with the installation of a package, but the actual fix for the issue that only the error log for the last failure is available afterwards was already discovered in #1132 (comment) (I think it's correct). What I mean to do is to enable installing multiple failing packages with install-all – which currently isn't possible, that's why I have proposed the PR. By this, all errors with the installation procedure for each package should be logged, but that behaviour is currently broken. In a follow-up, a redux for #1133 could then be provided, using an install-all operation as a reproducer in the tests.

@huxuan
Copy link
Member

huxuan commented Apr 16, 2024

In a follow-up, a redux for #1133 could then be provided, using an install-all operation as a reproducer in the tests.

Sorry for my misunderstanding. I suppose we need a different approach to fix the problem since #1133 was closed. That makes everything clear. Thanks for your patient explanation.

@chrysle
Copy link
Contributor

chrysle commented Apr 16, 2024

Thanks for your patient explanation.

You're welcome, and thank you for all the work you've done for pipx already!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
3 participants