Skip to content

Commit d5fd7be

Browse files
authored
Merge pull request #8 from lemonyte/update-2024
2 parents 3e38115 + 7c1b9c4 commit d5fd7be

File tree

9 files changed

+154
-158
lines changed

9 files changed

+154
-158
lines changed

.github/workflows/lint.yaml

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# GitHub Action Workflow enforcing our code style.
1+
# GitHub Action workflow enforcing our code style.
22

33
name: Lint
44

@@ -9,6 +9,7 @@ on:
99
branches:
1010
- main
1111
pull_request:
12+
1213
# Brand new concurrency setting! This ensures that not more than one run can be triggered for the same commit.
1314
# It is useful for pull requests coming from the main repository since both triggers will match.
1415
concurrency: lint-${{ github.sha }}
@@ -19,18 +20,16 @@ jobs:
1920

2021
env:
2122
# The Python version your project uses. Feel free to change this if required.
22-
PYTHON_VERSION: "3.10"
23+
PYTHON_VERSION: "3.12"
2324

2425
steps:
25-
# Checks out the repository in the current folder.
26-
- name: Checks out repository
27-
uses: actions/checkout@v3
26+
- name: Checkout repository
27+
uses: actions/checkout@v4
2828

29-
# Set up the right version of Python
3029
- name: Set up Python ${{ env.PYTHON_VERSION }}
31-
uses: actions/setup-python@v3
30+
uses: actions/setup-python@v5
3231
with:
3332
python-version: ${{ env.PYTHON_VERSION }}
3433

3534
- name: Run pre-commit hooks
36-
uses: pre-commit/[email protected].0
35+
uses: pre-commit/[email protected].1

.pre-commit-config.yaml

+6-19
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,18 @@
1-
## Pre-commit setup
1+
# Pre-commit configuration.
22
# See https://github.com/python-discord/code-jam-template/tree/main#pre-commit-run-linting-before-committing
33

4-
# Make sure to edit the `additional_dependencies` list if you want to add plugins
5-
64
repos:
75
- repo: https://github.com/pre-commit/pre-commit-hooks
8-
rev: v2.5.0
6+
rev: v4.6.0
97
hooks:
108
- id: check-toml
119
- id: check-yaml
1210
- id: end-of-file-fixer
1311
- id: trailing-whitespace
1412
args: [--markdown-linebreak-ext=md]
1513

16-
- repo: https://github.com/pre-commit/pygrep-hooks
17-
rev: v1.5.1
18-
hooks:
19-
- id: python-check-blanket-noqa
20-
21-
- repo: https://github.com/PyCQA/isort
22-
rev: 5.12.0
23-
hooks:
24-
- id: isort
25-
26-
- repo: https://github.com/pycqa/flake8
27-
rev: 4.0.1
14+
- repo: https://github.com/astral-sh/ruff-pre-commit
15+
rev: v0.5.0
2816
hooks:
29-
- id: flake8
30-
additional_dependencies:
31-
- flake8-docstrings~=1.6.0
17+
- id: ruff
18+
- id: ruff-format

LICENSE renamed to LICENSE.txt

File renamed without changes.

README.md

+84-73
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,130 @@
11
# Python Discord Code Jam Repository Template
22

3-
## A Primer
3+
## A primer
4+
45
Hello code jam participants! We've put together this repository template for you to use in [our code jams](https://pythondiscord.com/events/) or even other Python events!
56

6-
This document will contain the following information:
7+
This document contains the following information:
8+
79
1. [What does this template contain?](#what-does-this-template-contain)
8-
2. [How do I use it?](#how-do-i-use-it)
9-
3. [How do I adapt it to my project?](#how-do-i-adapt-it-to-my-project)
10+
2. [How do I use this template?](#how-do-i-use-this-template)
11+
3. [How do I adapt this template to my project?](#how-do-i-adapt-this-template-to-my-project)
1012

11-
You can also look at [our style guide](https://pythondiscord.com/events/code-jams/code-style-guide/) to get more information about what we consider a maintainable code style.
13+
> [!TIP]
14+
> You can also look at [our style guide](https://pythondiscord.com/events/code-jams/code-style-guide/) to get more information about what we consider a maintainable code style.
1215
1316
## What does this template contain?
1417

1518
Here is a quick rundown of what each file in this repository contains:
16-
- `LICENSE`: [The MIT License](https://opensource.org/licenses/MIT), an OSS approved license which grants rights to everyone to use and modify your projects and limits your liability. We highly recommend you to read the license.
17-
- `.gitignore`: A list of files that will be ignored by Git. Most of them are auto-generated or contain data that you wouldn't want to share publicly.
18-
- `dev-requirements.txt`: Every PyPI packages used for the project's development, to ensure a common and maintainable code style. [More on that below](#using-the-default-pip-setup).
19-
- `tox.ini`: The configurations of two of our style tools: [`flake8`](https://pypi.org/project/flake8/) and [`isort`](https://pypi.org/project/isort/).
20-
- `.pre-commit-config.yaml`: The configuration of the [`pre-commit`](https://pypi.org/project/pre-commit/) tool.
21-
- `.github/workflows/lint.yaml`: A [GitHub Actions](https://github.com/features/actions) workflow, a set of actions run by GitHub on their server after each push, to ensure the style requirements are met.
19+
20+
- [`LICENSE.txt`](LICENSE.txt): [The MIT License](https://opensource.org/licenses/MIT), an OSS approved license which grants rights to everyone to use and modify your project, and limits your liability. We highly recommend you to read the license.
21+
- [`.gitignore`](.gitignore): A list of files and directories that will be ignored by Git. Most of them are auto-generated or contain data that you wouldn't want to share publicly.
22+
- [`requirements-dev.txt`](requirements-dev.txt): Every PyPI package used for the project's development, to ensure a common development environment. More on that [below](#using-the-default-pip-setup).
23+
- [`pyproject.toml`](pyproject.toml): Configuration and metadata for the project, as well as the linting tool Ruff. If you're interested, you can read more about `pyproject.toml` in the [Python Packaging documentation](https://packaging.python.org/en/latest/guides/writing-pyproject-toml/).
24+
- [`.pre-commit-config.yaml`](.pre-commit-config.yaml): The configuration of the [pre-commit](https://pre-commit.com/) tool.
25+
- [`.github/workflows/lint.yaml`](.github/workflows/lint.yaml): A [GitHub Actions](https://github.com/features/actions) workflow, a set of actions run by GitHub on their server after each push, to ensure the style requirements are met.
2226

2327
Each of these files have comments for you to understand easily, and modify to fit your needs.
2428

25-
### flake8: general style rules
29+
### Ruff: general style rules
30+
31+
Our first tool is Ruff. It will check your codebase and warn you about any non-conforming lines.
32+
It is run with the command `ruff check` in the project root.
2633

27-
Our first and probably most important tool is flake8. It will run a set of plugins on your codebase and warn you about any non-conforming lines.
2834
Here is a sample output:
29-
```
30-
~> flake8
31-
./app.py:1:6: N802 function name 'helloWorld' should be lowercase
32-
./app.py:1:16: E201 whitespace after '('
33-
./app.py:2:1: D400 First line should end with a period
34-
./app.py:2:1: D403 First word of the first line should be properly capitalized
35-
./app.py:3:19: E225 missing whitespace around operator
35+
36+
```shell
37+
$ ruff check
38+
app.py:1:5: N802 Function name `helloWorld` should be lowercase
39+
app.py:1:5: ANN201 Missing return type annotation for public function `helloWorld`
40+
app.py:2:5: D400 First line should end with a period
41+
app.py:2:5: D403 First word of the first line should be capitalized: `docstring` -> `Docstring`
42+
app.py:3:15: W292 No newline at end of file
43+
Found 5 errors.
3644
```
3745

3846
Each line corresponds to an error. The first part is the file path, then the line number, and the column index.
3947
Then comes the error code, a unique identifier of the error, and then a human-readable message.
4048

4149
If, for any reason, you do not wish to comply with this specific error on a specific line, you can add `# noqa: CODE` at the end of the line.
4250
For example:
51+
4352
```python
4453
def helloWorld(): # noqa: N802
4554
...
46-
```
47-
will pass linting. Although we do not recommend ignoring errors unless you have a good reason to do so.
48-
49-
It is run by calling `flake8` in the project root.
5055

51-
#### Plugin List:
56+
```
5257

53-
- `flake8-docstring`: Checks that you properly documented your code.
58+
This will ignore the function naming issue and pass linting.
5459

55-
### ISort: automatic import sorting
60+
> [!WARNING]
61+
> We do not recommend ignoring errors unless you have a good reason to do so.
5662
57-
This second tool will sort your imports according to the [PEP8](https://www.python.org/dev/peps/pep-0008/#imports). That's it! One less thing for you to do!
63+
### Ruff: formatting
5864

59-
It is run by calling `isort .` in the project root. Notice the dot at the end, it tells ISort to use the current directory.
65+
Ruff also comes with a formatter, which can be run with the command `ruff format`.
66+
It follows the same code style enforced by [Black](https://black.readthedocs.io/en/stable/index.html), so there's no need to pick between them.
6067

6168
### Pre-commit: run linting before committing
6269

63-
This third tool doesn't check your code, but rather makes sure that you actually *do* check it.
70+
The second tool doesn't check your code, but rather makes sure that you actually *do* check it.
6471

6572
It makes use of a feature called [Git hooks](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks) which allow you to run a piece of code before running `git commit`.
66-
The good thing about it is that it will cancel your commit if the lint doesn't pass. You won't have to wait for Github Actions to report and have a second fix commit.
73+
The good thing about it is that it will cancel your commit if the lint doesn't pass. You won't have to wait for GitHub Actions to report issues and have a second fix commit.
6774

6875
It is *installed* by running `pre-commit install` and can be run manually by calling only `pre-commit`.
6976

7077
[Lint before you push!](https://soundcloud.com/lemonsaurusrex/lint-before-you-push)
7178

72-
#### Hooks List:
79+
#### List of hooks
7380

7481
- `check-toml`: Lints and corrects your TOML files.
7582
- `check-yaml`: Lints and corrects your YAML files.
7683
- `end-of-file-fixer`: Makes sure you always have an empty line at the end of your file.
77-
- `trailing-whitespaces`: Removes whitespaces at the end of each line.
78-
- `python-check-blanket-noqa`: Forbids you from using noqas on large pieces of code.
79-
- `isort`: Runs ISort.
80-
- `flake8`: Runs flake8.
84+
- `trailing-whitespace`: Removes whitespaces at the end of each line.
85+
- `ruff`: Runs the Ruff linter.
86+
- `ruff-format`: Runs the Ruff formatter.
8187

82-
## How do I use it?
88+
## How do I use this template?
8389

84-
### Creating your Team Repository
90+
### Creating your team repository
8591

8692
One person in the team, preferably the leader, will have to create the repository and add other members as collaborators.
8793

8894
1. In the top right corner of your screen, where **Clone** usually is, you have a **Use this template** button to click.
89-
90-
![](https://docs.github.com/assets/images/help/repository/use-this-template-button.png)
91-
95+
![use-this-template-button](https://docs.github.com/assets/images/help/repository/use-this-template-button.png)
9296
2. Give the repository a name and a description.
93-
94-
![](https://docs.github.com/assets/images/help/repository/create-repository-name.png)
95-
97+
![create-repository-name](https://docs.github.com/assets/images/help/repository/create-repository-name.png)
9698
3. Click **Create repository from template**.
97-
9899
4. Click **Settings** in your newly created repository.
99-
100-
![](https://docs.github.com/assets/images/help/repository/repo-actions-settings.png)
101-
100+
![repo-actions-settings](https://docs.github.com/assets/images/help/repository/repo-actions-settings.png)
102101
5. In the "Access" section of the sidebar, click **Collaborators**.
103-
104-
![Screenshot from 2023-08-28 14-09-55](https://github.com/python-discord/code-jam-template/assets/63936253/c150110e-d1b5-4e4d-93e0-0a2cf1de352b)
105-
102+
![collaborators-settings](https://github.com/python-discord/code-jam-template/assets/63936253/c150110e-d1b5-4e4d-93e0-0a2cf1de352b)
106103
6. Click **Add people**.
107-
108104
7. Insert the names of each of your teammates, and invite them. Once they have accepted the invitation in their email, they will have write access to the repository.
109105

110-
You are now ready to go! Now sit down, relax, and wait for the kickstart!
111-
Don't forget to swap "Python Discord" in the `LICENSE` file for the name of each of your team members or the name of your team after the start of the jam.
106+
You are now ready to go! Sit down, relax, and wait for the kickstart!
112107

113-
### Using the Default Pip Setup
108+
> [!IMPORTANT]
109+
> Don't forget to swap "Python Discord" in the [`LICENSE.txt`](LICENSE.txt) file for the name of each of your team members or the name of your team *after* the start of the code jam.
114110
115-
Our default setup includes a bare requirement file to be used with a [virtual environment](https://docs.python.org/3/library/venv.html).
111+
### Using the default pip setup
116112

117-
We recommend this if you never have used any other dependency manager, although if you have, feel free to switch to it. More on that below.
113+
Our default setup includes a bare requirements file to be used with a [virtual environment](https://docs.python.org/3/library/venv.html).
114+
We recommend this if you have never used any other dependency manager, although if you have, feel free to switch to it. More on that [below](#how-do-i-adapt-this-template-to-my-project).
118115

119116
#### Creating the environment
117+
120118
Create a virtual environment in the folder `.venv`.
119+
121120
```shell
122-
$ python -m venv .venv
121+
python -m venv .venv
123122
```
124123

125-
#### Enter the environment
124+
#### Entering the environment
125+
126126
It will change based on your operating system and shell.
127+
127128
```shell
128129
# Linux, Bash
129130
$ source .venv/bin/activate
@@ -139,35 +140,45 @@ $ .venv/bin/Activate.ps1
139140
> .venv\Scripts\Activate.ps1
140141
```
141142

142-
#### Installing the Dependencies
143+
#### Installing the dependencies
144+
143145
Once the environment is created and activated, use this command to install the development dependencies.
146+
144147
```shell
145-
$ pip install -r dev-requirements.txt
148+
pip install -r requirements-dev.txt
146149
```
147150

148151
#### Exiting the environment
149-
Interestingly enough, it is the same for every platform
152+
153+
Interestingly enough, it is the same for every platform.
154+
150155
```shell
151-
$ deactivate
156+
deactivate
152157
```
153158

154-
Once the environment is activated, all the commands listed previously should work. We highly recommend that you run `pre-commit install` as soon as possible.
159+
Once the environment is activated, all the commands listed previously should work.
160+
161+
> [!IMPORTANT]
162+
> We highly recommend that you run `pre-commit install` as soon as possible.
155163
156-
## How do I adapt it to my project?
164+
## How do I adapt this template to my project?
157165

158-
If you wish to use Pipenv or Poetry, you will have to move the dependencies in `dev-requirements.txt` to the development dependencies of your tool.
166+
If you wish to use Pipenv or Poetry, you will have to move the dependencies in [`requirements-dev.txt`](requirements-dev.txt) to the development dependencies of your tool.
159167

160-
We've included a porting of `dev-requirements.txt` to both [poetry](./samples/pyproject.toml) and [pipenv](./samples/Pipfile) in the [samples folder](./samples).
161-
If you use the poetry setup, make sure to change the project name, description, and authors at the top of the file.
168+
We've included a porting of [`requirements-dev.txt`](requirements-dev.txt) to both [Poetry](samples/pyproject.toml) and [Pipenv](samples/Pipfile) in the [`samples` folder](samples).
169+
If you use the Poetry setup, make sure to change the project name, description, and authors at the top of the file.
170+
Also note that the Poetry [`pyproject.toml`](samples/pyproject.toml) file does not include the Ruff configuration, so if you simply replace the file then the Ruff configuration will be lost.
162171

163-
When installing new dependencies, don't forget to [pin them](https://pip.pypa.io/en/stable/user_guide/#pinned-version-numbers) by adding a version tag at the end.
164-
For example, if I wish to install `Click`, a quick look at [PyPI](https://pypi.org/project/click/) tells me that 8.0.1 is the latest version.
165-
I will then add `click ~= 8.0`, without the last number, to my dependency manager.
172+
When installing new dependencies, don't forget to [pin](https://pip.pypa.io/en/stable/topics/repeatable-installs/#pinning-the-package-versions) them by adding a version tag at the end.
173+
For example, if I wish to install [Click](https://click.palletsprojects.com/en/8.1.x/), a quick look at [PyPI](https://pypi.org/project/click/) tells me that `8.1.7` is the latest version.
174+
I will then add `click~=8.1`, without the last number, to my requirements file or dependency manager.
166175

167-
A code jam project is left unmaintained after the end of the event. If the dependencies aren't pinned, the project will break after the first major change in an API.
176+
> [!IMPORTANT]
177+
> A code jam project is left unmaintained after the end of the event. If the dependencies aren't pinned, the project will break after any major change in an API.
168178
169179
## Final words
170180

171-
Don't forget to replace this README with an actual description of your project! Images are also welcome!
181+
> [!IMPORTANT]
182+
> Don't forget to replace this README with an actual description of your project! Images are also welcome!
172183
173184
We hope this template will be helpful. Good luck in the jam!

pyproject.toml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[tool.ruff]
2+
# Increase the line length. This breaks PEP8 but it is way easier to work with.
3+
# The original reason for this limit was a standard vim terminal is only 79 characters,
4+
# but this doesn't really apply anymore.
5+
line-length = 119
6+
# Target Python 3.12. If you decide to use a different version of Python
7+
# you will need to update this value.
8+
target-version = "py312"
9+
# Automatically fix auto-fixable issues.
10+
fix = true
11+
# The directory containing the source code. If you choose a different project layout
12+
# you will need to update this value.
13+
src = ["src"]
14+
15+
[tool.ruff.lint]
16+
# Enable all linting rules.
17+
select = ["ALL"]
18+
# Ignore some of the most obnoxious linting errors.
19+
ignore = [
20+
# Missing docstrings.
21+
"D100",
22+
"D104",
23+
"D105",
24+
"D106",
25+
"D107",
26+
# Docstring whitespace.
27+
"D203",
28+
"D213",
29+
# Docstring punctuation.
30+
"D415",
31+
# Docstring quotes.
32+
"D301",
33+
# Builtins.
34+
"A",
35+
# Print statements.
36+
"T20",
37+
# TODOs.
38+
"TD002",
39+
"TD003",
40+
"FIX",
41+
# Annotations.
42+
"ANN101",
43+
"ANN102",
44+
]

dev-requirements.txt renamed to requirements-dev.txt

+2-7
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,5 @@
22
# Don't forget to pin your dependencies!
33
# This list will have to be migrated if you wish to use another dependency manager.
44

5-
# Base tools
6-
flake8~=4.0.1
7-
isort~=5.10.1
8-
pre-commit~=2.17.0
9-
10-
# Flake8 plugins, see https://github.com/python-discord/code-jam-template/tree/main#plugin-list
11-
flake8-docstrings~=1.6.0
5+
ruff~=0.5.0
6+
pre-commit~=3.7.1

0 commit comments

Comments
 (0)