mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Fix assorted bugs in packaging.util.cfg_to_args (#11595).
Original patch by Erik Bray.
This commit is contained in:
parent
1c1d9a5026
commit
3605030c9b
4 changed files with 67 additions and 17 deletions
|
@ -8,16 +8,18 @@ import subprocess
|
|||
from io import StringIO
|
||||
|
||||
from packaging.tests import support, unittest
|
||||
from packaging.tests.test_config import SETUP_CFG
|
||||
from packaging.errors import (
|
||||
PackagingPlatformError, PackagingByteCompileError, PackagingFileError,
|
||||
PackagingExecError, InstallationException)
|
||||
from packaging import util
|
||||
from packaging.dist import Distribution
|
||||
from packaging.util import (
|
||||
convert_path, change_root, split_quoted, strtobool, rfc822_escape,
|
||||
get_compiler_versions, _MAC_OS_X_LD_VERSION, byte_compile, find_packages,
|
||||
spawn, get_pypirc_path, generate_pypirc, read_pypirc, resolve_name, iglob,
|
||||
RICH_GLOB, egginfo_to_distinfo, is_setuptools, is_distutils, is_packaging,
|
||||
get_install_method)
|
||||
get_install_method, cfg_to_args)
|
||||
|
||||
|
||||
PYPIRC = """\
|
||||
|
@ -88,13 +90,15 @@ class UtilTestCase(support.EnvironRestorer,
|
|||
support.LoggingCatcher,
|
||||
unittest.TestCase):
|
||||
|
||||
restore_environ = ['HOME']
|
||||
restore_environ = ['HOME', 'PLAT']
|
||||
|
||||
def setUp(self):
|
||||
super(UtilTestCase, self).setUp()
|
||||
self.tmp_dir = self.mkdtemp()
|
||||
self.rc = os.path.join(self.tmp_dir, '.pypirc')
|
||||
os.environ['HOME'] = self.tmp_dir
|
||||
self.addCleanup(os.chdir, os.getcwd())
|
||||
tempdir = self.mkdtemp()
|
||||
self.rc = os.path.join(tempdir, '.pypirc')
|
||||
os.environ['HOME'] = tempdir
|
||||
os.chdir(tempdir)
|
||||
# saving the environment
|
||||
self.name = os.name
|
||||
self.platform = sys.platform
|
||||
|
@ -103,7 +107,6 @@ class UtilTestCase(support.EnvironRestorer,
|
|||
self.join = os.path.join
|
||||
self.isabs = os.path.isabs
|
||||
self.splitdrive = os.path.splitdrive
|
||||
#self._config_vars = copy(sysconfig._config_vars)
|
||||
|
||||
# patching os.uname
|
||||
if hasattr(os, 'uname'):
|
||||
|
@ -137,7 +140,6 @@ class UtilTestCase(support.EnvironRestorer,
|
|||
os.uname = self.uname
|
||||
else:
|
||||
del os.uname
|
||||
#sysconfig._config_vars = copy(self._config_vars)
|
||||
util.find_executable = self.old_find_executable
|
||||
subprocess.Popen = self.old_popen
|
||||
sys.old_stdout = self.old_stdout
|
||||
|
@ -491,6 +493,38 @@ class UtilTestCase(support.EnvironRestorer,
|
|||
content = f.read()
|
||||
self.assertEqual(content, WANTED)
|
||||
|
||||
def test_cfg_to_args(self):
|
||||
opts = {'description-file': 'README', 'extra-files': '',
|
||||
'setup-hook': 'packaging.tests.test_config.hook'}
|
||||
self.write_file('setup.cfg', SETUP_CFG % opts)
|
||||
self.write_file('README', 'loooong description')
|
||||
|
||||
args = cfg_to_args()
|
||||
# use Distribution to get the contents of the setup.cfg file
|
||||
dist = Distribution()
|
||||
dist.parse_config_files()
|
||||
metadata = dist.metadata
|
||||
|
||||
self.assertEqual(args['name'], metadata['Name'])
|
||||
# + .dev1 because the test SETUP_CFG also tests a hook function in
|
||||
# test_config.py for appending to the version string
|
||||
self.assertEqual(args['version'] + '.dev1', metadata['Version'])
|
||||
self.assertEqual(args['author'], metadata['Author'])
|
||||
self.assertEqual(args['author_email'], metadata['Author-Email'])
|
||||
self.assertEqual(args['maintainer'], metadata['Maintainer'])
|
||||
self.assertEqual(args['maintainer_email'],
|
||||
metadata['Maintainer-Email'])
|
||||
self.assertEqual(args['description'], metadata['Summary'])
|
||||
self.assertEqual(args['long_description'], metadata['Description'])
|
||||
self.assertEqual(args['classifiers'], metadata['Classifier'])
|
||||
self.assertEqual(args['requires'], metadata['Requires-Dist'])
|
||||
self.assertEqual(args['provides'], metadata['Provides-Dist'])
|
||||
|
||||
self.assertEqual(args['package_dir'].get(''), dist.package_dir)
|
||||
self.assertEqual(args['packages'], dist.packages)
|
||||
self.assertEqual(args['scripts'], dist.scripts)
|
||||
self.assertEqual(args['py_modules'], dist.py_modules)
|
||||
|
||||
|
||||
class GlobTestCaseBase(support.TempdirManager,
|
||||
support.LoggingCatcher,
|
||||
|
|
|
@ -1015,16 +1015,20 @@ def cfg_to_args(path='setup.cfg'):
|
|||
"requires": ("metadata", "requires_dist"),
|
||||
"provides": ("metadata", "provides_dist"), # **
|
||||
"obsoletes": ("metadata", "obsoletes_dist"), # **
|
||||
"package_dir": ("files", 'packages_root'),
|
||||
"packages": ("files",),
|
||||
"scripts": ("files",),
|
||||
"py_modules": ("files", "modules"), # **
|
||||
}
|
||||
|
||||
MULTI_FIELDS = ("classifiers",
|
||||
"requires",
|
||||
"platforms",
|
||||
"requires",
|
||||
"provides",
|
||||
"obsoletes",
|
||||
"packages",
|
||||
"scripts")
|
||||
"scripts",
|
||||
"py_modules")
|
||||
|
||||
def has_get_option(config, section, option):
|
||||
if config.has_option(section, option):
|
||||
|
@ -1036,9 +1040,9 @@ def cfg_to_args(path='setup.cfg'):
|
|||
|
||||
# The real code starts here
|
||||
config = RawConfigParser()
|
||||
if not os.path.exists(file):
|
||||
if not os.path.exists(path):
|
||||
raise PackagingFileError("file '%s' does not exist" %
|
||||
os.path.abspath(file))
|
||||
os.path.abspath(path))
|
||||
config.read(path)
|
||||
|
||||
kwargs = {}
|
||||
|
@ -1055,17 +1059,24 @@ def cfg_to_args(path='setup.cfg'):
|
|||
in_cfg_value = has_get_option(config, section, option)
|
||||
if not in_cfg_value:
|
||||
# There is no such option in the setup.cfg
|
||||
if arg == "long_description":
|
||||
filename = has_get_option(config, section, "description_file")
|
||||
if filename:
|
||||
with open(filename) as fp:
|
||||
in_cfg_value = fp.read()
|
||||
if arg == 'long_description':
|
||||
filenames = has_get_option(config, section, 'description-file')
|
||||
if filenames:
|
||||
filenames = split_multiline(filenames)
|
||||
in_cfg_value = []
|
||||
for filename in filenames:
|
||||
with open(filename) as fp:
|
||||
in_cfg_value.append(fp.read())
|
||||
in_cfg_value = '\n\n'.join(in_cfg_value)
|
||||
else:
|
||||
continue
|
||||
|
||||
if arg == 'package_dir' and in_cfg_value:
|
||||
in_cfg_value = {'': in_cfg_value}
|
||||
|
||||
if arg in MULTI_FIELDS:
|
||||
# support multiline options
|
||||
in_cfg_value = in_cfg_value.strip().split('\n')
|
||||
in_cfg_value = split_multiline(in_cfg_value)
|
||||
|
||||
kwargs[arg] = in_cfg_value
|
||||
|
||||
|
|
|
@ -116,6 +116,7 @@ Monty Brandenberg
|
|||
Georg Brandl
|
||||
Christopher Brannon
|
||||
Terrence Brannon
|
||||
Erik Bray
|
||||
Brian Brazil
|
||||
Dave Brennan
|
||||
Tom Bridgman
|
||||
|
|
|
@ -187,6 +187,10 @@ Core and Builtins
|
|||
Library
|
||||
-------
|
||||
|
||||
- Issue #11595: Fix assorted bugs in packaging.util.cfg_to_args, a
|
||||
compatibility helper for the distutils-packaging transition. Original patch
|
||||
by Erik Bray.
|
||||
|
||||
- Issue #12246: Warn and fail when trying to install a third-party project from
|
||||
an uninstalled Python (built in a source checkout). Original patch by
|
||||
Tshepang Lekhonkhobe.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue