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

Quiet warnings about netrc #3267

Merged
merged 1 commit into from
Oct 15, 2018
Merged

Quiet warnings about netrc #3267

merged 1 commit into from
Oct 15, 2018

Conversation

nicktimko
Copy link
Contributor

@nicktimko nicktimko commented Sep 13, 2018

What do these changes do?

If there isn't a .netrc file specified by an environment variable, it can be confusing to see warnings about it. If NETRC isn't set, don't warn. Only warn if one of

  • can't resolve HOME
  • can load, but can't parse file
  • can't find file
  • file appears to exist at the default location but is unreadable for some reason.

Are there changes in behavior for the user?

When using the client from a command line application, the user will no longer see could't find .netrc file if ~/.netrc is missing and/or the envvar NETRC isn't set.

Related issue number

None.

Checklist

  • I think the code is well written: Tried to reduce how much code the try/except was catching, added some early exits to reduce number of conditionals
  • Unit tests for the changes exist: n/a: UI change?
  • Documentation reflects the changes: n/a, UI change?
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt: n/a trivial change
  • Add a new news fragment into the CHANGES folder: trivial change?
    • name it <issue_id>.<type> for example (588.bugfix)
    • if you don't have an issue_id change it to the pr id after creating the pr
    • ensure type is one of the following:
      • .feature: Signifying a new feature.
      • .bugfix: Signifying a bug fix.
      • .doc: Signifying a documentation improvement.
      • .removal: Signifying a deprecation or removal of public API.
      • .misc: A ticket has been closed, but it is not of interest to users.
    • Make sure to use full sentences with correct case and punctuation, for example: "Fix issue with non-ascii contents in doctest text files."

netrc_path = home_dir.joinpath('.netrc')
except RuntimeError as e: # pragma: no cover
# if pathlib can't resolve home, it may raise a RuntimeError
client_logger.warning("Could not find .netrc file: %s", e)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This message seems to be misleading

""" handle error raised by pathlib """
client_logger.warning("could't find .netrc file: %s", e)
return netrc_obj
if os.name == 'nt': # pragma: no cover
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use platform.system() instead

Copy link
Member

@webknjaz webknjaz Sep 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

netrc_path = home_dir / ('_netrc' if platform.system() == 'Windows' else '.netrc')

If there isn't a .netrc file specified by an environment variable, it
can be confusing to see warnings about it. If NETRC isn't set, don't
warn. Only warn if: a) can't resolve HOME, b) can load, but can't parse
file, c) can't find file, d) file appears to exist at the default
location but is unreadable for some reason.
@agronholm
Copy link
Contributor

I also couldn't understand why these warnings were printed in the first place.

@nicktimko
Copy link
Contributor Author

I dunno, if I just submit a diff where I delete all of them, that fine?

@asvetlov asvetlov merged commit 965a1cd into aio-libs:master Oct 15, 2018
@asvetlov
Copy link
Member

Thanks!

@agronholm
Copy link
Contributor

@nicktimko Why is it even necessary to print a warning if the home directory cannot be resolved? A typical Docker container will not have a resolvable home directory unless one is explicitly created in the Dockerfile.

@asvetlov
Copy link
Member

If your code is not supposed to work with trust_env=True -- why do you want to pass the flag at all?

@nicktimko
Copy link
Contributor Author

nicktimko commented Oct 15, 2018

@agronholm This was a bit monkey-see, monkey-do. I was trying to preserve the existing behavior that I didn't understand, as I haven't used a .netrc file didn't fully grok it. I was going on the assumption that the existing code was correct (#2584) for most circumstances, and I don't think I changed much in the functionality aside from the narrow case that I cut out (nothing set in the env, the file doesn't exist.)

@agronholm
Copy link
Contributor

If your code is not supposed to work with trust_env=True -- why do you want to pass the flag at all?

What are you talking about? I use trust_env=True so it could pick up my proxy settings from the environment variables.

@asvetlov
Copy link
Member

Ok, I see nothing bad if we will suppress a warning if the home directory doesn't exist..

@agronholm would you prepare a pull request?

@agronholm
Copy link
Contributor

Sure, I'll try to get that done this week.

@lock
Copy link

lock bot commented Oct 28, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs.
If you feel like there's important points made in this discussion, please include those exceprts into that [new issue].
[new issue]: https://github.com/aio-libs/aiohttp/issues/new

@lock lock bot added the outdated label Oct 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants