frostming / unearth

A utility to fetch and download python packages
https://unearth.readthedocs.io
MIT License
141 stars 18 forks source link

.netrc Parsing Warning Message Is Printed as Many Times as Packages Are Installed #146

Closed jbdyn closed 2 months ago

jbdyn commented 2 months ago

Thank you for precious time looking into this issue and your work on PDM/unearth!

Describe the Bug Not having a .netrc file in $HOME/ triggers this logging warning message

https://github.com/frostming/unearth/blob/9ee45283f6f60426bd2cfe4c819ec8032c15db01/src/unearth/utils.py#L302-L303

to be printed as many times as packages are installed on $ pdm outdated. So in my project with ~90 packages, I got flooded with messages and did not see that the command actually exits fine.

Similarly, pdm show --name seems to produce a similar result, as commented on the introducing commit

Current Workaround

$ touch ~/.netrc

To Reproduce

$ mkdir /tmp/netrc-test && cd /tmp/netrc-test

$ python -m venv --upgrade-deps .venv

$ . .venv/bin/activate

$ pdm init # say 'yes' to library for `pdm show --name`
[...]

$ pdm list
╭──────┬─────────┬──────────╮
│ name │ version │ location │
├──────┼─────────┼──────────┤
│ pip  │ 24.2    │          │
╰──────┴─────────┴──────────╯

$ pdm outdated
Couldn't parse netrc because of FileNotFoundError: [Errno 2] No such file or directory: '/home/jbdyn/.netrc'
╭─────────┬───────────┬────────┬────────╮
│ Package │ Installed │ Pinned │ Latest │
├─────────┼───────────┼────────┼────────┤
╰─────────┴───────────┴────────┴────────╯

$ pdm add ruff black
[...]

$ pdm list
╭─────────────────┬─────────┬──────────╮
│ name            │ version │ location │
├─────────────────┼─────────┼──────────┤
│ black           │ 24.8.0  │          │
│ click           │ 8.1.7   │          │
│ mypy-extensions │ 1.0.0   │          │
│ packaging       │ 24.1    │          │
│ pathspec        │ 0.12.1  │          │
│ pip             │ 24.2    │          │
│ platformdirs    │ 4.2.2   │          │
│ ruff            │ 0.6.3   │          │
╰─────────────────┴─────────┴──────────╯

$ pdm outdated
Couldn't parse netrc because of FileNotFoundError: [Errno 2] No such file or directory: '/home/jbdyn/.netrc'
Couldn't parse netrc because of FileNotFoundError: [Errno 2] No such file or directory: '/home/jbdyn/.netrc'
Couldn't parse netrc because of FileNotFoundError: [Errno 2] No such file or directory: '/home/jbdyn/.netrc'
Couldn't parse netrc because of FileNotFoundError: [Errno 2] No such file or directory: '/home/jbdyn/.netrc'
Couldn't parse netrc because of FileNotFoundError: [Errno 2] No such file or directory: '/home/jbdyn/.netrc'
Couldn't parse netrc because of FileNotFoundError: [Errno 2] No such file or directory: '/home/jbdyn/.netrc'
Couldn't parse netrc because of FileNotFoundError: [Errno 2] No such file or directory: '/home/jbdyn/.netrc'
Couldn't parse netrc because of FileNotFoundError: [Errno 2] No such file or directory: '/home/jbdyn/.netrc'
╭─────────┬───────────┬────────┬────────╮
│ Package │ Installed │ Pinned │ Latest │
├─────────┼───────────┼────────┼────────┤
╰─────────┴───────────┴────────┴────────╯

Expected Behavior The warning should be shown only once, independent from the number of present packages.

System