Skip to content

Commit

Permalink
Remove distutils index-servers from config
Browse files Browse the repository at this point in the history
Replace RawConfigParser with ConfigParser
Update lookup to use `.sections()` and `.has_section()`

Removes extra entries from tests, since the default fallback will
no longer automatically add them to an empty config.

Signed-off-by: Mike Fiedler <miketheman@gmail.com>
  • Loading branch information
miketheman committed Dec 23, 2023
1 parent 99fcf8f commit 560a288
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 22 deletions.
15 changes: 0 additions & 15 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ def test_get_config_no_distutils(write_config_file):
"username": "testuser",
"password": "testpassword",
},
"testpypi": {
"repository": utils.TEST_REPOSITORY,
"username": None,
"password": None,
},
}


Expand Down Expand Up @@ -108,11 +103,6 @@ def test_get_config_missing(config_file):
"username": None,
"password": None,
},
"testpypi": {
"repository": utils.TEST_REPOSITORY,
"username": None,
"password": None,
},
}


Expand Down Expand Up @@ -201,11 +191,6 @@ def test_get_config_deprecated_pypirc():
"username": "testusername",
"password": "testpassword",
},
"testpypi": {
"repository": utils.TEST_REPOSITORY,
"username": "testusername",
"password": "testpassword",
},
}


Expand Down
14 changes: 7 additions & 7 deletions twine/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def get_config(path: str) -> Dict[str, RepositoryConfig]:
pypyi and testpypi.
"""
realpath = os.path.realpath(os.path.expanduser(path))
parser = configparser.RawConfigParser()
parser = configparser.ConfigParser()

try:
with open(realpath) as f:
Expand All @@ -75,17 +75,17 @@ def get_config(path: str) -> Dict[str, RepositoryConfig]:
config: DefaultDict[str, RepositoryConfig]
config = collections.defaultdict(lambda: defaults.copy())

index_servers = parser.get(
"distutils", "index-servers", fallback="pypi testpypi"
).split()

# Don't require users to manually configure URLs for these repositories
config["pypi"]["repository"] = DEFAULT_REPOSITORY
if "testpypi" in index_servers:
if parser.has_section("testpypi"):
config["testpypi"]["repository"] = TEST_REPOSITORY

# Optional configuration values for individual repositories
for repository in index_servers:
for repository in parser.sections():
if repository == "server-login":
# handled by defaults already, don't add an extra key to config
continue

for key in [
"username",
"repository",
Expand Down

0 comments on commit 560a288

Please sign in to comment.