You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: package-structure-code/code-style-linting-format.md
+13-9Lines changed: 13 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Python Package Code Style, Format and Linters
2
2
3
-
```{admonition} Take Aways
3
+
:::{admonition} Take Aways
4
4
5
5
* pyOpenSci requires authors to follow PEP 8 code format guidelines
6
6
* Setting up a code formatters like Black and isort will help you enforce PEP 8 style guidelines and also consistent, readable code format
@@ -9,7 +9,7 @@
9
9
each time you make a commit.
10
10
*[precommit.ci](https://pre-commit.ci/) is a bot that you can add to your GitHub repository. It will automagically apply code format to every PR using the tools specified in your pre-commit-config.yaml file. It can save significant time and make contributions easier for new contributors.
11
11
* Automation is good! By making code quality tools care of your code, you can focus on structural and high values tasks.
12
-
```
12
+
:::
13
13
14
14
Consistent code format and style is useful to both your package
15
15
and across the scientific Python ecosystem because using similar
@@ -35,6 +35,7 @@ a discussion of:
35
35
1. Setting up pre-commit hooks and the pre-commit.ci bot to make using code
36
36
format tools in daily workflows and in pull requests on GitHub easier.
37
37
38
+
(code-style-tools)=
38
39
## Use a code format tool (or tools) to make your life easier
39
40
40
41
We suggest that you use a code format tool, or a set of format tools, because
@@ -57,18 +58,18 @@ the work out of manually implementing code format requirements.
57
58
Consistent code format across packages within the (scientific) Python ecosystem,
58
59
will also broadly make code easier to scan, understand and contribute to.
59
60
60
-
## Linting vs format and style
61
+
## Linting vs. format and style
61
62
62
63
Before we dive in let's get a few definitions out of the way.
63
64
64
-
### Code Linting
65
+
### Code linting
65
66
66
67
A code linter is a tool that will review your code and
67
68
identify errors or issues. A linter typically does not modify your code. It
68
69
will tell you what the error is and on what line it was discovered. Flake8,
69
70
discussed below, is an example of a commonly-used code linter.
70
71
71
-
### Code Formatters (and stylers)
72
+
### Code formatters (and stylers)
72
73
73
74
Code formatters will reformat your code for you. Python focused code formatters
74
75
often follow PEP 8 standards. However, they also make stylistic decisions about
@@ -82,6 +83,7 @@ You will learn more about Black below.
82
83
83
84
## Code linting, formatting and styling tools
84
85
86
+
(about-black)=
85
87
### Black
86
88
87
89
[Black](https://black.readthedocs.io/en/stable/) is a code
@@ -94,14 +96,15 @@ some exceptions. A few examples of those exceptions are below:
94
96
- Black will not adjust line length in your comments or docstrings.
95
97
- This tool will not review and fix import order (you need `isort` or `ruff` to do that - see below).
96
98
97
-
```{tip}
99
+
:::{tip}
98
100
If you are interested in seeing how Black will format your code, you can
99
101
use the [Black playground](https://black.vercel.app/)
100
-
```
102
+
:::
101
103
102
104
Using a code formatter like Black will leave you more time to work on
103
105
code function rather than worry about format.
104
106
107
+
(about-flake8)=
105
108
### Flake8
106
109
107
110
To adhere to Python `pep8` format standards, you might want to add
@@ -186,6 +189,7 @@ Python file `temporal.py` imports after `isort` has been run
186
189
:end-before: def calc_annual_mean
187
190
:::
188
191
192
+
(about-ruff)=
189
193
### Ruff
190
194
191
195
[Ruff](https://docs.astral.sh/ruff/) is a new addition to the code quality
@@ -272,13 +276,13 @@ on your the code files in your commit. It will update any files to match
272
276
black format standards. You can then retype the commit and push files to
273
277
GitHub that have been formatted by black. -->
274
278
275
-
```{important}
279
+
:::{important}
276
280
If have a Python code-base and multiple maintainers actively working
277
281
on the code, and you intend to run a tool like Black, be sure to coordinate across your team. An initial commit that
278
282
applies Black to your entire package will likely change a significant amount of
279
283
your code. This could lead to merge conflicts on open and new PR's before the
Copy file name to clipboardExpand all lines: package-structure-code/complex-python-package-builds.md
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,9 +3,11 @@
3
3
This guide is focused on packages that are either pure-python or that
4
4
have a few simple extensions in another language such as C or C++.
5
5
6
-
In the future, we want to provide resources for packaging workflows that require more complex builds. If you have questions about these types of package, please [add a question to our discourse](https://pyopensci.discourse.group/) or open an [issue about this guide specifically in the GitHub repo for this guide](https://github.com/pyOpenSci/python-package-guide/issues). There are many nuances to building and distributing Python packages that have compiled extensions requiring non-Python dependencies at build time. For an overview and thorough discussion of these nuances, please see [this site.](https://pypackaging-native.github.io/)
6
+
For comprehensive guidance on packaging compiled projects with C/C++/Fortran/Rust extensions, see the [Scientific Python Development Guide on compiled packaging](https://learn.scientific-python.org/development/guides/packaging-compiled/). This is the best reference for complex builds and covers scikit-build-core, meson-python, maturin, and other modern build backends.
7
7
8
-
## Pure Python Packages vs. packages with extensions in other languages
8
+
If you have questions about these types of package, please open an [issue about this guide specifically in the GitHub repo for this guide](https://github.com/pyOpenSci/python-package-guide/issues). There are many nuances to building and distributing Python packages that have compiled extensions requiring non-Python dependencies at build time. For an overview and thorough discussion of these nuances, please see [this site.](https://pypackaging-native.github.io/)
9
+
10
+
## Pure Python packages vs. packages with extensions in other languages
9
11
10
12
You can classify Python package complexity into three general categories. These
11
13
categories can in turn help you select the correct package frontend and
0 commit comments