Skip to content

Commit

Permalink
Adopt ruff and clean up pre-commit (jupyterlab#13562)
Browse files Browse the repository at this point in the history
* adopt ruff and clean up pre-commit

* ignore changelog.md

* reinstate prints

* reinstate print

* reinstate print

* reinstate imports

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* reinstate prints

* print fixups

* fixups in labapp

* lint and fix output

* Fix latest linter errors

* sync pre-commit and pyproject versions

* use local versions of black, ruff

* formatting

* Update snapshots

* Correct gutter lines

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Frédéric Collonval <[email protected]>
Co-authored-by: Frédéric Collonval <[email protected]>
  • Loading branch information
4 people authored Jan 19, 2023
1 parent c253a94 commit 834680b
Show file tree
Hide file tree
Showing 94 changed files with 510 additions and 547 deletions.
16 changes: 0 additions & 16 deletions .flake8

This file was deleted.

8 changes: 7 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,11 @@ updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
# Check for updates to GitHub Actions every weekday
# Check for updates to GitHub Actions every week
interval: "weekly"
# Set update schedule for pip
- package-ecosystem: "pip"
directory: "/"
schedule:
# Check for updates to GitHub Actions every week
interval: "weekly"
11 changes: 0 additions & 11 deletions .github/workflows/linuxtests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,3 @@ jobs:
with:
ignore_glob: "packages/ui-components/docs/source/ui_components.rst images"
ignore_links: "../api/*.* .*/images/[\\w-]+.png https://docs.github.com/en/.* https://jupyterlab.github.io"

pre-commit:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v3
- name: Base Setup
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
- name: Install Jupyterlab
run: pip install -e .
- uses: pre-commit/[email protected]
43 changes: 10 additions & 33 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ci:
# skip any check that needs internet access
skip: [check-jsonschema, prettier, eslint, stylelint, integrity]
skip: [prettier, eslint, stylelint]

default_language_version:
node: system
Expand All @@ -24,44 +24,21 @@ repos:
- id: trailing-whitespace
exclude: .bumpversion.cfg

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.19.2
hooks:
- id: check-github-workflows

- repo: https://github.com/psf/black
rev: 22.12.0
hooks:
- id: black
args: ['--line-length', '100']

- repo: https://github.com/PyCQA/isort
rev: 5.11.4
hooks:
- id: isort
files: \.py$
args: [--profile=black]

- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies:
[
'flake8-bugbear==22.6.22',
'flake8-implicit-str-concat==0.2.0'
]

- repo: https://github.com/executablebooks/mdformat
rev: 0.7.16
hooks:
- id: mdformat
additional_dependencies:
[mdformat-gfm, mdformat-frontmatter, mdformat-footnote]

- repo: https://github.com/sirosen/check-jsonschema
rev: 0.20.0
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.177
hooks:
- id: check-jsonschema
name: 'Check GitHub Workflows'
files: ^\.github/workflows/
types: [yaml]
args: ['--schemafile', 'https://json.schemastore.org/github-workflow']
- id: ruff
args: ["--fix"]

- repo: local
hooks:
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
**/static
**/.ipynb_checkpoints
tests/**/coverage
CHANGELOG.md

.eggs
dev_mode/index.js
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ To learn more about extensions, see the [user documentation](https://jupyterlab.

Read the current JupyterLab documentation on [ReadTheDocs](http://jupyterlab.readthedocs.io/en/stable/).

______________________________________________________________________
---

## Getting started

Expand Down Expand Up @@ -92,7 +92,7 @@ The latest versions of the following browsers are currently _known to work_:

See our [documentation](http://jupyterlab.readthedocs.io/en/latest/getting_started/installation.html) for additional details.

______________________________________________________________________
---

## Getting help

Expand All @@ -106,7 +106,7 @@ To report a bug please read the [guidelines](https://jupyterlab.readthedocs.io/e

We also welcome suggestions for new features as they help make the project more useful for everyone. To request a feature please use the [feature request template](https://github.com/jupyterlab/jupyterlab/issues/new?labels=enhancement%2C+status%3ANeeds+Triage&template=feature_request.md).

______________________________________________________________________
---

## Development

Expand Down Expand Up @@ -165,7 +165,7 @@ Maintainer emeritus:
This list is provided to give the reader context on who we are and how our team functions.
To be listed, please submit a pull request with your information.

______________________________________________________________________
---

### Weekly Dev Meeting

Expand Down
2 changes: 1 addition & 1 deletion RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ Now do the actual final release:
- [ ] Create a branch for the release and push to GitHub
- [ ] Update the API [docs](#updating-api-docs)
- [ ] Merge the PRs on the other repos and set the default branch of the
xckd repo
xckd repo
- [ ] Publish to [conda-forge](https://github.com/jupyterlab/jupyterlab/blob/master/RELEASE.md#publishing-to-conda-forge).

After a few days (to allow for possible patch releases), set up development for
Expand Down
3 changes: 1 addition & 2 deletions binder/jupyter_notebook_config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import logging

common = [
"--no-browser",
Expand Down Expand Up @@ -41,6 +42,4 @@
},
}

import logging

c.ServerApp.log_level = logging.DEBUG
9 changes: 4 additions & 5 deletions binder/start
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

import sys
import shutil
import os
import shutil
import sys

argv = sys.argv[1:] + [
"--debug",
Expand All @@ -17,16 +17,15 @@ argv = sys.argv[1:] + [
"--config",
"binder/jupyter_notebook_config.py",
]
print(argv)

print(argv) # noqa

# Convert from jupyter-notebook based to jupyter-lab based start-up
def nb2jps(s):
return s.replace("jupyter-notebook", "jupyter-lab").replace("--NotebookApp.", "--ServerApp.")


new_argv = list(map(nb2jps, argv.copy()))
print(new_argv)
print(new_argv) # noqa

with open(".startup_args.txt", "w") as fid:
fid.write(str(new_argv))
Expand Down
4 changes: 2 additions & 2 deletions clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
subprocess.check_call("python -m pip uninstall -y jupyterlab".split(), cwd=here)


def resolvePattern(pat):
def resolve_pattern(pat):
"""handle a leading `#` or `@` in a pattern"""
pat = pat.strip()

Expand All @@ -33,7 +33,7 @@ def resolvePattern(pat):

# get the exclude patterns listed in .cleanignore
with open(os.path.join(here, ".cleanignore")) as f:
git_clean_exclude = [f"--exclude={pat}" for line in f for pat in resolvePattern(line)]
git_clean_exclude = [f"--exclude={pat}" for line in f for pat in resolve_pattern(line)]

git_clean_command = ["git", "clean", "-dfx"] + git_clean_exclude
subprocess.check_call(git_clean_command, cwd=here)
2 changes: 0 additions & 2 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

Expand Down
2 changes: 1 addition & 1 deletion design/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@ The About Plugin will feature an interactive guide for the user to scroll throug

Motion will also be implemented in our animations for each feature, using a moving image format (\_.gif or \_.gifv file) of a UX demonstration of a real screen, to show users not only where and what each feature looks like, but also how to actually use each feature in real time.

______________________________________________________________________
---

Please let our team know if you have any questions, suggestions, or comments about the design of the About plugin. Thank you!
14 changes: 5 additions & 9 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

Expand Down Expand Up @@ -67,7 +66,7 @@

# General information about the project.
project = "JupyterLab"
copyright = f"2018-{time.localtime().tm_year}, Project Jupyter"
copyright = f"2018-{time.localtime().tm_year}, Project Jupyter" # noqa
author = "Project Jupyter"


Expand All @@ -78,7 +77,7 @@
_version_py = HERE.parent.parent / "jupyterlab" / "_version.py"
version_ns = {}

exec(_version_py.read_text(), version_ns)
exec(_version_py.read_text(), version_ns) # noqa

# The short X.Y version.
version = "{0:d}.{1:d}".format(*version_ns["version_info"])
Expand Down Expand Up @@ -118,15 +117,13 @@ def build_api_docs(out_dir: Path):
if api_index.exists():
# avoid rebuilding docs because it takes forever
# `make clean` to force a rebuild
print(f"already have {api_index!s}")
pass
else:
print("Building jupyterlab API docs")
check_call(jlpm, cwd=str(root))
check_call(jlpm + ["build:packages"], cwd=str(root))
check_call(jlpm + ["docs"], cwd=str(root))

dest_dir = out_dir / "api"
print(f"Copying {docs_api!s} -> {dest_dir!s}")
if dest_dir.exists():
shutil.rmtree(str(dest_dir))
shutil.copytree(str(docs_api), str(dest_dir))
Expand Down Expand Up @@ -173,7 +170,6 @@ def copy_automated_screenshots(temp_folder: Path) -> List[Path]:
Returns:
List of copied files
"""
print(f"\n\n{temp_folder}\n")
docs = HERE.parent
root = docs.parent

Expand Down Expand Up @@ -386,8 +382,8 @@ def clean_code_files(tmp_files, app, exception):
"""Remove temporary folder."""
try:
shutil.rmtree(str(Path(app.srcdir) / SNIPPETS_FOLDER))
except Exception as e:
print(f"Fail to remove temporary snippet folder: {e}")
except Exception:
pass

for f in tmp_files:
f.unlink()
Expand Down
9 changes: 7 additions & 2 deletions examples/app/example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
],
"source": [
"import sys\n",
"\n",
"print('hello world', flush=True)\n",
"for i in range(3):\n",
" print(i, flush=True)\n",
Expand Down Expand Up @@ -98,6 +99,7 @@
],
"source": [
"from IPython.display import Image\n",
"\n",
"Image('./jupyter.png')"
]
},
Expand Down Expand Up @@ -134,7 +136,9 @@
],
"source": [
"from IPython.display import Latex\n",
"Latex('''The mass-energy equivalence is described by the famous equation\n",
"\n",
"Latex(\n",
" '''The mass-energy equivalence is described by the famous equation\n",
" \n",
"$$E=mc^2$$\n",
" \n",
Expand All @@ -143,7 +147,8 @@
" \n",
"\\\\begin{equation}\n",
"E=m\n",
"\\\\end{equation}''')"
"\\\\end{equation}'''\n",
")"
]
},
{
Expand Down
5 changes: 1 addition & 4 deletions examples/cell/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
import os

from jupyter_server.base.handlers import JupyterHandler
from jupyter_server.extension.handler import (
ExtensionHandlerJinjaMixin,
ExtensionHandlerMixin,
)
from jupyter_server.extension.handler import ExtensionHandlerJinjaMixin, ExtensionHandlerMixin
from jupyter_server.utils import url_path_join as ujoin
from jupyterlab_server import LabServerApp

Expand Down
5 changes: 1 addition & 4 deletions examples/console/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
import os

from jupyter_server.base.handlers import JupyterHandler
from jupyter_server.extension.handler import (
ExtensionHandlerJinjaMixin,
ExtensionHandlerMixin,
)
from jupyter_server.extension.handler import ExtensionHandlerJinjaMixin, ExtensionHandlerMixin
from jupyter_server.utils import url_path_join as ujoin
from jupyterlab_server import LabServerApp

Expand Down
9 changes: 7 additions & 2 deletions examples/console/test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
],
"source": [
"import sys\n",
"\n",
"print('hello world', flush=True)\n",
"for i in range(3):\n",
" print(i, flush=True)\n",
Expand Down Expand Up @@ -98,6 +99,7 @@
],
"source": [
"from IPython.display import Image\n",
"\n",
"Image('./jupyter.png')"
]
},
Expand Down Expand Up @@ -134,7 +136,9 @@
],
"source": [
"from IPython.display import Latex\n",
"Latex('''The mass-energy equivalence is described by the famous equation\n",
"\n",
"Latex(\n",
" '''The mass-energy equivalence is described by the famous equation\n",
" \n",
"$$E=mc^2$$\n",
" \n",
Expand All @@ -143,7 +147,8 @@
" \n",
"\\\\begin{equation}\n",
"E=m\n",
"\\\\end{equation}''')"
"\\\\end{equation}'''\n",
")"
]
},
{
Expand Down
1 change: 0 additions & 1 deletion examples/example_check.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

Expand Down
Loading

0 comments on commit 834680b

Please sign in to comment.