Skip to content

Commit

Permalink
Add support for .gitignore to scripts/lint.py (#2666)
Browse files Browse the repository at this point in the history
### What

Maintaining a separate list of ignore directory in `scripts/lint.py` bit
me several times already (e.g. `venv38`, `.nox`, etc.). This PR makes it
so that `lint.py` now uses `.gitignore` instead.

To check correctness, I verified the list of files that is considered
before and after the change. Of the 1078 files originally checked, a
single one is now missing
(`examples/python/dicom_mri/dataset/dicom/README.md`) due to the
`**/dataset/` rule in .gitignore. This is actually more correct than
before, as this is a foreign file.

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested [demo.rerun.io](https://demo.rerun.io/pr/2666) (if
applicable)

- [PR Build Summary](https://build.rerun.io/pr/2666)
- [Docs
preview](https://rerun.io/preview/pr%3Aantoine%2Flint-py-gitignore/docs)
- [Examples
preview](https://rerun.io/preview/pr%3Aantoine%2Flint-py-gitignore/examples)
  • Loading branch information
abey79 authored Jul 11, 2023
1 parent da81c90 commit 951c5ca
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/reusable_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ jobs:
with:
python-version: "3.8"

- name: Install dependencies
run: |
pip install gitignore_parser
- name: Rerun lints
run: |
./scripts/lint.py
Expand Down Expand Up @@ -325,4 +329,3 @@ jobs:
shell: bash
id: expected_version
run: ./scripts/ci/cargo_deny.sh

11 changes: 8 additions & 3 deletions scripts/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import sys
from typing import Any

from gitignore_parser import parse_gitignore

# -----------------------------------------------------------------------------

todo_pattern = re.compile(r"TODO([^(]|$)")
Expand Down Expand Up @@ -443,8 +445,6 @@ def main() -> None:

extensions = ["c", "cpp", "fbs", "h", "hpp" "html", "js", "md", "py", "rs", "sh", "toml", "txt", "wgsl", "yml"]

exclude_dirs = {"env", "renv", "venv", "venv3.10", "target", "target_ra", "target_wasm", ".nox"}

exclude_paths = {
"./CODE_STYLE.md",
"./crates/re_types_builder/src/reflection.rs", # auto-generated
Expand All @@ -454,12 +454,17 @@ def main() -> None:
"./web_viewer/re_viewer_debug.js", # auto-generated by wasm_bindgen
}

matches = parse_gitignore(".gitignore")

for root, dirs, files in os.walk(".", topdown=True):
dirs[:] = [d for d in dirs if d not in exclude_dirs]
dirs[:] = [d for d in dirs if not matches(d)]

for filename in files:
extension = filename.split(".")[-1]
if extension in extensions:
filepath = os.path.join(root, filename)
if matches(filepath):
continue
if filepath not in exclude_paths:
num_errors += lint_file(filepath, args)

Expand Down
1 change: 1 addition & 0 deletions scripts/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ PyGithub==1.58.2 # for scripts/ci/generate_pr_summary.py and scripts/ci/update_p
Pillow # for scripts/upload_image.py
tqdm
requests
gitignore_parser # handle .gitignore

0 comments on commit 951c5ca

Please sign in to comment.