-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e1c8ccc
Showing
192 changed files
with
28,006 additions
and
0 deletions.
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,27 @@ | ||
.venv | ||
.coverage | ||
.coverage.* | ||
_build | ||
.DS_Store | ||
.vscode | ||
docs/_static/pypi.svg | ||
.tox | ||
__pycache__ | ||
|
||
# Packaging artifacts | ||
pyink.egg-info | ||
pyink.dist-info | ||
build/ | ||
dist/ | ||
pip-wheel-metadata/ | ||
.eggs | ||
|
||
src/_pyink_version.py | ||
.idea | ||
|
||
.dmypy.json | ||
*.swp | ||
.hypothesis/ | ||
venv/ | ||
.ipynb_checkpoints/ | ||
|
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,11 @@ | ||
# Pyink Changelog | ||
|
||
All notable changes to Pyink are recorded here. | ||
|
||
## Unreleased | ||
|
||
Nothing notable unreleased. | ||
|
||
## 22.10.0 | ||
|
||
* Initial release based on _Black_ v22.10.0. |
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,26 @@ | ||
# How to Contribute | ||
|
||
## Community Guidelines | ||
|
||
This project follows | ||
[Google's Open Source Community Guidelines](https://opensource.google/conduct/). | ||
|
||
## Contributor License Agreement | ||
|
||
Contributions to this project must be accompanied by a Contributor License | ||
Agreement (CLA). You (or your employer) retain the copyright to your | ||
contribution; this simply gives us permission to use and redistribute your | ||
contributions as part of the project. Head over to | ||
<https://cla.developers.google.com/> to see your current agreements on file or | ||
to sign a new one. | ||
|
||
You generally only need to submit a CLA once, so if you've already submitted one | ||
(even if it was for a different project), you probably don't need to do it | ||
again. | ||
|
||
## Code Reviews | ||
|
||
All submissions, including submissions by project members, require review. We | ||
use GitHub pull requests for this purpose. Consult | ||
[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more | ||
information on using pull requests. |
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,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2018 Łukasz Langa | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,167 @@ | ||
*Pyink*, pronounced pī-ˈiŋk, is a Python formatter, forked from | ||
*[Black](https://github.com/psf/black)* with a few different formatting | ||
behaviors. We intend to keep rebasing on top of *Black*'s latest changes. | ||
|
||
# Why *Pyink*? | ||
|
||
We would love to adopt *Black*, but adopting it overnight is too disruptive to | ||
the thousands of developers working in our monorepo. We also have other Python | ||
tooling that assumes certain formatting, it would be a too big task to update | ||
them all at once. We decided to maintain a few local patches to *Black* as a | ||
medium-term solution, and release them as a separate tool called *Pyink*. | ||
|
||
*Pyink* is intended to be an adoption helper, and we wish to remove as many | ||
patches as possible in the future. | ||
|
||
# What are the main differences? | ||
|
||
* Support only formatting selected line ranges, using the `--pyink-lines=` | ||
argument (see [psf/black#830](https://github.com/psf/black/issues/830)). | ||
|
||
* Support two-space indentation, using the `pyink-indentation` option. | ||
|
||
* Support inferring preferred quote style by calculating the majority in a | ||
file, using the `pyink-use-majority-quotes` option. | ||
|
||
* Do not wrap trailing pragma comments if the line exceeds the length only | ||
because of the pragma (see | ||
[psf/black#2843](https://github.com/psf/black/issues/2843)). Example | ||
|
||
```python | ||
# Pyink: | ||
result = some_other_module._private_function(arg="value") # pylint: disable=protected-access | ||
|
||
# Black: | ||
result = some_other_module._private_function( | ||
arg="value" | ||
) # pylint: disable=protected-access | ||
``` | ||
|
||
* Do not wrap imports in parentheses and move them to separate lines (see | ||
[psf/black#3324](https://github.com/psf/black/issues/3324)). Example: | ||
|
||
```python | ||
# Pyink: | ||
from very_long_top_level_package_name.sub_package.another_level import a_long_module | ||
|
||
# Black: | ||
from very_long_top_level_package_name.sub_package.another_level import ( | ||
a_long_module, | ||
) | ||
``` | ||
|
||
* Prefer not breaking lines between immediately nested brackets (see | ||
[psf/black#1811](https://github.com/psf/black/issues/1811)). Example: | ||
|
||
```python | ||
# Pyink: | ||
secrets = frozenset({ | ||
1001, | ||
1002, | ||
1003, | ||
1004, | ||
1005, | ||
1006, | ||
1007, | ||
1008, | ||
1009, | ||
}) | ||
|
||
# Black: | ||
secrets = frozenset( | ||
{ | ||
1001, | ||
1002, | ||
1003, | ||
1004, | ||
1005, | ||
1006, | ||
1007, | ||
1008, | ||
1009, | ||
} | ||
) | ||
``` | ||
|
||
* Wrap concatenated strings in parens for function arguments (see | ||
[psf/black#3292](https://github.com/psf/black/issues/3292)). Example: | ||
|
||
```python | ||
# Pyink: | ||
function_call( | ||
( | ||
" lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor" | ||
" incididunt ut labore et dolore magna aliqua Ut enim ad minim" | ||
), | ||
" veniam quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo", | ||
) | ||
|
||
# Black: | ||
function_call( | ||
" lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor" | ||
" incididunt ut labore et dolore magna aliqua Ut enim ad minim", | ||
" veniam quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo", | ||
) | ||
``` | ||
|
||
* Add an empty line between class statements without docstrings, and the first | ||
method. We expect we will simply remove this difference from *Pyink* at some | ||
point. Example: | ||
|
||
```python | ||
# Pyink: | ||
class MyTest(unittest.TestCase): | ||
|
||
def test_magic(self): | ||
... | ||
|
||
# Black: | ||
class MyTest(unittest.TestCase): | ||
def test_magic(self): | ||
... | ||
``` | ||
|
||
# How do I use *Pyink*? | ||
|
||
Same as `black`, except you'll use `pyink`. All `black` command line options are | ||
supported by `pyink`. To configure the options in the `pyproject.toml` file, you | ||
need to put them in the `[tool.pyink]` section instead of `[tool.black]`. | ||
|
||
There are also a few *Pyink* only options: | ||
|
||
``` | ||
--pyink / --no-pyink Enable the Pyink formatting mode. Disabling | ||
it should behave the same as Black. | ||
[default: pyink] | ||
--pyink-indentation [2|4] The number of spaces used for indentation. | ||
[default: 4] | ||
--pyink-lines START-END Range of lines to format. Must be specified | ||
as "START-END", index is 1-based and | ||
inclusive on both ends. | ||
--pyink-use-majority-quotes When normalizing string quotes, infer | ||
preferred quote style by calculating the | ||
majority in the file. Multi-line strings and | ||
docstrings are excluded from this as they | ||
always use double quotes. | ||
``` | ||
|
||
# Why the name? | ||
|
||
We want a name with the same number of characters as *Black*, to make patching | ||
easier. And squid ink is black. | ||
|
||
# License | ||
|
||
[MIT](./LICENSE) | ||
|
||
# Contributing | ||
|
||
See the [contribution guide](./CONTRIBUTING.md). | ||
|
||
# Changelog | ||
|
||
See [CHANGES.md](./CHANGES.md). | ||
|
||
# Disclaimer | ||
|
||
This is not an officially supported Google product. |
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,101 @@ | ||
[tool.pyink] | ||
# Yes, we use the _Black_ style to format _Pyink_ code. | ||
pyink = false | ||
line-length = 88 | ||
target-version = ['py37', 'py38'] | ||
include = '\.pyi?$' | ||
extend-exclude = 'tests/data' | ||
preview = true | ||
|
||
[build-system] | ||
requires = ["hatchling>=1.8.0", "hatch-vcs"] | ||
build-backend = "hatchling.build" | ||
|
||
[project] | ||
name = "pyink" | ||
description = "Pyink is a python formatter, forked from Black with slightly different behavior." | ||
license = "MIT" | ||
requires-python = ">=3.7" | ||
readme = "README.md" | ||
authors = [{name = "The Pyink Maintainers", email = "[email protected]"}] | ||
classifiers = [ | ||
"Development Status :: 5 - Production/Stable", | ||
"Environment :: Console", | ||
"Intended Audience :: Developers", | ||
"License :: OSI Approved :: MIT License", | ||
"Operating System :: OS Independent", | ||
"Programming Language :: Python", | ||
"Programming Language :: Python :: 3 :: Only", | ||
"Programming Language :: Python :: 3.7", | ||
"Programming Language :: Python :: 3.8", | ||
"Programming Language :: Python :: 3.9", | ||
"Programming Language :: Python :: 3.10", | ||
"Programming Language :: Python :: 3.11", | ||
"Topic :: Software Development :: Libraries :: Python Modules", | ||
"Topic :: Software Development :: Quality Assurance", | ||
] | ||
dependencies = [ | ||
"click>=8.0.0", | ||
"mypy_extensions>=0.4.3", | ||
"pathspec>=0.9.0", | ||
"platformdirs>=2", | ||
"tomli>=1.1.0; python_full_version < '3.11.0a7'", | ||
"typed-ast>=1.4.2; python_version < '3.8' and implementation_name == 'cpython'", | ||
"typing_extensions>=3.10.0.0; python_version < '3.10'", | ||
"black>=22.10.0", | ||
] | ||
dynamic = ["version"] | ||
|
||
[project.optional-dependencies] | ||
colorama = ["colorama>=0.4.3"] | ||
uvloop = ["uvloop>=0.15.2"] | ||
jupyter = [ | ||
"ipython>=7.8.0", | ||
"tokenize-rt>=3.2.0", | ||
] | ||
|
||
[project.scripts] | ||
pyink = "pyink:patched_main" | ||
|
||
[project.urls] | ||
Changelog = "https://github.com/google/pyink/blob/main/CHANGES.md" | ||
Homepage = "https://github.com/google/pyink" | ||
|
||
[tool.hatch.version] | ||
source = "vcs" | ||
|
||
[tool.hatch.build.hooks.vcs] | ||
version-file = "src/_pyink_version.py" | ||
template = ''' | ||
version = "{version}" | ||
''' | ||
|
||
[tool.hatch.build.targets.wheel] | ||
only-include = ["src"] | ||
sources = ["src"] | ||
|
||
[tool.pytest.ini_options] | ||
# Option below requires `tests/optional.py` | ||
addopts = "--strict-config --strict-markers" | ||
optional-tests = [ | ||
"no_jupyter: run when `jupyter` extra NOT installed", | ||
] | ||
markers = [ | ||
"incompatible_with_mypyc: run when testing mypyc compiled black" | ||
] | ||
xfail_strict = true | ||
filterwarnings = [ | ||
"error", | ||
# this is mitigated by a try/catch in https://github.com/psf/black/pull/2974/ | ||
# this ignore can be removed when support for aiohttp 3.7 is dropped. | ||
'''ignore:Decorator `@unittest_run_loop` is no longer needed in aiohttp 3\.8\+:DeprecationWarning''', | ||
# this is mitigated by a try/catch in https://github.com/psf/black/pull/3198/ | ||
# this ignore can be removed when support for aiohttp 3.x is dropped. | ||
'''ignore:Middleware decorator is deprecated since 4\.0 and its behaviour is default, you can simply remove this decorator:DeprecationWarning''', | ||
# this is mitigated by https://github.com/python/cpython/issues/79071 in python 3.8+ | ||
# this ignore can be removed when support for 3.7 is dropped. | ||
'''ignore:Bare functions are deprecated, use async ones:DeprecationWarning''', | ||
# aiohttp is using deprecated cgi modules - Safe to remove when fixed: | ||
# https://github.com/aio-libs/aiohttp/issues/6905 | ||
'''ignore:'cgi' is deprecated and slated for removal in Python 3.13:DeprecationWarning''', | ||
] |
Oops, something went wrong.