|
2 | 2 |
|
3 | 3 | import importlib |
4 | 4 | import itertools |
| 5 | +import logging |
5 | 6 | import os |
6 | 7 | import pathlib |
7 | 8 | import runpy |
|
12 | 13 | import typing as t |
13 | 14 | import unittest |
14 | 15 |
|
15 | | -__version__ = '2022.08.27' |
| 16 | +__version__ = '2023.03.09' |
| 17 | + |
| 18 | +_LOG = logging.getLogger(__name__) |
| 19 | + |
| 20 | + |
| 21 | +def expand_args_by_globbing_items(*args: str) -> t.Tuple[str, ...]: |
| 22 | + """Expand a list of glob expressions.""" |
| 23 | + cwd = pathlib.Path.cwd() |
| 24 | + expanded_args = [] |
| 25 | + for arg in args: |
| 26 | + if '*' not in arg: |
| 27 | + expanded_args.append(arg) |
| 28 | + continue |
| 29 | + expanded_arg = [str(_.relative_to(cwd)) for _ in cwd.glob(arg)] |
| 30 | + assert expanded_arg, arg |
| 31 | + _LOG.debug('expanded arg "%s" to %s', arg, expanded_arg) |
| 32 | + expanded_args += expanded_arg |
| 33 | + _LOG.debug('expanded args to %s', expanded_args) |
| 34 | + return tuple(expanded_args) |
16 | 35 |
|
17 | 36 |
|
18 | 37 | def run_program(*args, glob: bool = False) -> None: |
19 | 38 | """Run subprocess with given args. Use path globbing for each arg that contains an asterisk.""" |
20 | 39 | if glob: |
21 | | - cwd = pathlib.Path.cwd() |
22 | | - args = tuple(itertools.chain.from_iterable( |
23 | | - list(str(_.relative_to(cwd)) for _ in cwd.glob(arg)) if '*' in arg else [arg] |
24 | | - for arg in args)) |
| 40 | + args = expand_args_by_globbing_items(*args) |
25 | 41 | try: |
26 | 42 | subprocess.run(args, check=True) |
27 | 43 | except subprocess.CalledProcessError as err: |
@@ -97,7 +113,7 @@ def import_module_member(module_name: str, member_name: str) -> t.Any: |
97 | 113 | (None, 'setup.py', True), ('this file', 'setup.py', True), (None, 'test/test_setup.py', True), |
98 | 114 | (None, 'test/test_setup.py#L98', True), ('line 5 of this file', 'setup.py#L5', True), |
99 | 115 | (None, 'http://site.com', False), (None, '../something/else', False), (None, 'no.thing', False), |
100 | | - (None, '/my/abs/path', False)] |
| 116 | + (None, '/my/abs/path', False), ('test dir', 'test', True)] |
101 | 117 |
|
102 | 118 |
|
103 | 119 | def get_package_folder_name(): |
@@ -293,7 +309,7 @@ class Package(package): # pylint: disable=too-few-public-methods, missing-docst |
293 | 309 |
|
294 | 310 | @unittest.skipUnless(os.environ.get('TEST_PACKAGING') or os.environ.get('CI'), |
295 | 311 | 'skipping packaging tests for actual package') |
296 | | -class IntergrationTests(unittest.TestCase): |
| 312 | +class IntegrationTests(unittest.TestCase): |
297 | 313 | """Test if the boilerplate can actually create a valid package.""" |
298 | 314 |
|
299 | 315 | pkg_name = get_package_folder_name() |
|
0 commit comments