From 873cf585cb872586a1c298be2ada6992b80cdc55 Mon Sep 17 00:00:00 2001 From: Jirka Date: Sat, 30 Sep 2023 22:29:59 +0200 Subject: [PATCH 1/3] precommit: enable codespell --- .pre-commit-config.yaml | 7 +++++++ src/lightning_utilities/cli/dependencies.py | 4 ++-- src/lightning_utilities/docs/retriever.py | 8 ++++---- tests/unittests/docs/test_retriever.py | 8 ++++---- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8e1f7a89..f41b7b15 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,6 +28,13 @@ repos: args: [--py37-plus] name: Upgrade code + - repo: https://github.com/codespell-project/codespell + rev: v2.2.5 + hooks: + - id: codespell + additional_dependencies: [tomli] + args: ["--write-changes"] # uncomment if you want to get automatic fixing + - repo: https://github.com/psf/black rev: 23.7.0 hooks: diff --git a/src/lightning_utilities/cli/dependencies.py b/src/lightning_utilities/cli/dependencies.py index 7bb2c901..f5b94313 100644 --- a/src/lightning_utilities/cli/dependencies.py +++ b/src/lightning_utilities/cli/dependencies.py @@ -38,8 +38,8 @@ def _prune_packages(req_file: str, packages: Sequence[str]) -> None: def _replace_min(fname: str) -> None: - with open(fname) as fo: - req = fo.read().replace(">=", "==") + with open(fname) as fopen: + req = fopen.read().replace(">=", "==") with open(fname, "w") as fw: fw.write(req) diff --git a/src/lightning_utilities/docs/retriever.py b/src/lightning_utilities/docs/retriever.py index 80496051..4215840c 100644 --- a/src/lightning_utilities/docs/retriever.py +++ b/src/lightning_utilities/docs/retriever.py @@ -32,8 +32,8 @@ def _search_all_occurrences(list_files: List[str], pattern: str) -> List[str]: """ collected = [] for file_path in list_files: - with open(file_path, encoding="UTF-8") as fo: - body = fo.read() + with open(file_path, encoding="UTF-8") as fopem: + body = fopem.read() found = re.findall(pattern, body) collected += found return collected @@ -53,8 +53,8 @@ def _replace_remote_with_local( relt_path = os.path.dirname(file_path).replace(docs_folder, "") # filter the path starting with / as not empty folder names depth = len([p for p in relt_path.split(os.path.sep) if p]) - with open(file_path, encoding="UTF-8") as fo: - body = fo.read() + with open(file_path, encoding="UTF-8") as fopen: + body = fopen.read() for url, fpath in pairs_url_path: if depth: path_up = [".."] * depth diff --git a/tests/unittests/docs/test_retriever.py b/tests/unittests/docs/test_retriever.py index a77ce77f..f8cc6919 100644 --- a/tests/unittests/docs/test_retriever.py +++ b/tests/unittests/docs/test_retriever.py @@ -15,15 +15,15 @@ def test_retriever_s3(): fetch_external_assets(docs_folder=path_docs) - with open(path_index, encoding="UTF-8") as fo: - body = fo.read() + with open(path_index, encoding="UTF-8") as fopen: + body = fopen.read() # that the image exists~ assert "Lightning.gif" in body # but it is not sourced from S3 assert ".s3." not in body - with open(path_page, encoding="UTF-8") as fo: - body = fo.read() + with open(path_page, encoding="UTF-8") as fopen: + body = fopen.read() # that the image exists~ assert "Lightning.gif" in body # check the proper depth From 99f122001c12e0b79543a4cfc21753e9f404f79b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 30 Sep 2023 20:32:41 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .github/workflows/check-code.yml | 2 +- CHANGELOG.md | 2 +- src/lightning_utilities/core/imports.py | 2 +- src/lightning_utilities/docs/retriever.py | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/check-code.yml b/.github/workflows/check-code.yml index 1132c47a..39931505 100644 --- a/.github/workflows/check-code.yml +++ b/.github/workflows/check-code.yml @@ -1,4 +1,4 @@ -name: Check formating flow +name: Check formatting flow on: workflow_call: diff --git a/CHANGELOG.md b/CHANGELOG.md index b32c3670..3c2f8853 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -111,7 +111,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -- CI: Checking schem in both yaml & yml + verbose ([#84](https://github.com/Lightning-AI/utilities/pull/84)) +- CI: Checking scheme in both yaml & yml + verbose ([#84](https://github.com/Lightning-AI/utilities/pull/84)) ## [0.5.0] - 2022-12-21 diff --git a/src/lightning_utilities/core/imports.py b/src/lightning_utilities/core/imports.py index 56413ca2..b96d1e86 100644 --- a/src/lightning_utilities/core/imports.py +++ b/src/lightning_utilities/core/imports.py @@ -276,7 +276,7 @@ def requires(*module_path_version: str, raise_exception: bool = True) -> Callabl """Wrap early import failure with some nice exception message. Args: - module_path_version: pythin package path (e.g. `torch.cuda`) or pip like requiremsnt (e.g. `torch>=2.0.0`) + module_path_version: python package path (e.g. `torch.cuda`) or pip like requiremsnt (e.g. `torch>=2.0.0`) raise_exception: how strict the check shall be if exit the code or just warn user Example: diff --git a/src/lightning_utilities/docs/retriever.py b/src/lightning_utilities/docs/retriever.py index 4215840c..3bcce647 100644 --- a/src/lightning_utilities/docs/retriever.py +++ b/src/lightning_utilities/docs/retriever.py @@ -24,7 +24,7 @@ def _download_file(file_url: str, folder: str) -> str: def _search_all_occurrences(list_files: List[str], pattern: str) -> List[str]: - """Search for all occurrences of specific patter in a collection of files. + """Search for all occurrences of specific pattern in a collection of files. Args: list_files: list of files to be scanned @@ -76,7 +76,7 @@ def fetch_external_assets( docs_folder: the location of docs related to the project root assets_folder: a folder inside ``docs_folder`` to be created and saving online assets file_pattern: what kind of files shall be scanned - retrieve_pattern: patter for reg. expression to search URL/S3 resources + retrieve_pattern: pattern for reg. expression to search URL/S3 resources """ list_files = glob.glob(os.path.join(docs_folder, "**", file_pattern), recursive=True) if not list_files: From 7f12d6f7629028641de11416d06078ab867982e1 Mon Sep 17 00:00:00 2001 From: Jirka Date: Sat, 30 Sep 2023 22:35:33 +0200 Subject: [PATCH 3/3] fixing --- .github/actions/pkg-install/action.yml | 4 ++-- .github/scripts/find-unused-caches.txt | 2 +- .pre-commit-config.yaml | 2 +- pyproject.toml | 25 ++++++++++++------------- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/.github/actions/pkg-install/action.yml b/.github/actions/pkg-install/action.yml index e9c87012..23f8ed3f 100644 --- a/.github/actions/pkg-install/action.yml +++ b/.github/actions/pkg-install/action.yml @@ -31,7 +31,7 @@ runs: - name: Install package (wheel) working-directory: pypi/ run: | - # TODO: reset env / conside add as conda + # TODO: reset env / consider add as conda pip install *.whl ${{ inputs.pip-flags }} python -c "import ${{ inputs.import-name }} as pkg; print(f'version: {pkg.__version__}')" pip list @@ -46,7 +46,7 @@ runs: - name: Install package (archive) working-directory: pypi/ run: | - # TODO: reset env / conside add as conda + # TODO: reset env / consider add as conda pip install *.tar.gz ${{ inputs.pip-flags }} python -c "import ${{ inputs.import-name }} as pkg; print(f'version: {pkg.__version__}')" pip list diff --git a/.github/scripts/find-unused-caches.txt b/.github/scripts/find-unused-caches.txt index 5c5803b9..004fd96d 100644 --- a/.github/scripts/find-unused-caches.txt +++ b/.github/scripts/find-unused-caches.txt @@ -1,4 +1,4 @@ -# Requirements for running equally named scrit, +# Requirements for running equally named script, # having it in extra file to prevent version discrepancy if hardcoded in workflow fire diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f41b7b15..6b7391fe 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -33,7 +33,7 @@ repos: hooks: - id: codespell additional_dependencies: [tomli] - args: ["--write-changes"] # uncomment if you want to get automatic fixing + #args: ["--write-changes"] # uncomment if you want to get automatic fixing - repo: https://github.com/psf/black rev: 23.7.0 diff --git a/pyproject.toml b/pyproject.toml index 5e2ca4fe..6fd1a773 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,7 +23,6 @@ norecursedirs = [ "build", "docs", ] - addopts = [ "--strict-markers", "--doctest-modules", @@ -39,28 +38,28 @@ exclude_lines = [ "pragma: no cover", "pass", ] - [tool.coverage.run] parallel = true concurrency = "thread" relative_files = true + +[tool.codespell] +# Todo: enable also python files in a next step +skip = '*.py' +quiet-level = 3 +# comma separated list of words; waiting for: +# https://github.com/codespell-project/codespell/issues/2839#issuecomment-1731601603 +# also adding links until they ignored by its: nature +# https://github.com/codespell-project/codespell/issues/2243#issuecomment-1732019960 +ignore-words-list = "te, compiletime" + + [tool.black] # https://github.com/psf/black line-length = 120 exclude = "(.eggs|.git|.hg|.mypy_cache|.venv|_build|buck-out|build|dist)" -[tool.isort] -known_first_party = [ - "lightning_utilities", - "tests" -] -skip_glob = [] -profile = "black" -line_length = 120 -order_by_type = false -multi_line_output = 3 -include_trailing_comma = true [tool.mypy] files = [