Skip to content

Commit

Permalink
Merge pull request #1466 from pfmoore/pep517_fix
Browse files Browse the repository at this point in the history
Fix for Unicode handling in PEP 518 backend
  • Loading branch information
jaraco committed Aug 21, 2018
2 parents 167e902 + 687cfab commit 3f3b1a6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/1466.change.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix handling of Unicode arguments in PEP 517 backend
15 changes: 14 additions & 1 deletion setuptools/build_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ def patch(cls):
distutils.core.Distribution = orig


def _to_str(s):
"""
Convert a filename to a string (on Python 2, explicitly
a byte string, not Unicode) as distutils checks for the
exact type str.
"""
if sys.version_info[0] == 2 and not isinstance(s, str):
# Assume it's Unicode, as that's what the PEP says
# should be provided.
return s.encode(sys.getfilesystemencoding())
return s


def _run_setup(setup_script='setup.py'):
# Note that we can reuse our build directory between calls
# Correctness comes first, then optimization later
Expand Down Expand Up @@ -109,7 +122,7 @@ def get_requires_for_build_sdist(config_settings=None):


def prepare_metadata_for_build_wheel(metadata_directory, config_settings=None):
sys.argv = sys.argv[:1] + ['dist_info', '--egg-base', metadata_directory]
sys.argv = sys.argv[:1] + ['dist_info', '--egg-base', _to_str(metadata_directory)]
_run_setup()

dist_info_directory = metadata_directory
Expand Down
9 changes: 9 additions & 0 deletions setuptools/tests/test_build_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,12 @@ def test_prepare_metadata_for_build_wheel(build_backend):
dist_info = build_backend.prepare_metadata_for_build_wheel(dist_dir)

assert os.path.isfile(os.path.join(dist_dir, dist_info, 'METADATA'))


def test_prepare_metadata_for_build_wheel_with_unicode(build_backend):
dist_dir = os.path.abspath(u'pip-dist-info')
os.makedirs(dist_dir)

dist_info = build_backend.prepare_metadata_for_build_wheel(dist_dir)

assert os.path.isfile(os.path.join(dist_dir, dist_info, 'METADATA'))

0 comments on commit 3f3b1a6

Please sign in to comment.