-
Notifications
You must be signed in to change notification settings - Fork 4
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
chore: add overview of code quality tools; format code with black (DEV-2224) #391
Merged
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
2eaeac6
add black, remove isort, set line length = 120
jnussbaum fb68c26
Merge branch 'main' into wip/dev-2224-black
jnussbaum 27151c6
start
jnussbaum 2d6c764
second run
jnussbaum e0a6886
third run
jnussbaum 51728f1
format some test files
jnussbaum a90b432
format rest of tests
jnussbaum 1842ff8
reformat models
jnussbaum 55db11a
second run
jnussbaum 78d3007
update import_scripts
jnussbaum c7a7566
update submodule
jnussbaum 3e552d6
fix unittests
jnussbaum ee4531a
resolve too long lines in src
jnussbaum 9659eb2
resolve pylint errors
jnussbaum 823c8da
update submodule
jnussbaum 4165d1a
Merge branch 'main' into wip/dev-2224-black
jnussbaum 82ee812
fix test
jnussbaum ae5ac57
move black to dev dependencies
jnussbaum b8ebc52
edit
jnussbaum 5b461af
reformat readme
jnussbaum e266ca0
edit
jnussbaum 68f76a3
edit
jnussbaum 1dcecf0
remove unused pyright: ignore comments
jnussbaum 436cc30
edit
jnussbaum e2ac6b5
reformat
jnussbaum f60db0f
edit
jnussbaum a5f2bc0
edit
jnussbaum ebd5af7
Merge branch 'main' into wip/dev-2224-black
jnussbaum e7f394b
split into subpages
jnussbaum a9e8653
tidy up
jnussbaum ac38fb0
edit
jnussbaum ab0eb0b
edit
jnussbaum 1869689
edit
jnussbaum 0359b69
fix link
jnussbaum 54f1a9e
Merge branch 'main' into wip/dev-2224-black
jnussbaum cb70d58
blacken merge commit
jnussbaum File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
# https://EditorConfig.org | ||
|
||
# Unix-style newlines with a newline ending every file | ||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
|
||
# 4 space indentation | ||
[*.py] | ||
indent_style = space | ||
indent_size = 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
[![PyPI version](https://badge.fury.io/py/dsp-tools.svg)](https://badge.fury.io/py/dsp-tools) | ||
|
||
# Code quality tools | ||
|
||
There is a variety of tools that help to keep the code quality high. | ||
|
||
DSP-TOOLS uses the ones listed on this page. | ||
|
||
The decision to use this set of tools is based on the information in the following pages. | ||
|
||
|
||
| Task | Tool | Configuration | | ||
| --------------------------------------------------------------- | ------------------------------------------------------------------ | ------------------------ | | ||
| [General formatting](./general-formatting.md) | [EditorConfig](https://EditorConfig.org/) | `.editorconfig` | | ||
| | [markdownlint](https://github.com/igorshubovych/markdownlint-cli/) | `.markdownlint.yml` | | ||
| [Python formatting](./python-formatting.md) | [Black](https://pypi.org/project/black/) | `pyproject.toml` | | ||
| [Python docstring formatting](./python-docstring-formatting.md) | [pydocstyle](https://pypi.org/project/pydocstyle/) * | | | ||
| [Python type checking](./python-type-checking.md) | [Mypy](https://pypi.org/project/mypy/) | `pyproject.toml` | | ||
| [Python linting](./python-linting.md) | [Ruff](https://pypi.org/project/ruff/) * | | | ||
| | [Pylint](https://pypi.org/project/pylint/) ** | `pyproject.toml` | | ||
| [Security checks](./security.md) | [Dependabot](https://docs.github.com/en/code-security/dependabot/) | `.github/dependabot.yml` | | ||
| | [CodeQL](https://codeql.github.com/) | GitHub settings | | ||
| | [Gitleaks](https://gitleaks.io/) * | `.gitleaks.toml` | | ||
| | [Bandit](https://pypi.org/project/bandit/) * | `pyproject.toml` | | ||
|
||
(*) coming soon | ||
|
||
(**) will perhaps become redundant, as Ruff matures |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[![PyPI version](https://badge.fury.io/py/dsp-tools.svg)](https://badge.fury.io/py/dsp-tools) | ||
|
||
# General formatting | ||
|
||
## [EditorConfig](https://EditorConfig.org) | ||
|
||
Language-independent, cross-editor settings for indentation, line endings, etc. | ||
|
||
## [markdownlint](https://github.com/igorshubovych/markdownlint-cli) | ||
|
||
A CLI for David Anson's markdownlint, a static analysis tool with a library of rules. | ||
The flexibility of the markdown syntax is both a benefit and a drawback. | ||
Many styles are possible, so formatting can be inconsistent. | ||
Some constructs don't work well in all parsers and should be avoided. |
74 changes: 74 additions & 0 deletions
74
docs/developers/code-quality-tools/python-docstring-formatting.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
[![PyPI version](https://badge.fury.io/py/dsp-tools.svg)](https://badge.fury.io/py/dsp-tools) | ||
|
||
# Python Docstring formatting | ||
|
||
## Docstring flavors | ||
|
||
Python uses docstrings to document code. | ||
A docstring is a string that is the first statement in a package, module, class or function. | ||
Python docsrings are written in the | ||
[reStructuredText](https://docutils.sourceforge.io/rst.html) syntax (abbreviated as RST or reST). | ||
|
||
There are at least 4 flavors of docstrings, | ||
each following the [PEP 257](http://www.python.org/dev/peps/pep-0257/) conventions. | ||
The following examples show how to document a function parameter: | ||
|
||
Epytext: | ||
|
||
```pydocstring | ||
@type param1: int | ||
@param param1: The first parameter | ||
``` | ||
|
||
Sphinx: | ||
|
||
```pydocstring | ||
:param param1: The first parameter | ||
:type: int | ||
``` | ||
|
||
Google: | ||
|
||
```pydocstring | ||
Args: | ||
param1 (int): The first parameter | ||
``` | ||
|
||
NumPy: | ||
|
||
```pydocstring | ||
Parameters | ||
---------- | ||
param1 : int | ||
The first parameter | ||
``` | ||
|
||
DSP-TOOLS uses the Google style without typing, | ||
as defined [here](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings). | ||
|
||
|
||
## Existing formatters | ||
|
||
### [pydocstyle](https://pypi.org/project/pydocstyle/) | ||
|
||
Static analysis tool for checking compliance with Python docstring conventions. | ||
Pydocstyle supports most of [PEP 257](http://www.python.org/dev/peps/pep-0257/) out of the box, | ||
but it should not be considered a reference implementation. | ||
Pydocstyle seems to be the most popular docstring checker. | ||
It supports the styles "pep257", "numpy", and "google". | ||
|
||
### [pydocstringformatter](https://pypi.org/project/pydocstringformatter/) | ||
|
||
A docstring formatter that follows | ||
[PEP 8](http://www.python.org/dev/peps/pep-0008/) and [PEP 257](http://www.python.org/dev/peps/pep-0257/) | ||
but makes some of the more controversial elements of the PEPs optional. | ||
Can be configured for other styles as well. | ||
This project is heavily inspired by docformatter. | ||
Supported styles: "pep257", "numpy". | ||
|
||
### [docformatter](https://pypi.org/project/docformatter/) | ||
|
||
Automatically formats docstrings to follow a subset of | ||
the [PEP 257](http://www.python.org/dev/peps/pep-0257/) conventions. | ||
Currently, only the style "sphinx" and "epytext" are recognized, | ||
but "numpy" and "google" are future styles. |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again, this should not be in our documentation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
[![PyPI version](https://badge.fury.io/py/dsp-tools.svg)](https://badge.fury.io/py/dsp-tools) | ||
|
||
# Python formatting | ||
|
||
There is a variety of style checkers (tools that give a feedback) | ||
and autoformatters (tools that are able to fix the formatting violations automatically). | ||
|
||
## Existing type checkers and autoformatters | ||
|
||
### [pycodestyle](https://pypi.org/project/pycodestyle/) | ||
|
||
Checks Python code against some of the style conventions in [PEP 8](http://www.python.org/dev/peps/pep-0008/). | ||
|
||
### [autopep8](https://pypi.org/project/autopep8/) | ||
|
||
Automatically fixes most of the formatting issues reported by pycodestyle. | ||
Since PEP 8 is rather liberal, autopep8/pycodestyle don't modify code too much. | ||
|
||
### [black](https://pypi.org/project/black/) | ||
|
||
A PEP 8 compliant opinionated autoformatter with its own style, going further than autopep8/pycodestyle. | ||
Style configuration options are deliberately limited to a minimum. | ||
Black aims for readability and reducing git diffs. | ||
Black is an easy to use tool, with sensible and useful defaults. | ||
Its style is very elegant. | ||
|
||
### [yapf](https://pypi.org/project/yapf/) | ||
|
||
Autoformatter that can be configured to support different styles. | ||
|
||
### [isort](https://pypi.org/project/isort/) | ||
|
||
Sorts imports alphabetically, and separates them into sections, according to their type. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this should exist in our documentation. It makes sense to note somewhere, which style we follow; but this seems way out of scope of what we should have in our documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see your point. For me personally, it was important to make all these notes, and to store them somewhere where they can be accessed, and reevaluated. When the ecosystem will have changed in some years, and we don't have these notes, then it will be more difficult to assess if our choice of tools is still okay.
In my view, these notes make our choice more transparent.
And I would never have put these notes into the user part of the documentation. If they belong somewhere, then here in the developers/ADR section.
Writing this, the idea comes to my mind to move them to my personal github.io page. This would allow me to keep them stored somewhere, and to reference them, without cluttering the dsp-tools docs. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't recommend mixing private and work stuff too much... but that's up to you. However if it's on your personal page, you shouldn't expect other team members to search for it there.
To me, the most intuitive place for this kind of internal note-keeping would be Notion, as it is our "internal Wiki".
But at the end of the day, it really doesn't matter too much; and you can also just leave it in the docs.