Skip to content

Commit d068e95

Browse files
authored
Add: pre-commit and linting / formatting (#25)
* Add: pre-commit and linting / formatting * Fix: run pre-commit / ruff * Fix: changelog
1 parent 5f3901c commit d068e95

File tree

7 files changed

+90
-12
lines changed

7 files changed

+90
-12
lines changed

.pre-commit-config.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# pre-commit (https://pre-commit.com/) is a tool that runs source code checks
2+
# such as linting, formatting, and code style.
3+
4+
# CI
5+
# pyosMeta uses pre-commit with the precommit.ci bot to check pull requests.
6+
# Configuration reference doc: https://pre-commit.com/#pre-commit-configyaml---top-level
7+
8+
# Developers
9+
# You may want to install pre-commit to run locally on each minimum_pre_commit_version
10+
# See https://pre-commit.com/#install
11+
# To set up pre-commit hooks: pre-commit install
12+
# To run on all files: pre-commit run --all-files
13+
14+
ci:
15+
# pyosMeta disables autofixing of PRs to simplify new contributor experience and cleaner git history
16+
autofix_prs: false
17+
# Frequency of hook updates
18+
autoupdate_schedule: weekly
19+
20+
repos:
21+
# Out of the box hooks for pre-commit https://github.com/pre-commit/pre-commit-hooks
22+
- repo: https://github.com/pre-commit/pre-commit-hooks
23+
rev: v4.6.0
24+
hooks:
25+
# Makes sure files end in a newline and only a newline.
26+
- id: end-of-file-fixer
27+
# Check for files with names that would conflict on a case-insensitive filesystem like MacOS HFS+ or Windows FAT.
28+
- id: check-case-conflict
29+
# Remove trailing whitespace on code lines
30+
- id: trailing-whitespace
31+
32+
# Spelling hook
33+
- repo: https://github.com/codespell-project/codespell
34+
rev: v2.3.0
35+
hooks:
36+
- id: codespell
37+
additional_dependencies:
38+
- tomli
39+
40+
# Lint code using ruff
41+
- repo: https://github.com/astral-sh/ruff-pre-commit
42+
rev: v0.3.5
43+
hooks:
44+
- id: ruff
45+
args: [--fix, --exit-non-zero-on-fix]
46+
# Ruff can be used as a code formatter replacing black
47+
# It can also replace isort
48+
- id: ruff-format
49+
args: ["--line-length", "79"]

CODE_OF_CONDUCT.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
We as members, contributors, and leaders pledge to make participation in our
77
community a harassment-free experience for everyone, regardless of age, body
88
size, visible or invisible disability, ethnicity, sex characteristics, gender
9-
identity and expression, level of experience, education, socio-economic status,
9+
identity and expression, level of experience, education, socioeconomic status,
1010
nationality, personal appearance, race, caste, color, religion, or sexual
1111
identity and orientation.
1212

@@ -60,7 +60,7 @@ representative at an online or offline event.
6060
## Enforcement
6161

6262
Instances of abusive, harassing, or otherwise unacceptable behavior may be
63-
reported to the community leaders responsible for enforcement using
63+
reported to the community leaders responsible for enforcement using
6464
[this form](https://forms.gle/7MR7tCpDuprtStWP9).
6565

6666
All complaints will be reviewed and investigated promptly and fairly.
@@ -130,5 +130,5 @@ For answers to common questions about this code of conduct, see the FAQ at
130130
## pyOpenSci Code of Conduct
131131

132132
Please note the anyone contributing to any Github repositories in the pyOpenSci
133-
GitHub organization must also adhere to the
134-
[pyOpenSci Code of Conduct](https://www.pyopensci.org/handbook/CODE_OF_CONDUCT.html).
133+
GitHub organization must also adhere to the
134+
[pyOpenSci Code of Conduct](https://www.pyopensci.org/handbook/CODE_OF_CONDUCT.html).

README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# pyospackage
1+
# pyospackage
22
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
33
[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors-)
44
<!-- ALL-CONTRIBUTORS-BADGE:END -->
@@ -11,7 +11,7 @@
1111
[![pyOpenSci](https://tinyurl.com/y22nb8up)](https://github.com/pyOpenSci/software-review/issues/115)
1212

1313
## What does pyospackage do?
14-
pyospackage is a demonstration Python package that compliments the pyOpenSci [beginner tutorial series on creating a Python package](https://www.pyopensci.org/python-package-guide/tutorials/intro.html).
14+
pyospackage is a demonstration Python package that compliments the pyOpenSci [beginner tutorial series on creating a Python package](https://www.pyopensci.org/python-package-guide/tutorials/intro.html).
1515

1616
**Table of Contents**
1717

@@ -47,6 +47,23 @@ print(a)
4747

4848
You can also add any links to this section to tutorials in your documentation.
4949

50+
## Development
51+
52+
* TODO: link to development docs when they exist and move the text below to the
53+
docs.
54+
55+
### Linting & Code Formatting
56+
57+
TODO: this will be added to the docs once they are created in a separate pr.
58+
59+
All linting and code formatting is implemented in this package using a combination
60+
of pre-commit hooks and Ruff. Ruff is a fast, rust-based linter and code
61+
formatter that covers functionality previously implemented by Black and isort
62+
(formatters that are commonly used in the Python ecosystem). Ruff simplifies
63+
your linting and code format setup but running all of the checks and fixes
64+
using a single tool. As such pyOpenSci encourages new projects to consider
65+
using Ruff.
66+
5067
## Community
5168

5269
Information here about contributing to your package. links to your code of conduct and development guide.
@@ -85,4 +102,4 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
85102

86103
<!-- ALL-CONTRIBUTORS-LIST:END -->
87104

88-
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
105+
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!

changelog.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
* Fix: Drop support for python 3.9, add for 3.12 (@lwasser, #15)
66
* Add: Code of conduct to repo following contributors covenant (@lwasser, #17)
7+
* Add: Linting & code format using ruff / precommit (@lwasser, #19)
78

89
## 0.1.10
910

10-
* Initial publish to PyPI & Conda forge
11+
* Initial publish to PyPI & Conda forge
1112

1213
## 0.1.9
1314

@@ -23,4 +24,4 @@
2324

2425
## 0.1.6
2526

26-
* Fix: Add `readme` and `pyproject.toml` file
27+
* Fix: Add `readme` and `pyproject.toml` file

pyproject.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,13 @@ Source = "https://github.com/pyopensci/pyospackage"
3434
dependencies = [
3535
"pytest",
3636
"pytest-cov"
37-
]
37+
]
38+
39+
40+
[tool.ruff]
41+
lint.select = [
42+
"F", # pyflakes
43+
"I", # isort
44+
]
45+
lint.ignore = ["F841"]
46+
line-length = 79

src/pyospackage/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
from pyospackage.add_numbers import add_num

src/pyospackage/add_numbers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
"""A module that performs basic math operations."""
22

33

4-
def add_num(a: int, b: int) -> int:
4+
def add_num(
5+
a: int,
6+
b: int,
7+
) -> int:
58
return a + b

0 commit comments

Comments
 (0)