Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use modern Python syntax features #436

Merged
merged 1 commit into from
Jan 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions twine/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ def main():
try:
return dispatch(sys.argv[1:])
except (exceptions.TwineException, requests.exceptions.HTTPError) as exc:
return '{0}: {1}'.format(
exc.__class__.__name__,
exc.args[0],
)
return '{}: {}'.format(exc.__class__.__name__, exc.args[0])


if __name__ == "__main__":
Expand Down
10 changes: 6 additions & 4 deletions twine/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

def _registered_commands(group='twine.registered_commands'):
registered_commands = pkg_resources.iter_entry_points(group=group)
return dict((c.name, c) for c in registered_commands)
return {c.name: c for c in registered_commands}


def list_dependencies_and_versions():
Expand All @@ -44,7 +44,7 @@ def list_dependencies_and_versions():

def dep_versions():
return ', '.join(
'{0}: {1}'.format(*dependency)
'{}: {}'.format(*dependency)
for dependency in list_dependencies_and_versions()
)

Expand All @@ -55,8 +55,10 @@ def dispatch(argv):
parser.add_argument(
"--version",
action="version",
version="%(prog)s version {0} ({1})".format(twine.__version__,
dep_versions()),
version="%(prog)s version {} ({})".format(
twine.__version__,
dep_versions(),
),
)
parser.add_argument(
"command",
Expand Down
4 changes: 2 additions & 2 deletions twine/commands/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
def register(register_settings, package):
repository_url = register_settings.repository_config['repository']

print("Registering package to {0}".format(repository_url))
print("Registering package to {}".format(repository_url))
repository = register_settings.create_repository()

if not os.path.exists(package):
raise exceptions.PackageNotFound(
'"{0}" does not exist on the file system.'.format(package)
'"{}" does not exist on the file system.'.format(package)
)

resp = repository.register(
Expand Down
10 changes: 4 additions & 6 deletions twine/commands/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def skip_upload(response, skip_existing, package):
filename = package.basefilename
msg_400 = (
# Old PyPI message:
'A file named "{0}" already exists for'.format(filename),
'A file named "{}" already exists for'.format(filename),
# Warehouse message:
'File already exists',
# Nexus Repository OSS message:
Expand All @@ -55,21 +55,19 @@ def upload(upload_settings, dists):
dists = _find_dists(dists)

# Determine if the user has passed in pre-signed distributions
signatures = dict(
(os.path.basename(d), d) for d in dists if d.endswith(".asc")
)
signatures = {os.path.basename(d): d for d in dists if d.endswith(".asc")}
uploads = [i for i in dists if not i.endswith(".asc")]
upload_settings.check_repository_url()
repository_url = upload_settings.repository_config['repository']

print("Uploading distributions to {0}".format(repository_url))
print("Uploading distributions to {}".format(repository_url))

repository = upload_settings.create_repository()

for filename in uploads:
package = PackageFile.from_filename(filename, upload_settings.comment)
skip_message = (
" Skipping {0} because it appears to already exist".format(
" Skipping {} because it appears to already exist".format(
package.basefilename)
)

Expand Down
4 changes: 2 additions & 2 deletions twine/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ class UploadToDeprecatedPyPIDetected(TwineException):
@classmethod
def from_args(cls, target_url, default_url, test_url):
"""Return an UploadToDeprecatedPyPIDetected instance."""
return cls("You're trying to upload to the legacy PyPI site '{0}'. "
return cls("You're trying to upload to the legacy PyPI site '{}'. "
"Uploading to those sites is deprecated. \n "
"The new sites are pypi.org and test.pypi.org. Try using "
"{1} (or {2}) to upload your packages instead. "
"{} (or {}) to upload your packages instead. "
"These are the default URLs for Twine now. \n More at "
"https://packaging.python.org/guides/migrating-to-pypi-org/"
" .".format(target_url, default_url, test_url)
Expand Down
2 changes: 1 addition & 1 deletion twine/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def add_gpg_signature(self, signature_filepath, signature_filename):
self.gpg_signature = (signature_filename, gpg.read())

def sign(self, sign_with, identity):
print("Signing {0}".format(self.basefilename))
print("Signing {}".format(self.basefilename))
gpg_args = (sign_with, "--detach-sign")
if identity:
gpg_args += ("--local-user", identity)
Expand Down
6 changes: 3 additions & 3 deletions twine/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

import twine

KEYWORDS_TO_NOT_FLATTEN = set(["gpg_signature", "content"])
KEYWORDS_TO_NOT_FLATTEN = {"gpg_signature", "content"}

LEGACY_PYPI = 'https://pypi.python.org/'
LEGACY_TEST_PYPI = 'https://testpypi.python.org/'
Expand Down Expand Up @@ -106,7 +106,7 @@ def register(self, package):
"protocol_version": "1",
})

print("Registering {0}".format(package.basefilename))
print("Registering {}".format(package.basefilename))

data_to_send = self._convert_data_to_list_of_tuples(data)
encoder = MultipartEncoder(data_to_send)
Expand All @@ -130,7 +130,7 @@ def _upload(self, package):

data_to_send = self._convert_data_to_list_of_tuples(data)

print("Uploading {0}".format(package.basefilename))
print("Uploading {}".format(package.basefilename))

with open(package.filename, "rb") as fp:
data_to_send.append((
Expand Down
6 changes: 3 additions & 3 deletions twine/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def get_repository_from_config(config_file, repository, repository_url=None):
}
if repository_url and "://" not in repository_url:
raise exceptions.UnreachableRepositoryURLDetected(
"Repository URL {0} has no protocol. Please add "
"Repository URL {} has no protocol. Please add "
"'https://'. \n".format(repository_url))
try:
return get_config(config_file)[repository]
Expand All @@ -133,8 +133,8 @@ def get_repository_from_config(config_file, repository, repository_url=None):
raise exceptions.InvalidConfiguration(msg)


_HOSTNAMES = set(["pypi.python.org", "testpypi.python.org", "upload.pypi.org",
"test.pypi.org"])
_HOSTNAMES = {"pypi.python.org", "testpypi.python.org", "upload.pypi.org",
"test.pypi.org"}


def normalize_repository_url(url):
Expand Down