This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add info about black to code_style.rst #5537
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4382366
Add info about black to code_style.rst
anoadragon453 0d41f6a
Add changelog
anoadragon453 b4f5c3f
rewrite code_style.rst a bit
anoadragon453 f8238a0
Correct example code and remove old sections
anoadragon453 9d6c16e
no, they will not
anoadragon453 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
Add information about how to install and run `black` on the codebase to code_style.rst. |
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,5 +1,62 @@ | ||||||
- Everything should comply with PEP8. Code should pass | ||||||
``pep8 --max-line-length=100`` without any warnings. | ||||||
# Code Style | ||||||
|
||||||
The Synapse codebase uses a number of code formatting tools in order to | ||||||
quickly and automatically check for formatting (and sometimes logical) errors | ||||||
in code. | ||||||
|
||||||
The necessary tools are detailed below. | ||||||
|
||||||
## Formatting tools | ||||||
|
||||||
The Synapse codebase uses [black](https://pypi.org/project/black/) as an | ||||||
opinionated code formatter, ensuring all comitted code is properly | ||||||
formatted. | ||||||
|
||||||
First install ``black`` with:: | ||||||
|
||||||
pip install --upgrade black | ||||||
|
||||||
Have ``black`` auto-format your code (it shouldn't change any | ||||||
functionality) with:: | ||||||
|
||||||
black --check . --exclude="\.tox|build|env" | ||||||
|
||||||
- **flake8** | ||||||
|
||||||
``flake8`` is a code checking tool. We require code to pass ``flake8`` before being merged into the codebase. | ||||||
|
||||||
Install ``flake8`` with:: | ||||||
|
||||||
pip install --upgrade flake8 | ||||||
|
||||||
Check all application and test code with:: | ||||||
|
||||||
flake 8 synapse tests | ||||||
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.
Suggested change
|
||||||
|
||||||
- **isort** | ||||||
|
||||||
``isort`` ensures imports are nicely formatted, and can suggest and | ||||||
auto-fix issues such as double-importing. | ||||||
|
||||||
Install ``isort`` with:: | ||||||
|
||||||
pip install --upgrade isort | ||||||
|
||||||
Auto-fix imports with:: | ||||||
|
||||||
isort -rc synapse tests | ||||||
|
||||||
``-rc`` means to recursively search the given directories. | ||||||
|
||||||
It's worth noting that modern IDEs and text editors can run these tools | ||||||
automatically on save. It may be worth looking into whether this | ||||||
functionality is supported in your editor for a more convenient development | ||||||
workflow. It is not, however, recommended to run ``flake8`` on save as it | ||||||
takes a while and is very resource intensive. | ||||||
|
||||||
## General rules | ||||||
|
||||||
These rules are useful to keep in mind while programming, but be aware that the above tools will handle most of this for you | ||||||
richvdh marked this conversation as resolved.
Show resolved
Hide resolved
anoadragon453 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
- **Indenting**: | ||||||
|
||||||
|
@@ -32,9 +89,7 @@ | |||||
|
||||||
- **Line length**: | ||||||
|
||||||
Max line length is 79 chars (with flexibility to overflow by a "few chars" if | ||||||
the overflowing content is not semantically significant and avoids an | ||||||
explosion of vertical whitespace). | ||||||
Max line length is 90 chars. | ||||||
|
||||||
Use parentheses instead of ``\`` for line continuation where ever possible | ||||||
(which is pretty much everywhere). | ||||||
|
@@ -76,7 +131,7 @@ | |||||
|
||||||
- **Imports**: | ||||||
|
||||||
- Prefer to import classes and functions than packages or modules. | ||||||
- Prefer to import classes and functions rather than packages or modules. | ||||||
|
||||||
Example:: | ||||||
|
||||||
|
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.
doesn't --check just tell you if it's wrong, rather than formatting it for you?