Questions tagged [python-black]

Black is the uncompromising Python code formatter.

Black is the uncompromising Python code formatter.

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.

91 questions
1
vote
0 answers

Python Black package is not working when "black filename.py" is used in conda envvironment

I need to use python black (the code formatter), but seeing this issue for that I first moved to the git branch where I need to update environment with black package then activate the environment with conda activate my_env then I installed black…
0
votes
0 answers

VS Code setting for Python Black to automatically give arguments a new line when defining a function

Is there a setting in VS Code that automatically puts each argument in a function definition to a new line? I am using black, and if there are enough arguments that the line length is greater than 79 characters then each argument is given a new…
Anna
  • 29
  • 4
0
votes
1 answer

Bitbucket Pipeline automatic running black before the commit when pull request merged

I am trying to set up Bitbucket Pipeline to auto-format my python codebase. All I'm doing is running black. I'm working with distributed dev teams and it's hard to get everyone to install pre-commit hooks on their local machine so for now I just…
0
votes
0 answers

Ignore magic cells in jupytext percent formatted notebooks

My team uses a bigquery specific iPython magic command to query and return data from BigQuery: https://cloud.google.com/python/docs/reference/bigquery/latest/magics We also use jupytext to convert jupyter notebooks into percent formatted…
0
votes
1 answer

How to structure a nested "x if condition else y" so Black will leave it legible?

For a double nested x if condition else y it was legible before black got into the fray. It loses the nice indentations I had placed and now it's just a Wall of Code: clause = ( (f"{self.colname} " if self.colname else "") +…
WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560
0
votes
1 answer

Why does my python formatter add blank lines before and after function definitions?

My code is automatically formatted by the formatter, and it adds blank lines that I do not want. This happens while using both autopep8 and black. This is my code: dict_n = {} def new_dash(): new_list = input("do something ").split(",") for…
Babul 7154
  • 61
  • 2
  • 9
0
votes
1 answer

How can I enforce black's `--preview` option when invoking black with pre-commit?

I just found out that black's default behavior for long logfile messages does not enforce a maximum line length. I have verified that I can enforce max line length if I invoke black manually (v 23.1.0, in a Python 3.9.9 venv). Now I'd like to make…
Jeff Wright
  • 1,014
  • 1
  • 11
  • 17
0
votes
1 answer

Black make function arguments formatting without new lines around barackets

I'd like to format function argumetns in a way similar to the PyCharm default formatting - see image. Meaning no new line after '(' and before ) so it does NOT look like in the second image. It looks cleaner to me when function name is more…
0
votes
1 answer

Can I get the black python code format tool to recognize what directory my code is in

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…
Jon
  • 1,621
  • 5
  • 23
  • 46
0
votes
1 answer

How to merge lines previously broken by black due to violating the line length constraint when removing a few arguments?

Assume I have a single-line function call that exceeds black's line length constraint. Black will reformat this function call to a multi-line function call to satisfy the constraint, e.g., replace_config(user_args, tune_args, container_type,…
Matt
  • 796
  • 12
  • 25
0
votes
0 answers

Black is not honoring #fmt: skip

With below configuration in pyproject.toml : [tool.black] # How many characters per line to allow. line-length = 120 # When processing Jupyter Notebooks, add the given magic to the list of known # python-magics (timeit, prun, capture, pypy,…
0
votes
1 answer

Formatting python with Black in VSCode is causing arrays to expand vertically, any way to compress them?

I'm using Black to format python in VSCode, and it's making all my arrays super tall instead of wide. I've set max line length to 150 for pep8 and flake8 and black (but I'm new to Black, and not sure if it uses either of those…
brandonscript
  • 68,675
  • 32
  • 163
  • 220
0
votes
1 answer

black formatter won't be called when editing notebooks in VSCode

I am trying to enforce formatting on .ipynb files from VSCode. My settings.json looks like this: { "editor.formatOnSave": true, "python.formatting.provider": "black", "python.formatting.blackPath":…
wecx
  • 302
  • 2
  • 10
0
votes
0 answers

Cannot get Black to ignore a file

My IDE is VSCode. I have Black 22.8.0 set as Formatting Provider and IDE is set to format the code on save. This is the first time I apply a code formatter. This is my Django project structure: project |--- settings.py And this is my pyproject.toml…
Omid Shojaee
  • 333
  • 1
  • 4
  • 20
0
votes
1 answer

black's --include option not working in pre-commit to add Python files with non-standard naming

I am currently using black successfully as one of the tools in pre-commit. So far, it has only been applied to Python files with ".py" extensions, and default behaviour has sufficed. I would now like to extend black to some other files that in…
Bob
  • 195
  • 1
  • 11