Skip to content

Commit b393b24

Browse files
committed
Merge pull request #83 from pypa/bug/61
Read deprecated style of PyPI rc files
2 parents 3643687 + 42ff76a commit b393b24

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

tests/fixtures/deprecated-pypirc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[server-login]
2+
username:testusername
3+
password:testpassword
4+
5+
[pypi]
6+
foo:bar

tests/test_utils.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,20 @@ def test_get_config_missing(tmpdir):
9696
}
9797

9898

99+
def test_get_config_deprecated_pypirc():
100+
tests_dir = os.path.dirname(os.path.abspath(__file__))
101+
deprecated_pypirc_path = os.path.join(tests_dir, 'fixtures',
102+
'deprecated-pypirc')
103+
104+
assert get_config(deprecated_pypirc_path) == {
105+
"pypi": {
106+
"repository": DEFAULT_REPOSITORY,
107+
"username": 'testusername',
108+
"password": 'testpassword',
109+
},
110+
}
111+
112+
99113
@pytest.mark.parametrize(
100114
('cli_value', 'config', 'key', 'strategy', 'expected'),
101115
(

twine/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ def get_config(path="~/.pypirc"):
5858

5959
config = {}
6060

61+
defaults = {"username": None, "password": None}
62+
if parser.has_section("server-login"):
63+
for key in ["username", "password"]:
64+
if parser.has_option("server-login", key):
65+
defaults[key] = parser.get("server-login", key)
66+
6167
for repository in repositories:
6268
# Skip this repository if it doesn't exist in the config file
6369
if not parser.has_section(repository):
@@ -74,6 +80,8 @@ def get_config(path="~/.pypirc"):
7480
for key in ["username", "repository", "password"]:
7581
if parser.has_option(repository, key):
7682
config[repository][key] = parser.get(repository, key)
83+
elif defaults.get(key):
84+
config[repository][key] = defaults[key]
7785

7886
return config
7987

0 commit comments

Comments
 (0)