From 61b69bdfd99b3d709ca831b67725e98f44dbef99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joonhyung=20Lee/=EC=9D=B4=EC=A4=80=ED=98=95?= <33523965+veritas9872@users.noreply.github.com> Date: Tue, 11 Apr 2023 19:40:07 +0900 Subject: [PATCH] Miscellaneous bug fixes and updates. (#118) * Reorder pre-commits to have correction executed before formatting. Also move debug detection from pre-commit to ruff. * Add as many `ruff` rules as seems reasonable. * Change login shell for Dockerfiles to `zsh` even in non-interactive mode for consistency. * Reformat files. * Change PyTest tests according to the new recommendations. --- .pre-commit-config.yaml | 11 ++++------- Dockerfile | 1 + dockerfiles/simple.Dockerfile | 1 + pyproject.toml | 11 +++++++++-- tests/test_run.py | 8 ++++---- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b3a8f0e..a5f9ee7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,7 +19,6 @@ repos: - id: check-toml - id: check-xml - id: check-yaml - - id: debug-statements - id: destroyed-symlinks - id: detect-private-key - id: end-of-file-fixer @@ -45,23 +44,21 @@ repos: rev: v0.9.0 hooks: - id: shellcheck - # args: ["--severity=warning"] # Optionally only show errors and warnings - repo: https://github.com/google/pyink rev: 23.3.1 hooks: # Using PyInk, the Google fork of Black, for Python code formatting. - id: pyink - - repo: https://github.com/psf/black - rev: 23.3.0 # Always use the same version as PyInk. - hooks: # Using black for Jupyter Notebook formatting. - - id: black-jupyter - - repo: https://github.com/nbQA-dev/nbQA rev: 1.7.0 hooks: - id: nbqa-ruff # Run `ruff` on Jupyter Notebooks. + - repo: https://github.com/psf/black + rev: 23.3.0 # Always use the same version as PyInk. + hooks: # Using black for Jupyter Notebook formatting. + - id: black-jupyter # - repo: local # Clear Jupyter outputs before committing. # hooks: # - id: jupyter-nb-clear-output diff --git a/Dockerfile b/Dockerfile index 301b821..de4613c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -523,6 +523,7 @@ FROM train-base AS train-interactive-exclude COPY --link --from=train-builds /opt/conda /opt/conda RUN echo /opt/conda/lib >> /etc/ld.so.conf.d/conda.conf && ldconfig +RUN chsh --shell /bin/zsh ######################################################################## FROM train-interactive-${INTERACTIVE_MODE} AS train diff --git a/dockerfiles/simple.Dockerfile b/dockerfiles/simple.Dockerfile index 4f82ad6..699a43a 100644 --- a/dockerfiles/simple.Dockerfile +++ b/dockerfiles/simple.Dockerfile @@ -154,6 +154,7 @@ FROM train-base AS train-interactive-exclude # container registries such as Docker Hub. No users or interactive settings. COPY --link --from=install-conda /opt/conda /opt/conda RUN echo /opt/conda/lib >> /etc/ld.so.conf.d/conda.conf && ldconfig +RUN chsh --shell /bin/zsh ######################################################################## FROM train-base AS train-interactive-include diff --git a/pyproject.toml b/pyproject.toml index 592fc8d..0c2ed19 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,6 +30,7 @@ testpaths = [ line-length = 100 target-version = 'py38' select = [ +# "A", # flake8-builtins "B", # flake8-bugbear "BLE", # flake8-blind-except "C4", # flake8-comprehensions @@ -38,10 +39,16 @@ select = [ "E", # pycodestyle errors "F", # pyflakes "I", # isort + "ICN", # flake8-import-conventions + "ISC", # flake8-implicit-str-concat # "N", # PEP8-Naming "NPY", # NumPy-specific rules - "PLE", # Error - "PLW", # Warning + "PLC", # Pylint Convention + "PLE", # Pylint Error + "PLW", # Pylint Warning + "PT", # flake8-pytest-style + "SIM", # flake8-simplify + "T10", # flake8-debugger # "UP", # PyUpgrade "W", # pycodestyle warnings "YTT", # flake8-2020 diff --git a/tests/test_run.py b/tests/test_run.py index c601af6..eafc4c5 100644 --- a/tests/test_run.py +++ b/tests/test_run.py @@ -40,12 +40,12 @@ @pytest.fixture(scope="session", autouse=True) -def enable_cudnn_benchmarking(): +def _enable_cudnn_benchmarking(): torch.backends.cudnn.benchmark = True @pytest.fixture(scope="session", autouse=True) -def allow_tf32(): +def _allow_tf32(): torch.backends.cuda.matmul.allow_tf32 = True torch.backends.cudnn.allow_tf32 = True @@ -88,7 +88,7 @@ def num_steps(pytestconfig): return pytestconfig.getoption("num_steps") -@pytest.mark.parametrize(["name", "network_func", "input_shapes"], _configs) +@pytest.mark.parametrize(("name", "network_func", "input_shapes"), _configs) def test_inference_run( name: str, network_func: Callable[[], nn.Module], @@ -150,7 +150,7 @@ def _infer(network: nn.Module, inputs: Sequence[Tensor], num_steps: int) -> floa @pytest.fixture(scope="session", autouse=True) -def get_cuda_info(device): # Using as a fixture to get device info. +def _get_cuda_info(device): # Using as a fixture to get device info. logger.info(f"Python Version: {platform.python_version()}") logger.info(f"PyTorch Version: {torch.__version__}") if not torch.cuda.is_available():