Skip to content

Commit 6fa03c1

Browse files
committed
helpful messages if ~/.pypirc format is out-dated
see also: #111
1 parent 04cc97f commit 6fa03c1

3 files changed

Lines changed: 37 additions & 4 deletions

File tree

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ Tom Myers <tom.stephen.myers@gmail.com>
1313
Rodrigue Cloutier <rodcloutier@gmail.com>
1414
Tyrel Souza <tyrelsouza@gmail.com> (https://tyrelsouza.com)
1515
Adam Talsma <adam@talsma.ca>
16+
Jens Diemer <github@jensdiemer.de> (http://jensdiemer.de/)

tests/test_upload.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
from __future__ import unicode_literals
15+
16+
import os
17+
import textwrap
1418
import pretend
1519
import pytest
1620

@@ -72,3 +76,27 @@ def test_sign_file_with_identity(monkeypatch):
7276
args = ['gpg', '--detach-sign', '--local-user', 'identity', '-a',
7377
'my_file.tar.gz']
7478
assert replaced_check_call.calls == [pretend.call(args)]
79+
80+
def test_get_config_old_format(tmpdir):
81+
pypirc = os.path.join(str(tmpdir), ".pypirc")
82+
83+
with open(pypirc, "w") as fp:
84+
fp.write(textwrap.dedent("""
85+
[server-login]
86+
username:foo
87+
password:bar
88+
"""))
89+
90+
try:
91+
upload.upload(dists="foo", repository="pypi",
92+
sign=None, identity=None, username=None, password=None, comment=None,
93+
sign_with=None, config_file=pypirc
94+
)
95+
except KeyError as err:
96+
assert err.args[0] == (
97+
"Missing 'pypi' section from the configuration file.\n"
98+
"Maybe you have a out-dated '{0}' format?\n"
99+
"more info: https://docs.python.org/distutils/packageindex.html#pypirc\n"
100+
).format(pypirc)
101+
102+

twine/commands/upload.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,15 @@ def upload(dists, repository, sign, identity, username, password, comment,
114114
try:
115115
config = get_config(config_file)[repository]
116116
except KeyError:
117-
raise KeyError(
118-
"Missing '{0}' section from the configuration file".format(
119-
repository,
120-
),
117+
msg = (
118+
"Missing '{repo}' section from the configuration file.\n"
119+
"Maybe you have a out-dated '{cfg}' format?\n"
120+
"more info: https://docs.python.org/distutils/packageindex.html#pypirc\n"
121+
).format(
122+
repo=repository,
123+
cfg=config_file
121124
)
125+
raise KeyError(msg)
122126

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

0 commit comments

Comments
 (0)