Skip to content

Commit

Permalink
helpful messages if ~/.pypirc format is out-dated
Browse files Browse the repository at this point in the history
see also:
pypa#111
  • Loading branch information
jedie committed Jun 10, 2015
1 parent 04cc97f commit 6fa03c1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ Tom Myers <[email protected]>
Rodrigue Cloutier <[email protected]>
Tyrel Souza <[email protected]> (https://tyrelsouza.com)
Adam Talsma <[email protected]>
Jens Diemer <[email protected]> (http://jensdiemer.de/)
28 changes: 28 additions & 0 deletions tests/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import unicode_literals

import os
import textwrap
import pretend
import pytest

Expand Down Expand Up @@ -72,3 +76,27 @@ def test_sign_file_with_identity(monkeypatch):
args = ['gpg', '--detach-sign', '--local-user', 'identity', '-a',
'my_file.tar.gz']
assert replaced_check_call.calls == [pretend.call(args)]

def test_get_config_old_format(tmpdir):
pypirc = os.path.join(str(tmpdir), ".pypirc")

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

try:
upload.upload(dists="foo", repository="pypi",
sign=None, identity=None, username=None, password=None, comment=None,
sign_with=None, config_file=pypirc
)
except KeyError as err:
assert err.args[0] == (
"Missing 'pypi' section from the configuration file.\n"
"Maybe you have a out-dated '{0}' format?\n"
"more info: https://docs.python.org/distutils/packageindex.html#pypirc\n"
).format(pypirc)


12 changes: 8 additions & 4 deletions twine/commands/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,15 @@ def upload(dists, repository, sign, identity, username, password, comment,
try:
config = get_config(config_file)[repository]
except KeyError:
raise KeyError(
"Missing '{0}' section from the configuration file".format(
repository,
),
msg = (
"Missing '{repo}' section from the configuration file.\n"
"Maybe you have a out-dated '{cfg}' format?\n"
"more info: https://docs.python.org/distutils/packageindex.html#pypirc\n"
).format(
repo=repository,
cfg=config_file
)
raise KeyError(msg)

parsed = urlparse(config["repository"])
if parsed.netloc in ["pypi.python.org", "testpypi.python.org"]:
Expand Down

0 comments on commit 6fa03c1

Please sign in to comment.