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

New normalization for dist-info and wheel names #395

Merged
merged 1 commit into from
Mar 1, 2021
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
19 changes: 16 additions & 3 deletions flit_core/flit_core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,21 @@ def metadata_and_module_from_ini_path(ini_path):
metadata = make_metadata(module, ini_info)
return metadata,module


def normalize_dist_name(name: str, version: str) -> str:
"""Normalizes a name and a PEP 440 version

The resulting string is valid as dist-info folder name
and as first part of a wheel filename

See https://packaging.python.org/specifications/binary-distribution-format/#escaping-and-unicode
"""
normalized_name = re.sub(r'[-_.]+', '_', name, flags=re.UNICODE)
assert check_version(version) == version
assert '-' not in version, 'Normalized versions can’t have dashes'
return '{}-{}'.format(normalized_name, version)


def dist_info_name(distribution, version):
"""Get the correct name of the .dist-info folder"""
escaped_name = re.sub(r"[^\w\d.]+", "_", distribution, flags=re.UNICODE)
escaped_version = re.sub(r"[^\w\d.]+", "_", version, flags=re.UNICODE)
return u'{}-{}.dist-info'.format(escaped_name, escaped_version)
return normalize_dist_name(distribution, version) + '.dist-info'
7 changes: 2 additions & 5 deletions flit_core/flit_core/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import logging
import os
import os.path as osp
import re
import stat
import sys
import tempfile
Expand Down Expand Up @@ -98,11 +97,9 @@ def dist_info(self):

@property
def wheel_filename(self):
dist_name = common.normalize_dist_name(self.metadata.name, self.metadata.version)
tag = ('py2.' if self.metadata.supports_py2 else '') + 'py3-none-any'
return '{}-{}-{}.whl'.format(
re.sub(r"[^\w\d.]+", "_", self.metadata.name, flags=re.UNICODE),
re.sub(r"[^\w\d.]+", "_", self.metadata.version, flags=re.UNICODE),
tag)
return '{}-{}.whl'.format(dist_name, tag)

def _add_file_old(self, full_path, rel_path):
log.debug("Adding %s to zip file", full_path)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""
A module with a local version specifier
"""

__version__ = "0.1.dev0+test"
10 changes: 10 additions & 0 deletions tests/samples/modulewithlocalversion/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[build-system]
requires = ["flit_core >=2,<4"]
build-backend = "flit_core.buildapi"

[tool.flit.metadata]
module = "modulewithlocalversion"
author = "Sir Robin"
author-email = "robin@camelot.uk"
home-page = "http://github.com/sirrobin/modulewithlocalversion"

11 changes: 11 additions & 0 deletions tests/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,14 @@ def test_compression(tmp_path):
'module1-0.1.dist-info/METADATA',
]:
assert zf.getinfo(name).compress_type == zipfile.ZIP_DEFLATED

def test_wheel_module_local_version(copy_sample):
"""Test if a local version specifier is preserved in wheel filename and dist-info dir name"""
td = copy_sample('modulewithlocalversion')
make_wheel_in(td / 'pyproject.toml', td)

whl_file = td / 'modulewithlocalversion-0.1.dev0+test-py2.py3-none-any.whl'
assert_isfile(whl_file)
with unpack(whl_file) as unpacked:
assert_isfile(Path(unpacked, 'modulewithlocalversion.py'))
assert_isdir(Path(unpacked, 'modulewithlocalversion-0.1.dev0+test.dist-info'))