Skip to content

Commit

Permalink
Passed flake8, black, isort, upgraded miniconda GH action.
Browse files Browse the repository at this point in the history
  • Loading branch information
vbharadwaj-bk committed May 31, 2024
1 parent 9dcfae8 commit ab4e2f4
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: "*"
Expand Down
2 changes: 1 addition & 1 deletion cppimport/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions cppimport/build_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "")


Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cppimport/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 7 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
def pytest_addoption(parser):
parser.addoption('--multiprocessing', action='store_true', dest="multiprocessing",
default=False, help="enable multiprocessing tests with filelock")
parser.addoption(
"--multiprocessing",
action="store_true",
dest="multiprocessing",
default=False,
help="enable multiprocessing tests with filelock",
)
22 changes: 12 additions & 10 deletions tests/test_cppimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -27,6 +27,7 @@
handler.setFormatter(formatter)
root_logger.addHandler(handler)


@contextlib.contextmanager
def appended(filename, text):
with open(filename, "r") as f:
Expand Down Expand Up @@ -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)
"""
Expand All @@ -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'))
"""
Expand All @@ -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()
"""
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ab4e2f4

Please sign in to comment.