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

Allow defining empty username and password in .pypirc #426

Merged
merged 1 commit into from
Jan 12, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions twine/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
def get_config(path="~/.pypirc"):
# even if the config file does not exist, set up the parser
# variable to reduce the number of if/else statements
parser = configparser.RawConfigParser()
parser = configparser.RawConfigParser(allow_no_value=True)
Copy link
Member

Choose a reason for hiding this comment

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

Today I learned that allow_no_value=True allows for:

[pypi]
username
password

But with allow_no_value=False, username= and password= are still valid and still result in empty strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With allow_no_value=False, if the config file is of the form:

[pypi]
username
password

the username and password key won't be available in the parsed config.
Or am I mistaking?

Copy link
Member

Choose a reason for hiding this comment

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

In that case, the parser will raise an Exception, but naked username or password was not the prescribed syntax; rather username: (which I assume is equivalent to username=) was.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, now I remember why I had to add allow_no_value=True in order to allow empty value.

What's the difference between adding : (or =), and using naked keys?
Is it parsed differently?

Copy link
Member

Choose a reason for hiding this comment

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

Yes. Adding the separator causes the value to be parsed as the empty string. Not including the separator creates a ParseException unless allow_no_value=True in which case the value is None.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK. The intent of my PR was to be able to provide a None value in the configuration file in order to be anonymous.
Without this PR, you wouldn't be able to provide such value, so the CLI would systematically ask for a login/password (which I didn't want).


# this list will only be used if index-servers
# is not defined in the config file
Expand Down Expand Up @@ -195,7 +195,7 @@ def get_userpass_value(cli_value, config, key, prompt_strategy=None):
"""
if cli_value is not None:
return cli_value
elif config.get(key):
elif key in config:
Copy link
Member

Choose a reason for hiding this comment

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

Given that config always defaults with {'username': None, 'password': None}, I now believe this change unconditionally disables prompts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you don't add username nor password keys in your configuration file, the keys won't be available in the parsed config object, so it should continue to the prompt_strategy part.

Copy link
Member

@jaraco jaraco Feb 9, 2019

Choose a reason for hiding this comment

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

That's where you're mistaken. Keys are set unconditionally to default to None.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What if I don't have a server-login section (which is my case):

[distutils]
index-servers =
    internal

[internal]
repository: ******
username
password

Copy link
Member

Choose a reason for hiding this comment

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

return config[key]
elif prompt_strategy:
return prompt_strategy()
Expand Down