diff --git a/phlop/reflection.py b/phlop/reflection.py index e0d6bcb..7526ced 100644 --- a/phlop/reflection.py +++ b/phlop/reflection.py @@ -12,9 +12,14 @@ from phlop.sys import extend_sys_path +FORCE_RAISE_ON_IMPORT_ERROR = os.getenv( + "PHLOP_FORCE_RAISE_ON_IMPORT_ERROR", "False" +).lower() in ("true", "1", "t") -def classes_in_file(file, subclasses_only=None, fail_on_import_error=True): - assert file + +def classes_in_file(file_path, subclasses_only=None, fail_on_import_error=False): + file = Path(file_path) + assert file.exists() module = str(file).replace(os.path.sep, ".")[:-3] assert module @@ -23,7 +28,7 @@ def classes_in_file(file, subclasses_only=None, fail_on_import_error=True): classes = [] - with extend_sys_path(os.getcwd()): + with extend_sys_path([os.getcwd(), str(file.parent)]): try: for name, cls in inspect.getmembers( importlib.import_module(module), inspect.isclass @@ -34,7 +39,7 @@ def classes_in_file(file, subclasses_only=None, fail_on_import_error=True): if should_add: classes += [cls] except (ValueError, ModuleNotFoundError) as e: - if fail_on_import_error: + if fail_on_import_error or FORCE_RAISE_ON_IMPORT_ERROR: raise e logging.error(f"Skipping on error: {e} in module {module}") diff --git a/phlop/run/test_cases.py b/phlop/run/test_cases.py index ef2fd08..3f620b6 100644 --- a/phlop/run/test_cases.py +++ b/phlop/run/test_cases.py @@ -7,8 +7,8 @@ import logging import multiprocessing -import sys import re +import sys import unittest from pathlib import Path diff --git a/pyproject.toml b/pyproject.toml index 1e4eede..cd310e6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "phlop" -version = "0.0.14" +version = "0.0.15" dependencies = [ @@ -21,6 +21,12 @@ classifiers = [ [build-system] requires = [ - "setuptools>=42", "wheel", "packaging", "dill" + "setuptools>=62", "wheel", "packaging", "dill" ] +[tool.setuptools] +include-package-data = false + +[tool.setuptools.packages.find] +include = ["/phlop*"] +exclude = ["/sh*", "/tests*"] diff --git a/setup.py b/setup.py deleted file mode 100644 index 602dc1f..0000000 --- a/setup.py +++ /dev/null @@ -1,10 +0,0 @@ -from setuptools import find_packages, setup - -setup( - name="phlop", - version="0.0.14", - cmdclass={}, - classifiers=[], - include_package_data=True, - packages=find_packages(exclude=["lib/", "tests/"]), -)