diff --git a/cdd/__init__.py b/cdd/__init__.py index 25da082b..7ea3d400 100644 --- a/cdd/__init__.py +++ b/cdd/__init__.py @@ -9,7 +9,7 @@ from logging import getLogger as get_logger __author__ = "Samuel Marks" # type: str -__version__ = "0.0.99rc36" # type: str +__version__ = "0.0.99rc37" # type: str __description__ = ( "Open API to/fro routes, models, and tests. " "Convert between docstrings, classes, methods, argparse, pydantic, and SQLalchemy." diff --git a/cdd/shared/pkg_utils.py b/cdd/shared/pkg_utils.py index 34c78830..9188eff7 100644 --- a/cdd/shared/pkg_utils.py +++ b/cdd/shared/pkg_utils.py @@ -13,6 +13,15 @@ from sysconfig import _PREFIX as PREFIX from sysconfig import get_python_version + Str = type( + "_Never", + tuple(), + { + "__init__": lambda s=None, n=None, constant_value=None, string=None, col_offset=None, lineno=None: s + or n + }, + ) + def is_virtual_environment(): """ Whether one is in a virtual environment @@ -37,41 +46,49 @@ def get_python_lib(plat_specific=0, standard_lib=0, prefix=None): "/usr", "/usr/local", ) - if prefix is None: - if standard_lib: - prefix = plat_specific and BASE_EXEC_PREFIX or BASE_PREFIX - else: - prefix = plat_specific and EXEC_PREFIX or PREFIX - - if os.name == "posix": - if plat_specific or standard_lib: + prefix = ( + prefix or plat_specific and (BASE_EXEC_PREFIX or BASE_PREFIX) + if standard_lib + else (EXEC_PREFIX or PREFIX) + ) + + class DistutilsPlatformError(Exception): + """DistutilsPlatformError""" + + assert os.name in frozenset(("posix", "nt")), DistutilsPlatformError( + "I don't know where Python installs its library " + "on platform '{}'".format(os.name) + ) + return ( + ( + # plat_specific or standard_lib: # Platform-specific modules (any module from a non-pure-Python # module distribution) or standard Python library modules. - libdir = sys.platlibdir - else: + # else: # Pure Python - libdir = "lib" - libpython = os.path.join(prefix, libdir, "python" + get_python_version()) - if standard_lib: - return libpython - elif is_default_prefix and not is_virtual_environment(): - return os.path.join(prefix, "lib", "python3", "dist-packages") - else: - return os.path.join(libpython, "site-packages") - elif os.name == "nt": - if standard_lib: - return os.path.join(prefix, "Lib") - else: - return os.path.join(prefix, "Lib", "site-packages") - else: - - class DistutilsPlatformError(Exception): - """DistutilsPlatformError""" - - raise DistutilsPlatformError( - "I don't know where Python installs its library " - "on platform '%s'" % os.name + lambda libpython: ( + libpython + if standard_lib + else ( + os.path.join(prefix, "lib", "python3", "dist-packages") + if is_default_prefix and not is_virtual_environment() + else os.path.join(libpython, "site-packages") + ) + ) + )( + os.path.join( + prefix, + sys.platlibdir if plat_specific or standard_lib else "lib", + "python" + get_python_version(), + ) + ) + if os.name == "posix" + else ( + os.path.join(prefix, "Lib") + if standard_lib + else os.path.join(prefix, "Lib", "site-packages") ) + ) else: from distutils.sysconfig import get_python_lib @@ -92,10 +109,8 @@ def relative_filename(filename, remove_hints=tuple()): """ _filename: str = filename.casefold() lib = get_python_lib(), get_python_lib(prefix="") - for elem in remove_hints + lib: - if _filename.startswith(elem.casefold()): - return filename[len(elem) + 1 :] - return filename + return next(map(lambda elem: filename[len(elem) + 1 :], + filter(lambda elem: _filename.startswith(elem.casefold()), remove_hints + lib)), filename) __all__ = ["relative_filename"] # type: list[str] diff --git a/cdd/tests/test_sqlalchemy/test_emit_sqlalchemy.py b/cdd/tests/test_sqlalchemy/test_emit_sqlalchemy.py index 57f0fe0d..ba22ccc7 100644 --- a/cdd/tests/test_sqlalchemy/test_emit_sqlalchemy.py +++ b/cdd/tests/test_sqlalchemy/test_emit_sqlalchemy.py @@ -78,10 +78,6 @@ def test_to_sqlalchemy_table_with_inferred_pk(self) -> None: gold=empty_with_inferred_pk_column_assign, ) - @skipIf( - "GITHUB_ACTIONS" in os.environ and system() in frozenset(("Darwin", "Linux")), - "GitHub Actions fails this test on macOS & Linux (unable to replicate locally)", - ) def test_to_sqlalchemy(self) -> None: """ Tests that `emit.sqlalchemy` with `intermediate_repr_no_default_sql_doc` produces `config_tbl_ast` diff --git a/cdd/tests/test_utils_for_tests.py b/cdd/tests/test_utils_for_tests.py index 2f8fc7c0..ac825113 100644 --- a/cdd/tests/test_utils_for_tests.py +++ b/cdd/tests/test_utils_for_tests.py @@ -21,10 +21,6 @@ class TestUtilsForTests(TestCase): Tests whether docstrings are parsed out—and emitted—correctly """ - @skipIf( - "GITHUB_ACTIONS" in environ and version_info[:2] >= (3, 6), - "GitHub Actions fails this test (unable to replicate locally)", - ) def test_unittest_main(self) -> None: """ Tests whether `unittest_main` is called when `__name__ == '__main__'` @@ -32,6 +28,7 @@ def test_unittest_main(self) -> None: self.assertEqual(type(unittest_main).__name__, "function") self.assertIsNone(unittest_main()) argparse_mock = MagicMock() + # cdd.tests.utils_for_tests.py with patch("cdd.tests.utils_for_tests.__name__", "__main__"), patch( "sys.stderr", new_callable=StringIO ), self.assertRaises(SystemExit) as e: