]> git.madduck.net Git - etc/vim.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Add option to format Jupyter Notebooks in GitHub Action (#3282)
authorAntonio Ossa-Guerra <aaossa@uc.cl>
Mon, 26 Sep 2022 21:45:34 +0000 (18:45 -0300)
committerGitHub <noreply@github.com>
Mon, 26 Sep 2022 21:45:34 +0000 (17:45 -0400)
To run the formatter on Jupyter Notebooks, Black must be installed
with an extra dependency (`black[jupyter]`). This commit adds an
optional argument to install Black with this dependency when using the
official GitHub Action [1]. To enable the formatter on Jupyter
Notebooks, just add `jupyter: true` as an argument. Feature requested
at [2].

[1]: https://black.readthedocs.io/en/stable/integrations/github_actions.html
[2]: https://github.com/psf/black/issues/3280

Signed-off-by: Antonio Ossa Guerra <aaossa@uc.cl>
AUTHORS.md
CHANGES.md
action.yml
action/main.py
docs/integrations/github_actions.md

index 533606240d3d1ff313956147087b7e74977821ca..f2d599dd8780ca755bec01d2967266ac6912ffd2 100644 (file)
@@ -29,6 +29,7 @@ Multiple contributions by:
 - [Andrey](mailto:dyuuus@yandex.ru)
 - [Andy Freeland](mailto:andy@andyfreeland.net)
 - [Anthony Sottile](mailto:asottile@umich.edu)
+- [Antonio Ossa Guerra](mailto:aaossa+black@uc.cl)
 - [Arjaan Buijk](mailto:arjaan.buijk@gmail.com)
 - [Arnav Borbornah](mailto:arnavborborah11@gmail.com)
 - [Artem Malyshev](mailto:proofit404@gmail.com)
index 6fb099040b304c94bac93a75288951d432e2e622..c96d9a6e49259b133169fd33b92961bbc9c5efc2 100644 (file)
@@ -58,6 +58,8 @@
 
 <!-- For example, Docker, GitHub Actions, pre-commit, editors -->
 
+- Update GitHub Action to support formatting of Jupyter Notebook files via a `jupyter`
+  option (#3282)
 - Update GitHub Action to support use of version specifiers (e.g. `<23`) for Black
   version (#3265)
 
index cfa6ef9fb7e41b48ad436283efab35c157771255..35705e994146eb8fbb0ca12ad59a9cca52d46f47 100644 (file)
@@ -12,6 +12,11 @@ inputs:
     description: "Source to run Black. Default: '.'"
     required: false
     default: "."
+  jupyter:
+    description:
+      "Set this option to true to include Jupyter Notebook files. Default: false"
+    required: false
+    default: false
   black_args:
     description: "[DEPRECATED] Black input arguments."
     required: false
@@ -38,6 +43,7 @@ runs:
         # TODO: Remove once https://github.com/actions/runner/issues/665 is fixed.
         INPUT_OPTIONS: ${{ inputs.options }}
         INPUT_SRC: ${{ inputs.src }}
+        INPUT_JUPYTER: ${{ inputs.jupyter }}
         INPUT_BLACK_ARGS: ${{ inputs.black_args }}
         INPUT_VERSION: ${{ inputs.version }}
         pythonioencoding: utf-8
index 03228cb13e8134ffbcbd439d9dc37906daa45e27..ff9d4112aed7f19f14930284ef38ee6134a8bc05 100644 (file)
@@ -9,6 +9,7 @@ ENV_PATH = ACTION_PATH / ".black-env"
 ENV_BIN = ENV_PATH / ("Scripts" if sys.platform == "win32" else "bin")
 OPTIONS = os.getenv("INPUT_OPTIONS", default="")
 SRC = os.getenv("INPUT_SRC", default="")
+JUPYTER = os.getenv("INPUT_JUPYTER") == "true"
 BLACK_ARGS = os.getenv("INPUT_BLACK_ARGS", default="")
 VERSION = os.getenv("INPUT_VERSION", default="")
 
@@ -17,7 +18,11 @@ run([sys.executable, "-m", "venv", str(ENV_PATH)], check=True)
 version_specifier = VERSION
 if VERSION and VERSION[0] in "0123456789":
     version_specifier = f"=={VERSION}"
-req = f"black[colorama]{version_specifier}"
+if JUPYTER:
+    extra_deps = "[colorama,jupyter]"
+else:
+    extra_deps = "[colorama]"
+req = f"black{extra_deps}{version_specifier}"
 pip_proc = run(
     [str(ENV_BIN / "python"), "-m", "pip", "install", req],
     stdout=PIPE,
index d77b969367897f155671bd38941e6f2db117b493..12bcb21fee663bcd24c1a909016930d85e278f01 100644 (file)
@@ -39,6 +39,10 @@ or just the version number if you want an exact version. The action defaults to
 latest release available on PyPI. Only versions available from PyPI are supported, so no
 commit SHAs or branch names.
 
+If you want to include Jupyter Notebooks, _Black_ must be installed with the `jupyter`
+extra. Installing the extra and including Jupyter Notebook files can be configured via
+`jupyter` (default is `false`).
+
 You can also configure the arguments passed to _Black_ via `options` (defaults to
 `'--check --diff'`) and `src` (default is `'.'`)
 
@@ -49,6 +53,7 @@ Here's an example configuration:
   with:
     options: "--check --verbose"
     src: "./src"
+    jupyter: true
     version: "21.5b1"
 ```