From 35c0e9c2d67cbda4033ba0e0b1c20e4df8c24ce7 Mon Sep 17 00:00:00 2001 From: Benoit Pierre Date: Thu, 30 Nov 2017 19:46:16 +0100 Subject: [PATCH 1/2] fix `data_files` handling when installing from wheel --- setuptools/tests/test_wheel.py | 36 ++++++++++++++++++++++++++++++++++ setuptools/wheel.py | 27 +++++++++++++++++++++---- 2 files changed, 59 insertions(+), 4 deletions(-) diff --git a/setuptools/tests/test_wheel.py b/setuptools/tests/test_wheel.py index 408c357612..b6be6f1f05 100644 --- a/setuptools/tests/test_wheel.py +++ b/setuptools/tests/test_wheel.py @@ -444,6 +444,42 @@ def __repr__(self): '''), ), + dict( + id='data_in_package', + file_defs={ + 'foo': { + '__init__.py': '', + 'data_dir': { + 'data.txt': DALS( + ''' + Some data... + ''' + ), + } + } + }, + setup_kwargs=dict( + packages=['foo'], + data_files=[('foo/data_dir', ['foo/data_dir/data.txt'])], + ), + install_tree=DALS( + ''' + foo-1.0-py{py_version}.egg/ + |-- EGG-INFO/ + | |-- DESCRIPTION.rst + | |-- PKG-INFO + | |-- RECORD + | |-- WHEEL + | |-- metadata.json + | |-- top_level.txt + |-- foo/ + | |-- __init__.py + | |-- data_dir/ + | | |-- data.txt + ''' + ), + ), + ) @pytest.mark.parametrize( diff --git a/setuptools/wheel.py b/setuptools/wheel.py index c23272133f..9ffe434ae3 100644 --- a/setuptools/wheel.py +++ b/setuptools/wheel.py @@ -28,6 +28,28 @@ ''' +def unpack(src_dir, dst_dir): + '''Move everything under `src_dir` to `dst_dir`, and delete the former.''' + for dirpath, dirnames, filenames in os.walk(src_dir): + subdir = os.path.relpath(dirpath, src_dir) + for f in filenames: + src = os.path.join(dirpath, f) + dst = os.path.join(dst_dir, subdir, f) + os.renames(src, dst) + for n, d in reversed(list(enumerate(dirnames))): + src = os.path.join(dirpath, d) + dst = os.path.join(dst_dir, subdir, d) + if not os.path.exists(dst): + # Directory does not exist in destination, + # rename it and prune it from os.walk list. + os.renames(src, dst) + del dirnames[n] + # Cleanup. + for dirpath, dirnames, filenames in os.walk(src_dir, topdown=True): + assert not filenames + os.rmdir(dirpath) + + class Wheel(object): def __init__(self, filename): @@ -125,10 +147,7 @@ def raw_req(req): os.path.join(dist_data, d) for d in ('data', 'headers', 'purelib', 'platlib') )): - for entry in os.listdir(subdir): - os.rename(os.path.join(subdir, entry), - os.path.join(destination_eggdir, entry)) - os.rmdir(subdir) + unpack(subdir, destination_eggdir) if os.path.exists(dist_data): os.rmdir(dist_data) # Fix namespace packages. From e1946bc255e891ef1f8e399a2a2d30b197e89037 Mon Sep 17 00:00:00 2001 From: Benoit Pierre Date: Mon, 4 Dec 2017 18:01:09 +0100 Subject: [PATCH 2/2] update changelog --- CHANGES.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 0cff779e00..3694b15272 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,8 @@ +v38.2.4 +------- + +* #1220: Fix `data_files` handling when installing from wheel. + v38.2.3 -------