diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2017-11-09 20:24:08 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-11-09 20:24:08 -0500 |
| commit | 26cbce17dfb5aa9ea1ffae5d25363ad645bf6e44 (patch) | |
| tree | 31214b121a85092b65f971f6b3217ecb3c8784cb | |
| parent | ff9bc4902f32c331d917e8bae9136607e48c2738 (diff) | |
| parent | 4216b5f3fece69e3b74c646f72b8fe757b658729 (diff) | |
| download | python-setuptools-git-26cbce17dfb5aa9ea1ffae5d25363ad645bf6e44.tar.gz | |
Merge pull request #1145 from haobibo/master
python 3 bdist_egg --exclude-source-files __pycache__ issue
| -rw-r--r-- | CHANGES.rst | 3 | ||||
| -rw-r--r-- | setuptools/command/bdist_egg.py | 18 | ||||
| -rw-r--r-- | setuptools/tests/test_bdist_egg.py | 22 |
3 files changed, 40 insertions, 3 deletions
diff --git a/CHANGES.rst b/CHANGES.rst index 6b84c03f..bea60786 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,9 @@ v36.6.1 * #1132: Removed redundant and costly serialization/parsing step in ``EntryPoint.__init__``. +* #844: ``bdist_egg --exclude-source-files`` now tested and works + on Python 3. + v36.6.0 ------- diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 51755d52..5fdb62d9 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -8,6 +8,7 @@ from distutils import log from types import CodeType import sys import os +import re import textwrap import marshal @@ -240,11 +241,26 @@ class bdist_egg(Command): log.info("Removing .py files from temporary directory") for base, dirs, files in walk_egg(self.bdist_dir): for name in files: + path = os.path.join(base, name) + if name.endswith('.py'): - path = os.path.join(base, name) log.debug("Deleting %s", path) os.unlink(path) + if base.endswith('__pycache__'): + path_old = path + + pattern = r'(?P<name>.+)\.(?P<magic>[^.]+)\.pyc' + m = re.match(pattern, name) + path_new = os.path.join(base, os.pardir, m.group('name') + '.pyc') + log.info("Renaming file from [%s] to [%s]" % (path_old, path_new)) + try: + os.remove(path_new) + except OSError: + pass + os.rename(path_old, path_new) + + def zip_safe(self): safe = getattr(self.distribution, 'zip_safe', None) if safe is not None: diff --git a/setuptools/tests/test_bdist_egg.py b/setuptools/tests/test_bdist_egg.py index d24aa366..61615b38 100644 --- a/setuptools/tests/test_bdist_egg.py +++ b/setuptools/tests/test_bdist_egg.py @@ -2,6 +2,7 @@ """ import os import re +import zipfile import pytest @@ -16,7 +17,7 @@ setup(name='foo', py_modules=['hi']) """ -@pytest.yield_fixture +@pytest.fixture(scope='function') def setup_context(tmpdir): with (tmpdir / 'setup.py').open('w') as f: f.write(SETUP_PY) @@ -32,7 +33,7 @@ class Test: script_name='setup.py', script_args=['bdist_egg'], name='foo', - py_modules=['hi'] + py_modules=['hi'], )) os.makedirs(os.path.join('build', 'src')) with contexts.quiet(): @@ -42,3 +43,20 @@ class Test: # let's see if we got our egg link at the right place [content] = os.listdir('dist') assert re.match(r'foo-0.0.0-py[23].\d.egg$', content) + + def test_exclude_source_files(self, setup_context, user_override): + dist = Distribution(dict( + script_name='setup.py', + script_args=['bdist_egg', '--exclude-source-files'], + name='foo', + py_modules=['hi'], + )) + with contexts.quiet(): + dist.parse_command_line() + dist.run_commands() + [dist_name] = os.listdir('dist') + dist_filename = os.path.join('dist', dist_name) + zip = zipfile.ZipFile(dist_filename) + names = list(zi.filename for zi in zip.filelist) + assert 'hi.pyc' in names + assert 'hi.py' not in names |
