Commit 26cbce17 authored by Jason R. Coombs's avatar Jason R. Coombs Committed by GitHub

Merge pull request #1145 from haobibo/master

python 3 bdist_egg --exclude-source-files __pycache__ issue
parents ff9bc490 4216b5f3
......@@ -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
-------
......
......@@ -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:
......
......@@ -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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment