mirror of
https://github.com/python/cpython.git
synced 2025-11-01 02:38:53 +00:00
More fixes for PEP 3147 compliance in distutils (#11254)
This commit is contained in:
parent
5df1108de2
commit
c465b2f843
5 changed files with 94 additions and 59 deletions
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
import os
|
||||
import sys
|
||||
import io
|
||||
import imp
|
||||
import unittest
|
||||
|
||||
|
|
@ -54,7 +53,6 @@ class BuildPyTestCase(support.TempdirManager,
|
|||
# This makes sure the list of outputs includes byte-compiled
|
||||
# files for Python modules but not for package data files
|
||||
# (there shouldn't *be* byte-code files for those!).
|
||||
#
|
||||
self.assertEqual(len(cmd.get_outputs()), 3)
|
||||
pkgdest = os.path.join(destination, "pkg")
|
||||
files = os.listdir(pkgdest)
|
||||
|
|
@ -64,15 +62,11 @@ class BuildPyTestCase(support.TempdirManager,
|
|||
if sys.dont_write_bytecode:
|
||||
self.assertFalse(os.path.exists(pycache_dir))
|
||||
else:
|
||||
# XXX even with -O, distutils writes pyc, not pyo; bug?
|
||||
pyc_files = os.listdir(pycache_dir)
|
||||
self.assertIn("__init__.%s.pyc" % imp.get_tag(), pyc_files)
|
||||
|
||||
def test_empty_package_dir(self):
|
||||
# See SF 1668596/1720897.
|
||||
cwd = os.getcwd()
|
||||
|
||||
# create the distribution files.
|
||||
# See bugs #1668596/#1720897
|
||||
sources = self.mkdtemp()
|
||||
open(os.path.join(sources, "__init__.py"), "w").close()
|
||||
|
||||
|
|
@ -81,30 +75,55 @@ class BuildPyTestCase(support.TempdirManager,
|
|||
open(os.path.join(testdir, "testfile"), "w").close()
|
||||
|
||||
os.chdir(sources)
|
||||
old_stdout = sys.stdout
|
||||
sys.stdout = io.StringIO()
|
||||
dist = Distribution({"packages": ["pkg"],
|
||||
"package_dir": {"pkg": ""},
|
||||
"package_data": {"pkg": ["doc/*"]}})
|
||||
# script_name need not exist, it just need to be initialized
|
||||
dist.script_name = os.path.join(sources, "setup.py")
|
||||
dist.script_args = ["build"]
|
||||
dist.parse_command_line()
|
||||
|
||||
try:
|
||||
dist = Distribution({"packages": ["pkg"],
|
||||
"package_dir": {"pkg": ""},
|
||||
"package_data": {"pkg": ["doc/*"]}})
|
||||
# script_name need not exist, it just need to be initialized
|
||||
dist.script_name = os.path.join(sources, "setup.py")
|
||||
dist.script_args = ["build"]
|
||||
dist.parse_command_line()
|
||||
dist.run_commands()
|
||||
except DistutilsFileError:
|
||||
self.fail("failed package_data test when package_dir is ''")
|
||||
|
||||
try:
|
||||
dist.run_commands()
|
||||
except DistutilsFileError:
|
||||
self.fail("failed package_data test when package_dir is ''")
|
||||
finally:
|
||||
# Restore state.
|
||||
os.chdir(cwd)
|
||||
sys.stdout = old_stdout
|
||||
@unittest.skipIf(sys.dont_write_bytecode, 'byte-compile disabled')
|
||||
def test_byte_compile(self):
|
||||
project_dir, dist = self.create_dist(py_modules=['boiledeggs'])
|
||||
os.chdir(project_dir)
|
||||
self.write_file('boiledeggs.py', 'import antigravity')
|
||||
cmd = build_py(dist)
|
||||
cmd.compile = 1
|
||||
cmd.build_lib = 'here'
|
||||
cmd.finalize_options()
|
||||
cmd.run()
|
||||
|
||||
found = os.listdir(cmd.build_lib)
|
||||
self.assertEqual(sorted(found), ['__pycache__', 'boiledeggs.py'])
|
||||
found = os.listdir(os.path.join(cmd.build_lib, '__pycache__'))
|
||||
self.assertEqual(found, ['boiledeggs.%s.pyc' % imp.get_tag()])
|
||||
|
||||
@unittest.skipIf(sys.dont_write_bytecode, 'byte-compile disabled')
|
||||
def test_byte_compile_optimized(self):
|
||||
project_dir, dist = self.create_dist(py_modules=['boiledeggs'])
|
||||
os.chdir(project_dir)
|
||||
self.write_file('boiledeggs.py', 'import antigravity')
|
||||
cmd = build_py(dist)
|
||||
cmd.compile = 0
|
||||
cmd.optimize = 1
|
||||
cmd.build_lib = 'here'
|
||||
cmd.finalize_options()
|
||||
cmd.run()
|
||||
|
||||
found = os.listdir(cmd.build_lib)
|
||||
self.assertEqual(sorted(found), ['__pycache__', 'boiledeggs.py'])
|
||||
found = os.listdir(os.path.join(cmd.build_lib, '__pycache__'))
|
||||
self.assertEqual(sorted(found), ['boiledeggs.%s.pyo' % imp.get_tag()])
|
||||
|
||||
def test_dont_write_bytecode(self):
|
||||
# makes sure byte_compile is not used
|
||||
pkg_dir, dist = self.create_dist()
|
||||
dist = self.create_dist()[1]
|
||||
cmd = build_py(dist)
|
||||
cmd.compile = 1
|
||||
cmd.optimize = 1
|
||||
|
|
@ -118,6 +137,7 @@ class BuildPyTestCase(support.TempdirManager,
|
|||
|
||||
self.assertIn('byte-compiling is disabled', self.logs[0][1])
|
||||
|
||||
|
||||
def test_suite():
|
||||
return unittest.makeSuite(BuildPyTestCase)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue