I am trying to integrate the black python code formatting tool into my workflow. As a test I have created a directory with the following structure.
hello
|_ pyproject.toml
|_ hello
|_main.py
The pyproject.toml file has the following information in it.
[tool.poetry]
name = "hello"
version = "0.1.0"
description = ""
authors = ["my Name <name@gmail.com>"]
readme = "README.rst"
[tool.poetry.dependencies]
python = "^3.10"
[tool.poetry.group.dev.dependencies]
pytest = "^7.2.1"
flake8 = "^6.0.0"
mypy = "^1.0.0"
black = "^23.1.0"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
classifiers = [
"Development Status :: 4 - Beta",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"License :: OSI Approved :: MIT License",
"Operating System :: MacOS",
"Operating System :: POSIX :: Linux",
]
[tool.black]
line-length = 90
target-version = ['py38', 'py39', 'py310']
include = ['\.pyi?$', 'hello']
exclude = '''
/(
\.eggs
| \.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| _build
| buck-out
| build
| dist
# The following are specific to Black, you probably don't want those.
| blib2to3
| tests/data
| profiling
)/
'''
As you can see, I include the name of my source code directory, hello
in the include
line. From the uppermost hello
durectory, if I type black hello
it will look into the lowermost hello
directory and format any code in that directory. If I cd
to the lowermost hello
directory and type black
or black main.py
it will format the main.py
code. However, is there a way to use the pyproject.toml
file to tell black where my source code is, such that from the upper most hello
directory I can just type black
and it will look into the lowermost hello
directory without me explicitly pointing it there from command line.
Presently when I type black
from the uppermost hello
directory I get the message Usage of black [OPTIONS] SRC ... One of 'SRC' or 'code' is required