Skip to content

Commit

Permalink
Read deprecated style of PyPI rc files
Browse files Browse the repository at this point in the history
Fixes #61
  • Loading branch information
sigmavirus24 committed Dec 19, 2014
1 parent 3643687 commit 42ff76a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/fixtures/deprecated-pypirc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[server-login]
username:testusername
password:testpassword

[pypi]
foo:bar
14 changes: 14 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,20 @@ def test_get_config_missing(tmpdir):
}


def test_get_config_deprecated_pypirc():
tests_dir = os.path.dirname(os.path.abspath(__file__))
deprecated_pypirc_path = os.path.join(tests_dir, 'fixtures',
'deprecated-pypirc')

assert get_config(deprecated_pypirc_path) == {
"pypi": {
"repository": DEFAULT_REPOSITORY,
"username": 'testusername',
"password": 'testpassword',
},
}


@pytest.mark.parametrize(
('cli_value', 'config', 'key', 'strategy', 'expected'),
(
Expand Down
8 changes: 8 additions & 0 deletions twine/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ def get_config(path="~/.pypirc"):

config = {}

defaults = {"username": None, "password": None}
if parser.has_section("server-login"):
for key in ["username", "password"]:
if parser.has_option("server-login", key):
defaults[key] = parser.get("server-login", key)

for repository in repositories:
# Skip this repository if it doesn't exist in the config file
if not parser.has_section(repository):
Expand All @@ -74,6 +80,8 @@ def get_config(path="~/.pypirc"):
for key in ["username", "repository", "password"]:
if parser.has_option(repository, key):
config[repository][key] = parser.get(repository, key)
elif defaults.get(key):
config[repository][key] = defaults[key]

return config

Expand Down

0 comments on commit 42ff76a

Please sign in to comment.