Move useful function to packaging.util.
Original patch by Erik Bray as part of #11595, changed by me to improve readability.
This commit is contained in:
parent
df55334d52
commit
1c1d9a5026
|
@ -9,7 +9,8 @@ from configparser import RawConfigParser
|
|||
from packaging import logger
|
||||
from packaging.errors import PackagingOptionError
|
||||
from packaging.compiler.extension import Extension
|
||||
from packaging.util import check_environ, iglob, resolve_name, strtobool
|
||||
from packaging.util import (check_environ, iglob, resolve_name, strtobool,
|
||||
split_multiline)
|
||||
from packaging.compiler import set_compiler
|
||||
from packaging.command import set_command
|
||||
from packaging.markers import interpret
|
||||
|
@ -124,12 +125,6 @@ class Config:
|
|||
# XXX
|
||||
return value
|
||||
|
||||
def _multiline(self, value):
|
||||
value = [v for v in
|
||||
[v.strip() for v in value.split('\n')]
|
||||
if v != '']
|
||||
return value
|
||||
|
||||
def _read_setup_cfg(self, parser, cfg_filename):
|
||||
cfg_directory = os.path.dirname(os.path.abspath(cfg_filename))
|
||||
content = {}
|
||||
|
@ -155,7 +150,7 @@ class Config:
|
|||
for key, value in content['metadata'].items():
|
||||
key = key.replace('_', '-')
|
||||
if metadata.is_multi_field(key):
|
||||
value = self._multiline(value)
|
||||
value = split_multiline(value)
|
||||
|
||||
if key == 'project-url':
|
||||
value = [(label.strip(), url.strip())
|
||||
|
@ -192,7 +187,7 @@ class Config:
|
|||
files = content['files']
|
||||
self.dist.package_dir = files.pop('packages_root', None)
|
||||
|
||||
files = dict((key, self._multiline(value)) for key, value in
|
||||
files = dict((key, split_multiline(value)) for key, value in
|
||||
files.items())
|
||||
|
||||
self.dist.packages = []
|
||||
|
@ -310,7 +305,7 @@ class Config:
|
|||
opt = opt.replace('-', '_')
|
||||
|
||||
if opt == 'sub_commands':
|
||||
val = self._multiline(val)
|
||||
val = split_multiline(val)
|
||||
if isinstance(val, str):
|
||||
val = [val]
|
||||
|
||||
|
@ -348,14 +343,14 @@ class Config:
|
|||
raise PackagingOptionError(msg)
|
||||
|
||||
def _load_compilers(self, compilers):
|
||||
compilers = self._multiline(compilers)
|
||||
compilers = split_multiline(compilers)
|
||||
if isinstance(compilers, str):
|
||||
compilers = [compilers]
|
||||
for compiler in compilers:
|
||||
set_compiler(compiler.strip())
|
||||
|
||||
def _load_commands(self, commands):
|
||||
commands = self._multiline(commands)
|
||||
commands = split_multiline(commands)
|
||||
if isinstance(commands, str):
|
||||
commands = [commands]
|
||||
for command in commands:
|
||||
|
|
|
@ -250,6 +250,14 @@ def split_quoted(s):
|
|||
return words
|
||||
|
||||
|
||||
def split_multiline(value):
|
||||
"""Split a multiline string into a list, excluding blank lines."""
|
||||
|
||||
return [element for element in
|
||||
(line.strip() for line in value.split('\n'))
|
||||
if element]
|
||||
|
||||
|
||||
def execute(func, args, msg=None, verbose=0, dry_run=False):
|
||||
"""Perform some action that affects the outside world.
|
||||
|
||||
|
@ -542,18 +550,15 @@ def write_file(filename, contents):
|
|||
|
||||
|
||||
def _is_package(path):
|
||||
if not os.path.isdir(path):
|
||||
return False
|
||||
return os.path.isfile(os.path.join(path, '__init__.py'))
|
||||
return os.path.isdir(path) and os.path.isfile(
|
||||
os.path.join(path, '__init__.py'))
|
||||
|
||||
|
||||
# Code taken from the pip project
|
||||
def _is_archive_file(name):
|
||||
archives = ('.zip', '.tar.gz', '.tar.bz2', '.tgz', '.tar')
|
||||
ext = splitext(name)[1].lower()
|
||||
if ext in archives:
|
||||
return True
|
||||
return False
|
||||
return ext in archives
|
||||
|
||||
|
||||
def _under(path, root):
|
||||
|
|
Loading…
Reference in New Issue