Skip to content

Commit

Permalink
WIP to fix #269
Browse files Browse the repository at this point in the history
  • Loading branch information
brainwane committed Mar 18, 2018
1 parent d9bfce7 commit ad1c696
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 29 deletions.
49 changes: 26 additions & 23 deletions tests/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,31 +68,31 @@ def test_find_dists_handles_real_files():


def test_get_config_old_format(tmpdir):
pypirc = os.path.join(str(tmpdir), ".pypirc")
dists = ["tests/fixtures/twine-1.5.0-py2.py3-none-any.whl"]
with pytest.raises(Exception):
pypirc = os.path.join(str(tmpdir), ".pypirc")
dists = ["tests/fixtures/twine-1.5.0-py2.py3-none-any.whl"]

with open(pypirc, "w") as fp:
fp.write(textwrap.dedent("""
[server-login]
username:foo
password:bar
"""))
with open(pypirc, "w") as fp:
fp.write(textwrap.dedent("""
[server-login]
username:foo
password:bar
"""))

try:
upload.upload(dists=dists, repository="pypi", sign=None, identity=None,
username=None, password=None, comment=None,
cert=None, client_cert=None,
sign_with=None, config_file=pypirc, skip_existing=False,
repository_url=None,
)
except KeyError as err:
assert err.args[0] == (
"Missing 'pypi' section from the configuration file\n"
"or not a complete URL in --repository-url.\n"
"Maybe you have a out-dated '{0}' format?\n"
"more info: "
"https://docs.python.org/distutils/packageindex.html#pypirc\n"
).format(pypirc)
try:
upload.upload(dists=dists, repository="pypi", sign=None, identity=None,
username=None, password=None, comment=None,
cert=None, client_cert=None,
sign_with=None, config_file=pypirc, skip_existing=False,
repository_url=None,
)
except Exception as err:
assert err.args[0] == (
"Need 'index-servers' set in 'distutils' section of {0} ."
"Maybe you have a out-dated '{0}' format?\n"
"more info: "
"https://docs.python.org/distutils/packageindex.html#pypirc\n"
).format(pypirc)


def test_deprecated_repo(tmpdir):
Expand All @@ -102,6 +102,9 @@ def test_deprecated_repo(tmpdir):

with open(pypirc, "w") as fp:
fp.write(textwrap.dedent("""
[distutils]
index-servers = pypi
[pypi]
repository: https://pypi.python.org/pypi/
username:foo
Expand Down
20 changes: 14 additions & 6 deletions twine/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,18 @@ def get_config(path="~/.pypirc"):

# Get a list of repositories from the config file
# format: https://docs.python.org/3/distutils/packageindex.html#pypirc
if (parser.has_section("distutils") and
parser.has_option("distutils", "index-servers")):
if (parser.has_section("distutils") and parser.has_option(
"distutils", "index-servers")):
# distutils-compliant .pypirc file
repositories = parser.get("distutils", "index-servers").split()
else:
repositories = ["pypi"]
raise Exception(
"Need 'index-servers' set in 'distutils' section of {cfg} . "
"Maybe you have a out-dated '{cfg}' format?\n"
"more info: "
"https://docs.python.org/distutils/packageindex.html#pypirc "
"\n".format(cfg=path)
)

config = {}

Expand Down Expand Up @@ -104,10 +111,11 @@ def get_config(path="~/.pypirc"):


def get_repository_from_config(config_file, repository, repository_url=None):
# Get our config from the .pypirc file
# Get our config from the .pypirc file,
# and, if provided, command-line values for the repository
# name and URL
if repository_url and "://" in repository_url:
# assume that the repository is actually an URL and just sent
# them a dummy with the repo set
# prefer the command-line repository_url
return {
"repository": repository_url,
"username": None,
Expand Down

0 comments on commit ad1c696

Please sign in to comment.