diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 102888d..6b1fc3d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,7 +24,7 @@ jobs: shell: bash -l {0} steps: - uses: actions/checkout@v2 - - uses: conda-incubator/setup-miniconda@v2 + - uses: conda-incubator/setup-miniconda@v3 with: mamba-version: "*" channels: conda-forge @@ -58,7 +58,7 @@ jobs: name: Build and publish Python distributions to PyPI and TestPyPI runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: conda-incubator/setup-miniconda@v2 with: mamba-version: "*" diff --git a/cppimport/__init__.py b/cppimport/__init__.py index 34f91f5..f1bb6fc 100644 --- a/cppimport/__init__.py +++ b/cppimport/__init__.py @@ -18,7 +18,7 @@ force_rebuild=False, # `force_rebuild` with multiple processes is not supported file_exts=[".cpp", ".c"], rtld_flags=ctypes.RTLD_LOCAL, - use_filelock=True, # Use filelocking if multiple processes try to build simultaneously + use_filelock=True, # Filelock if multiple processes try to build simultaneously lock_suffix=".lock", lock_timeout=10 * 60, remove_strict_prototypes=True, diff --git a/cppimport/build_module.py b/cppimport/build_module.py index 9585c9b..bec390e 100644 --- a/cppimport/build_module.py +++ b/cppimport/build_module.py @@ -98,7 +98,7 @@ def _handle_strict_prototypes(): cfg_vars = distutils.sysconfig.get_config_vars() for key, value in cfg_vars.items(): - if type(value) == str: + if value is str: cfg_vars[key] = value.replace("-Wstrict-prototypes", "") @@ -144,7 +144,6 @@ def _parallel_compile( extra_postargs=None, depends=None, ): - # these lines are copied directly from distutils.ccompiler.CCompiler macros, objects, extra_postargs, pp_opts, build = self._setup_compile( output_dir, macros, include_dirs, sources, depends, extra_postargs diff --git a/cppimport/importer.py b/cppimport/importer.py index cd74953..e5ca91d 100644 --- a/cppimport/importer.py +++ b/cppimport/importer.py @@ -43,7 +43,7 @@ def build_completed(): t = time() - if cppimport.settings['use_filelock']: + if cppimport.settings["use_filelock"]: # Race to obtain the lock and build. Other processes can wait while not build_completed() and time() - t < cppimport.settings["lock_timeout"]: try: diff --git a/tests/conftest.py b/tests/conftest.py index 05b4d6a..627e092 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,3 +1,8 @@ def pytest_addoption(parser): - parser.addoption('--multiprocessing', action='store_true', dest="multiprocessing", - default=False, help="enable multiprocessing tests with filelock") \ No newline at end of file + parser.addoption( + "--multiprocessing", + action="store_true", + dest="multiprocessing", + default=False, + help="enable multiprocessing tests with filelock", + ) diff --git a/tests/test_cppimport.py b/tests/test_cppimport.py index 7fad207..a21942d 100644 --- a/tests/test_cppimport.py +++ b/tests/test_cppimport.py @@ -5,17 +5,17 @@ import shutil import subprocess import sys -import pytest from multiprocessing import Process from tempfile import TemporaryDirectory +import pytest + import cppimport import cppimport.build_module import cppimport.templating from cppimport.find import find_module_cpppath -cppimport.settings["use_filelock"] = False # No need for filelock except for - # multiprocessing test. +cppimport.settings["use_filelock"] = False # Filelock only enabled for multiprocessing multiprocessing_enable = pytest.mark.skipif("not config.getoption('multiprocessing')") root_logger = logging.getLogger() @@ -27,6 +27,7 @@ handler.setFormatter(formatter) root_logger.addHandler(handler) + @contextlib.contextmanager def appended(filename, text): with open(filename, "r") as f: @@ -131,8 +132,8 @@ def test_with_file_in_syspath(): def test_rebuild_after_failed_compile(): cppimport.imp("mymodule") test_code = """ -import cppimport; -cppimport.settings["use_filelock"] = False; +import cppimport; +cppimport.settings["use_filelock"] = False; mymodule = cppimport.imp("mymodule"); assert(mymodule.add(1,2) == 3) """ @@ -156,7 +157,7 @@ def test_no_rebuild_if_no_deps_change(): cppimport.imp("mymodule") test_code = """ import cppimport; -cppimport.settings["use_filelock"] = False; +cppimport.settings["use_filelock"] = False; mymodule = cppimport.imp("mymodule"); assert(not hasattr(mymodule, 'Thing')) """ @@ -168,7 +169,7 @@ def test_rebuild_header_after_change(): cppimport.imp("mymodule") test_code = """ import cppimport; -cppimport.settings["use_filelock"] = False; +cppimport.settings["use_filelock"] = False; mymodule = cppimport.imp("mymodule"); mymodule.Thing().cheer() """ @@ -223,12 +224,13 @@ def test_relative_import(): print(f()) assert f() == 3 + @multiprocessing_enable def test_multiple_processes(): - ''' + """ Only runs if the flag --multiprocessing is passed to - pytest. This function requires file locking enabled. - ''' + pytest. This function requires file locking enabled. + """ with tmp_dir(["tests/hook_test.cpp"]) as tmp_path: test_code = f""" import os;