Skip to content

Commit d852113

Browse files
committed
Merge pull request #112 from jedie/outdated_pypirc
helpful messages if ~/.pypirc format is out-dated
2 parents 04cc97f + 3e2f436 commit d852113

3 files changed

Lines changed: 38 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,11 @@
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
18+
1419
import pretend
1520
import pytest
1621

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

twine/commands/upload.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,16 @@ 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: "
121+
"https://docs.python.org/distutils/packageindex.html#pypirc\n"
122+
).format(
123+
repo=repository,
124+
cfg=config_file
121125
)
126+
raise KeyError(msg)
122127

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

0 commit comments

Comments
 (0)