diff --git a/.github/workflows/precommit.yml b/.github/workflows/precommit.yml new file mode 100644 index 0000000..9ec3eca --- /dev/null +++ b/.github/workflows/precommit.yml @@ -0,0 +1,13 @@ +name: pre-commit + +on: + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v3 + - uses: pre-commit/action@v3.0.1 diff --git a/.gitignore b/.gitignore index e2f19f1..c9128fa 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ reports STACpopulator.egg-info/ build *.pyc +.ruff_cache ## Logs *.jsonl diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..09d2144 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,10 @@ +repos: + - repo: https://github.com/astral-sh/ruff-pre-commit + # Ruff version. + rev: v0.9.5 + hooks: + # Run the linter. + - id: ruff + # Run the formatter. + - id: ruff-format + \ No newline at end of file diff --git a/CHANGES.md b/CHANGES.md index 030f7b8..a522a8c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -20,7 +20,8 @@ * move argument parsing for logging options to the implementation code * fix bug where logging options were being set incorrectly * rename files to avoid potential naming conflicts with other packages (`logging` and `requests`) - +* add `ruff` as a dev dependency to format and lint files +* add `pre-commit` as a dev dependency to run `ruff` on commit and a workflow to run it on github as well ## [0.6.0](https://github.com/crim-ca/stac-populator/tree/0.6.0) (2024-02-22) diff --git a/README.md b/README.md index 06563c7..f92ff3c 100644 --- a/README.md +++ b/README.md @@ -130,3 +130,28 @@ For more tests validation, you can also run the test suite with coverage analysi ```shell make test-cov ``` + +## Contributing + +We welcome any contributions to this codebase. To submit suggested changes, please do the following: + +- create a new feature branch off of `master` +- update the code, write/update tests, write/update documentation +- submit a pull request targetting the `master` branch + +### Coding Style + +This codebase uses the [`ruff`](https://docs.astral.sh/ruff/) formatter and linter to enforce style policies. + +To check that your changes conform to these policies please run: + +```sh +ruff format +ruff check +``` + +You can also set up pre-commit hooks that will run these checks before you create any commit in this repo: + +```sh +pre-commit install +``` diff --git a/pyproject.toml b/pyproject.toml index e3f5b34..9b2d141 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -168,6 +168,25 @@ dev = [ "responses", "bump-my-version", "jsonschema", - "pystac[validation]>=1.9.0" + "pystac[validation]>=1.9.0", + "ruff~=0.9", + "pre-commit~=4.1" ] +[tool.ruff] +line-length = 120 +target-version = "py312" + +[tool.ruff.format] +docstring-code-format = true +line-ending = "lf" + +[tool.ruff.lint] +select = ["E4", "E7", "E9", "F", "D", "I", "ANN"] +ignore = ["D100", "D104", "D417", "ANN002", "ANN003"] + +[tool.ruff.lint.pydocstyle] +convention = "numpy" + +[tool.ruff.lint.per-file-ignores] +"test/**.py" = ["D", "ANN"]