Go to file
temeddix 3759b856af
Solved Problem with Non-ASCII .gitignore Files (#2229)
* Solved Problem with non-alphabetical .gitignore files

When .gitignore file in the user's project directory contained non-alphabetical
characters(Japanese, Korean, Chinese, etc), Nothing works and printed this
weird message in the console('cp949' is the encoding for Korean characters
in this case). It even blocks VSCode's formatting from working. This commit
solves the problem.

Traceback (most recent call last):
  File "c:\users\username\anaconda3\envs\project-name\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\username\anaconda3\envs\project-name\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\username\anaconda3\envs\project-name\Scripts\black.exe\__main__.py", line 7, in <module>
  File "c:\users\username\anaconda3\envs\project-name\lib\site-packages\black\__init__.py", line 1056, in patched_main      
    main()
  File "c:\users\username\anaconda3\envs\project-name\lib\site-packages\click\core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "c:\users\username\anaconda3\envs\project-name\lib\site-packages\click\core.py", line 782, in main
    rv = self.invoke(ctx)
  File "c:\users\username\anaconda3\envs\project-name\lib\site-packages\click\core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "c:\users\username\anaconda3\envs\project-name\lib\site-packages\click\core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "c:\users\username\anaconda3\envs\project-name\lib\site-packages\click\decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "c:\users\username\anaconda3\envs\project-name\lib\site-packages\black\__init__.py", line 394, in main
    stdin_filename=stdin_filename,
  File "c:\users\username\anaconda3\envs\project-name\lib\site-packages\black\__init__.py", line 445, in get_sources        
    gitignore = get_gitignore(root)
  File "c:\users\username\anaconda3\envs\project-name\lib\site-packages\black\files.py", line 122, in get_gitignore
    lines = gf.readlines()
UnicodeDecodeError: 'cp949' codec can't decode byte 0xb0 in position 13: illegal multibyte sequence

* Made .gitignore File Reader Detect Its Encoding
* Revert "Made .gitignore File Reader Detect Its Encoding"

  This reverts commit 6c3a7ea42b5b1e441cc0026c8205d1cee68c1bba.

* Revert "Solved Problem with non-alphabetical .gitignore files"

  This reverts commit b0100b5d91c2f5db544a60f34aafab120f0aa458.

* Made .gitignore Reader Open the File with Auto Encoding Detecting

  https://docs.python.org/3.8/library/tokenize.html#tokenize.open

* Revert "Made .gitignore Reader Open the File with Auto Encoding Detecting"

  This reverts commit 50dd80422938649ccc8c7f43aac752f9f6481779.

* Made .gitignore Reader Use UTF-8
* Updated CHANGES.md for #2229
* Updated CHANGES.md for #2229
* Update CHANGES.md
* Update CHANGES.md

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Co-authored-by: Richard Si <63936253+ichard26@users.noreply.github.com>
2021-05-23 22:19:03 -04:00
.github Build macOS releases (#2198) 2021-05-23 18:59:03 -07:00
action Fix broken Action entrypoint (#2202) 2021-05-06 12:21:13 -07:00
autoload Use vim autoload script (#1157) 2021-03-07 16:13:25 -08:00
docs Link isort profile to Black code style isort mention (#2246) 2021-05-19 15:11:37 -04:00
gallery Replace references to master branch (#2210) 2021-05-09 17:50:17 -04:00
plugin Use vim autoload script (#1157) 2021-03-07 16:13:25 -08:00
profiling Move profiling data out of tests/data 2018-06-09 15:48:41 -07:00
src Solved Problem with Non-ASCII .gitignore Files (#2229) 2021-05-23 22:19:03 -04:00
tests Fix: black only respects the root gitignore. (#2225) 2021-05-16 13:51:27 -04:00
.coveragerc Speed up test suite via distributed testing (#2196) 2021-05-07 16:41:55 +02:00
.flake8 Remove useless flake8 config + test support code (#2221) 2021-05-11 14:09:33 -04:00
.gitignore Re-add .venv to .gitignore 2021-04-25 19:42:02 +02:00
.pre-commit-config.yaml Make Prettier preserve line ending type (#2244) 2021-05-17 14:38:43 -04:00
.pre-commit-hooks.yaml Bump minimum_pre_commit_version per recommendation (#1895) 2020-12-31 11:10:18 -08:00
.prettierrc.yaml Make Prettier preserve line ending type (#2244) 2021-05-17 14:38:43 -04:00
.readthedocs.yaml Autogenerate black(d|-primer)? help in usage docs (#2212) 2021-05-09 19:35:56 -07:00
action.yml Simplify GitHub Action entrypoint (#2119) 2021-05-05 22:25:43 -04:00
AUTHORS.md Reorganize docs v2 (GH-2174) 2021-05-08 15:17:38 -04:00
CHANGES.md Solved Problem with Non-ASCII .gitignore Files (#2229) 2021-05-23 22:19:03 -04:00
CONTRIBUTING.md Reorganize docs v2 (GH-2174) 2021-05-08 15:17:38 -04:00
Dockerfile Add black Dockerfile (#1916) 2021-04-07 21:13:11 -07:00
fuzz.py Fuzzer testing: less strict special-case regex match passthrough for multi-line EOF exceptions (#1998) 2021-02-22 07:49:38 -08:00
LICENSE Initial commit 2018-03-14 12:55:32 -07:00
mypy.ini Click 8.0 renamed its "die on LANG=C" function so we need to look for that one too (#2227) 2021-05-12 21:47:32 +02:00
Pipfile Add issue triage documentation (#2236) 2021-05-16 18:07:27 +02:00
Pipfile.lock Add issue triage documentation (#2236) 2021-05-16 18:07:27 +02:00
pyproject.toml Mark blackd tests with the blackd optional marker (#2204) 2021-05-07 16:33:36 +02:00
README.md Replace references to master branch (#2210) 2021-05-09 17:50:17 -04:00
setup.cfg Move to 'py3' tagged wheels (#1388) 2020-05-08 05:49:51 -07:00
setup.py Add lower bound for aiohttp-cors + fix primer (#2231) 2021-05-13 12:30:34 -07:00
test_requirements.txt Speed up test suite via distributed testing (#2196) 2021-05-07 16:41:55 +02:00
tox.ini Speed up test suite via distributed testing (#2196) 2021-05-07 16:41:55 +02:00

Black Logo

The Uncompromising Code Formatter

Actions Status Actions Status Documentation Status Coverage Status License: MIT PyPI Downloads conda-forge Code style: black

“Any color you like.”

Black is the uncompromising Python code formatter. By using it, you agree to cede control over minutiae of hand-formatting. In return, Black gives you speed, determinism, and freedom from pycodestyle nagging about formatting. You will save time and mental energy for more important matters.

Blackened code looks the same regardless of the project you're reading. Formatting becomes transparent after a while and you can focus on the content instead.

Black makes code review faster by producing the smallest diffs possible.

Try it out now using the Black Playground. Watch the PyCon 2019 talk to learn more.


Read the documentation on ReadTheDocs!


Installation and usage

Installation

Black can be installed by running pip install black. It requires Python 3.6.2+ to run. If you want to format Python 2 code as well, install with pip install black[python2].

If you can't wait for the latest hotness and want to install from GitHub, use:

pip install git+git://github.com/psf/black

Usage

To get started right away with sensible defaults:

black {source_file_or_directory}

You can run Black as a package if running it as a script doesn't work:

python -m black {source_file_or_directory}

Further information can be found in our docs:

NOTE: This is a beta product

Black is already successfully used by many projects, small and big. Black has a comprehensive test suite, with efficient parallel tests, and our own auto formatting and parallel Continuous Integration runner. However, Black is still beta. Things will probably be wonky for a while. This is made explicit by the "Beta" trove classifier, as well as by the "b" in the version number. What this means for you is that until the formatter becomes stable, you should expect some formatting to change in the future. That being said, no drastic stylistic changes are planned, mostly responses to bug reports.

Also, as a safety measure which slows down processing, Black will check that the reformatted code still produces a valid AST that is effectively equivalent to the original (see the Pragmatism section for details). If you're feeling confident, use --fast.

The Black code style

Black is a PEP 8 compliant opinionated formatter. Black reformats entire files in place. Style configuration options are deliberately limited and rarely added. It doesn't take previous formatting into account (see Pragmatism for exceptions).

Our documentation covers the current Black code style, but planned changes to it are also documented. They're both worth taking a look:

Please refer to this document before submitting an issue. What seems like a bug might be intended behaviour.

Pragmatism

Early versions of Black used to be absolutist in some respects. They took after its initial author. This was fine at the time as it made the implementation simpler and there were not many users anyway. Not many edge cases were reported. As a mature tool, Black does make some exceptions to rules it otherwise holds.

Please refer to this document before submitting an issue just like with the document above. What seems like a bug might be intended behaviour.

Configuration

Black is able to read project-specific default values for its command line options from a pyproject.toml file. This is especially useful for specifying custom --include and --exclude/--force-exclude/--extend-exclude patterns for your project.

You can find more details in our documentation:

And if you're looking for more general configuration documentation:

Pro-tip: If you're asking yourself "Do I need to configure anything?" the answer is "No". Black is all about sensible defaults. Applying those defaults will have your code in compliance with many other Black formatted projects.

Used by

The following notable open-source projects trust Black with enforcing a consistent code style: pytest, tox, Pyramid, Django Channels, Hypothesis, attrs, SQLAlchemy, Poetry, PyPA applications (Warehouse, Bandersnatch, Pipenv, virtualenv), pandas, Pillow, every Datadog Agent Integration, Home Assistant, Zulip.

The following organizations use Black: Facebook, Dropbox, Mozilla, Quora.

Are we missing anyone? Let us know.

Testimonials

Dusty Phillips, writer:

Black is opinionated so you don't have to be.

Hynek Schlawack, creator of attrs, core developer of Twisted and CPython:

An auto-formatter that doesn't suck is all I want for Xmas!

Carl Meyer, Django core developer:

At least the name is good.

Kenneth Reitz, creator of requests and pipenv:

This vastly improves the formatting of our code. Thanks a ton!

Show your style

Use the badge in your project's README.md:

[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

Using the badge in README.rst:

.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
    :target: https://github.com/psf/black

Looks like this: Code style: black

License

MIT

Contributing

Welcome! Happy to see you willing to make the project better. You can get started by reading this:

You can also take a look at the rest of the contributing docs or talk with the developers:

Change log

The log has become rather long. It moved to its own file.

See CHANGES.

Authors

The author list is quite long nowadays, so it lives in its own file.

See AUTHORS.md

Code of Conduct

Everyone participating in the Black project, and in particular in the issue tracker, pull requests, and social media activity, is expected to treat other people with respect and more generally to follow the guidelines articulated in the Python Community Code of Conduct.

At the same time, humor is encouraged. In fact, basic familiarity with Monty Python's Flying Circus is expected. We are not savages.

And if you really need to slap somebody, do it with a fish while dancing.