Black for Databricks notebooks
Project description
Blackbricks
A formatting tool for your Databricks notebooks.
Table of Contents
Installation and Usage
Install:
$ pip install blackbricks
Usage:
$ blackbricks --help
Usage: blackbricks [OPTIONS] [FILENAMES]...
Formatting tool for Databricks python notebooks.
Python cells are formatted using `black`, and SQL cells are formatted by
`sqlparse`.
Arguments:
[FILENAMES]... Path to the notebook(s) to format.
Options:
--line-length INTEGER How many characters per line to allow.
[default: 88]
--sql-upper SQL keywords should be UPPERCASE. [default: True]
--sql-lower SQL keywords should be lowercase. [default: False]
--check Don't write the files back, just return the
status. Return code 0 means nothing would
change.
--diff Don't write the files back, just output a
diff for each file on stdout.
--indent-with-two-spaces / --no-indent-with-two-spaces
Use two spaces for indentation in Python
cells instead of Black's default of four.
Databricks uses two spaces. [default: True]
--version Display version information and exit.
--help Show this message and exit.
Version control integration
Use pre-commit. Add a
.pre-commit-config.yaml
file to your repo with the following content (changing/removing the args
as you wish):
repos:
- repo: https://github.com/bsamseth/blackbricks
rev: 0.4.0
hooks:
- id: blackbricks
args: [--line-length=120, --indent-with-two-spaces]
Set the rev
attribute to the most recent version of blackbricks
.
The args
are optional and can be used to set any of blackbricks
options.
Contributing
If you find blackbricks useful or utterly broken, you are more than welcome to contribute improvements. Please open an issue first to discuss what you want added/fixed. Unless you are just adding tests. In that case your pull request is extremely likely to be merged right away.
FAQ
How do I use blackbricks
on my Databricks notebooks?
blackbricks
is a command line program, meant to be used on files stored locally. Databricks provides no direct way to run tools on notebooks from within the notebook interface in your browser.
The suggested way to use this is togheter with Git.
- Sync your notebooks to a remote repository (through the "revision history" tab in the top right)
- Clone the repo locally
- Run
blackbricks
on the desired notebook files from a terminal - Commit the newly formatted notebooks and push to your remote repo.
- Sync your notebook again to pick up the new changes.
Is there a more streamlined way to do it?
I'm considering adding an option to modify the Databricks notebooks directly (thorugh an additional commandline option). Something like
blackbricks --remote username:path/to/file # Not possible (yet).
Click here to indicate interest, and enable watching this repo for new releases:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for blackbricks-0.4.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f87d9f81e7b73cd054ff9ad39b43a9187a40f858b59b4c6c84b87d83183e4de |
|
MD5 | 7113242e4020830a61d945e5f89e9177 |
|
BLAKE2b-256 | 4564e732eb20794dc5f1111854df95808ca2d895f000c2260a000f2ee3b8602b |