Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add linter/formatter to enforce coding style #72

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/precommit.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ reports
STACpopulator.egg-info/
build
*.pyc
.ruff_cache

## Logs
*.jsonl
Expand Down
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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

3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
21 changes: 20 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Loading