saving dependency work

This commit is contained in:
2022-12-10 21:17:54 -06:00
parent bf923c3406
commit c2c19e5382
5636 changed files with 666283 additions and 8587 deletions
@@ -11,9 +11,17 @@ from unittest import TestLoader
from setuptools.extern import six
from setuptools.extern.six.moves import map, filter
from pkg_resources import (resource_listdir, resource_exists, normalize_path,
working_set, _namespace_packages, evaluate_marker,
add_activation_listener, require, EntryPoint)
from pkg_resources import (
resource_listdir,
resource_exists,
normalize_path,
working_set,
_namespace_packages,
evaluate_marker,
add_activation_listener,
require,
EntryPoint,
)
from setuptools import Command
from .build_py import _unique_everseen
@@ -21,7 +29,6 @@ __metaclass__ = type
class ScanningLoader(TestLoader):
def __init__(self):
TestLoader.__init__(self)
self._visited = set()
@@ -43,13 +50,13 @@ class ScanningLoader(TestLoader):
if hasattr(module, "additional_tests"):
tests.append(module.additional_tests())
if hasattr(module, '__path__'):
for file in resource_listdir(module.__name__, ''):
if file.endswith('.py') and file != '__init__.py':
submodule = module.__name__ + '.' + file[:-3]
if hasattr(module, "__path__"):
for file in resource_listdir(module.__name__, ""):
if file.endswith(".py") and file != "__init__.py":
submodule = module.__name__ + "." + file[:-3]
else:
if resource_exists(module.__name__, file + '/__init__.py'):
submodule = module.__name__ + '.' + file
if resource_exists(module.__name__, file + "/__init__.py"):
submodule = module.__name__ + "." + file
else:
continue
tests.append(self.loadTestsFromName(submodule))
@@ -77,10 +84,13 @@ class test(Command):
description = "run unit tests after in-place build (deprecated)"
user_options = [
('test-module=', 'm', "Run 'test_suite' in specified module"),
('test-suite=', 's',
"Run single test, case or suite (e.g. 'module.test_suite')"),
('test-runner=', 'r', "Test runner to use"),
("test-module=", "m", "Run 'test_suite' in specified module"),
(
"test-suite=",
"s",
"Run single test, case or suite (e.g. 'module.test_suite')",
),
("test-runner=", "r", "Test runner to use"),
]
def initialize_options(self):
@@ -102,11 +112,11 @@ class test(Command):
self.test_suite = self.test_module + ".test_suite"
if self.test_loader is None:
self.test_loader = getattr(self.distribution, 'test_loader', None)
self.test_loader = getattr(self.distribution, "test_loader", None)
if self.test_loader is None:
self.test_loader = "setuptools.command.test:ScanningLoader"
if self.test_runner is None:
self.test_runner = getattr(self.distribution, 'test_runner', None)
self.test_runner = getattr(self.distribution, "test_runner", None)
@NonDataProperty
def test_args(self):
@@ -114,9 +124,9 @@ class test(Command):
def _test_args(self):
if not self.test_suite and sys.version_info >= (2, 7):
yield 'discover'
yield "discover"
if self.verbose:
yield '--verbose'
yield "--verbose"
if self.test_suite:
yield self.test_suite
@@ -129,30 +139,30 @@ class test(Command):
@contextlib.contextmanager
def project_on_sys_path(self, include_dists=[]):
with_2to3 = not six.PY2 and getattr(self.distribution, 'use_2to3', False)
with_2to3 = not six.PY2 and getattr(self.distribution, "use_2to3", False)
if with_2to3:
# If we run 2to3 we can not do this inplace:
# Ensure metadata is up-to-date
self.reinitialize_command('build_py', inplace=0)
self.run_command('build_py')
self.reinitialize_command("build_py", inplace=0)
self.run_command("build_py")
bpy_cmd = self.get_finalized_command("build_py")
build_path = normalize_path(bpy_cmd.build_lib)
# Build extensions
self.reinitialize_command('egg_info', egg_base=build_path)
self.run_command('egg_info')
self.reinitialize_command("egg_info", egg_base=build_path)
self.run_command("egg_info")
self.reinitialize_command('build_ext', inplace=0)
self.run_command('build_ext')
self.reinitialize_command("build_ext", inplace=0)
self.run_command("build_ext")
else:
# Without 2to3 inplace works fine:
self.run_command('egg_info')
self.run_command("egg_info")
# Build extensions in-place
self.reinitialize_command('build_ext', inplace=1)
self.run_command('build_ext')
self.reinitialize_command("build_ext", inplace=1)
self.run_command("build_ext")
ei_cmd = self.get_finalized_command("egg_info")
@@ -164,7 +174,7 @@ class test(Command):
sys.path.insert(0, project_path)
working_set.__init__()
add_activation_listener(lambda dist: dist.activate())
require('%s==%s' % (ei_cmd.egg_name, ei_cmd.egg_version))
require("%s==%s" % (ei_cmd.egg_name, ei_cmd.egg_version))
with self.paths_on_pythonpath([project_path]):
yield
finally:
@@ -184,20 +194,20 @@ class test(Command):
Do this in a context that restores the value on exit.
"""
nothing = object()
orig_pythonpath = os.environ.get('PYTHONPATH', nothing)
current_pythonpath = os.environ.get('PYTHONPATH', '')
orig_pythonpath = os.environ.get("PYTHONPATH", nothing)
current_pythonpath = os.environ.get("PYTHONPATH", "")
try:
prefix = os.pathsep.join(_unique_everseen(paths))
to_join = filter(None, [prefix, current_pythonpath])
new_path = os.pathsep.join(to_join)
if new_path:
os.environ['PYTHONPATH'] = new_path
os.environ["PYTHONPATH"] = new_path
yield
finally:
if orig_pythonpath is nothing:
os.environ.pop('PYTHONPATH', None)
os.environ.pop("PYTHONPATH", None)
else:
os.environ['PYTHONPATH'] = orig_pythonpath
os.environ["PYTHONPATH"] = orig_pythonpath
@staticmethod
def install_dists(dist):
@@ -208,8 +218,9 @@ class test(Command):
ir_d = dist.fetch_build_eggs(dist.install_requires)
tr_d = dist.fetch_build_eggs(dist.tests_require or [])
er_d = dist.fetch_build_eggs(
v for k, v in dist.extras_require.items()
if k.startswith(':') and evaluate_marker(k[1:])
v
for k, v in dist.extras_require.items()
if k.startswith(":") and evaluate_marker(k[1:])
)
return itertools.chain(ir_d, tr_d, er_d)
@@ -224,14 +235,14 @@ class test(Command):
installed_dists = self.install_dists(self.distribution)
cmd = ' '.join(self._argv)
cmd = " ".join(self._argv)
if self.dry_run:
self.announce('skipping "%s" (dry run)' % cmd)
return
self.announce('running "%s"' % cmd)
paths = map(operator.attrgetter('location'), installed_dists)
paths = map(operator.attrgetter("location"), installed_dists)
with self.paths_on_pythonpath(paths):
with self.project_on_sys_path():
self.run_tests()
@@ -240,32 +251,34 @@ class test(Command):
# Purge modules under test from sys.modules. The test loader will
# re-import them from the build location. Required when 2to3 is used
# with namespace packages.
if not six.PY2 and getattr(self.distribution, 'use_2to3', False):
module = self.test_suite.split('.')[0]
if not six.PY2 and getattr(self.distribution, "use_2to3", False):
module = self.test_suite.split(".")[0]
if module in _namespace_packages:
del_modules = []
if module in sys.modules:
del_modules.append(module)
module += '.'
module += "."
for name in sys.modules:
if name.startswith(module):
del_modules.append(name)
list(map(sys.modules.__delitem__, del_modules))
test = unittest.main(
None, None, self._argv,
None,
None,
self._argv,
testLoader=self._resolve_as_ep(self.test_loader),
testRunner=self._resolve_as_ep(self.test_runner),
exit=False,
)
if not test.result.wasSuccessful():
msg = 'Test failed: %s' % test.result
msg = "Test failed: %s" % test.result
self.announce(msg, log.ERROR)
raise DistutilsError(msg)
@property
def _argv(self):
return ['unittest'] + self.test_args
return ["unittest"] + self.test_args
@staticmethod
def _resolve_as_ep(val):