From 6e4b1978f34ab0b406822db025a5822993cc8ebf Mon Sep 17 00:00:00 2001 From: Anderson Banihirwe <13301940+andersy005@users.noreply.github.com> Date: Thu, 29 Feb 2024 23:21:40 -0800 Subject: [PATCH] Update-pre-commit-hooks (#220) --- .github/workflows/ci.yaml | 2 +- .github/workflows/pypi-release.yaml | 4 +- .github/workflows/upstream-dev-ci.yaml | 2 +- .pre-commit-config.yaml | 31 ++--------- MANIFEST.in | 1 + ci/environment-docs.yml | 2 +- docs/source/conf.py | 1 - jupyter_forward/__init__.py | 1 + jupyter_forward/cli.py | 9 ++- jupyter_forward/core.py | 16 +++--- jupyter_forward/helpers.py | 7 ++- jupyter_forward/py.typed | 0 pyproject.toml | 77 ++++++++++++++++++++++++-- setup.py | 13 +++-- 14 files changed, 109 insertions(+), 57 deletions(-) create mode 100644 jupyter_forward/py.typed diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b0f8db6..bebfbbd 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -29,7 +29,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.7", "3.8", "3.9", "3.10"] + python-version: ["3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v4 with: diff --git a/.github/workflows/pypi-release.yaml b/.github/workflows/pypi-release.yaml index 41502ba..07f5394 100644 --- a/.github/workflows/pypi-release.yaml +++ b/.github/workflows/pypi-release.yaml @@ -16,7 +16,7 @@ jobs: - uses: actions/setup-python@v5 name: Install Python with: - python-version: 3.8 + python-version: 3.x - name: Install dependencies run: | @@ -51,7 +51,7 @@ jobs: - uses: actions/setup-python@v5 name: Install Python with: - python-version: 3.8 + python-version: 3.x - uses: actions/download-artifact@v4 with: name: releases diff --git a/.github/workflows/upstream-dev-ci.yaml b/.github/workflows/upstream-dev-ci.yaml index bd59ec9..47f366d 100644 --- a/.github/workflows/upstream-dev-ci.yaml +++ b/.github/workflows/upstream-dev-ci.yaml @@ -27,7 +27,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.10"] + python-version: ["3.11"] steps: - uses: actions/checkout@v4 with: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d6e644b..ad1e103 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,33 +14,12 @@ repos: - id: debug-statements - id: mixed-line-ending - - repo: https://github.com/asottile/pyupgrade - rev: v3.15.0 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: "v0.3.0" hooks: - - id: pyupgrade - args: - - "--py38-plus" - - - repo: https://github.com/psf/black - rev: 24.1.1 - hooks: - - id: black - - id: black-jupyter - - - repo: https://github.com/keewis/blackdoc - rev: v0.3.9 - hooks: - - id: blackdoc - - - repo: https://github.com/PyCQA/flake8 - rev: 7.0.0 - hooks: - - id: flake8 - - - repo: https://github.com/PyCQA/isort - rev: 5.13.2 - hooks: - - id: isort + - id: ruff + args: ["--fix"] + - id: ruff-format - repo: https://github.com/pre-commit/mirrors-prettier rev: v4.0.0-alpha.8 diff --git a/MANIFEST.in b/MANIFEST.in index 1af03cc..ac804e0 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -4,6 +4,7 @@ include README.md recursive-include jupyter_forward *.py recursive-exclude * __pycache__ recursive-exclude * *.py[co] +include jupyter_forward/py.typed include *.md include *.toml diff --git a/ci/environment-docs.yml b/ci/environment-docs.yml index ad81f47..0f70693 100644 --- a/ci/environment-docs.yml +++ b/ci/environment-docs.yml @@ -6,7 +6,7 @@ dependencies: - furo - myst-nb - pip - - python=3.9 + - python=3.11 - sphinx-copybutton - sphinx-inline-tabs - sqlalchemy diff --git a/docs/source/conf.py b/docs/source/conf.py index 90f99cb..df0ef2b 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -2,7 +2,6 @@ import jupyter_forward - extensions = [ 'sphinx.ext.autodoc', 'sphinx.ext.viewcode', diff --git a/jupyter_forward/__init__.py b/jupyter_forward/__init__.py index 198a1c9..9efd48d 100644 --- a/jupyter_forward/__init__.py +++ b/jupyter_forward/__init__.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 # flake8: noqa """Top-level module for jupyter_forward .""" + from pkg_resources import DistributionNotFound, get_distribution from .core import RemoteRunner diff --git a/jupyter_forward/cli.py b/jupyter_forward/cli.py index 07ac03a..6700341 100644 --- a/jupyter_forward/cli.py +++ b/jupyter_forward/cli.py @@ -1,4 +1,3 @@ -import typing from pathlib import Path import typer @@ -23,7 +22,7 @@ def start( port: int = typer.Option( 8888, help=( - '''The local port the remote notebook server will be forwarded to. If not specified, defaults to 8888.''' + """The local port the remote notebook server will be forwarded to. If not specified, defaults to 8888.""" ), show_default=True, ), @@ -40,7 +39,7 @@ def start( notebook: str = typer.Option( None, show_default=True, - help='''The absolute path of the notebook to load on the remote host. `--notebook-dir` and `--notebook` are mutually exclusive.''', + help="""The absolute path of the notebook to load on the remote host. `--notebook-dir` and `--notebook` are mutually exclusive.""", ), port_forwarding: bool = typer.Option( True, show_default=True, help='Whether to set up SSH port forwarding or not.' @@ -53,7 +52,7 @@ def start( file_okay=True, show_default=True, help=( - '''Selects a file from which the identity (private key) for public key authentication is read.''' + """Selects a file from which the identity (private key) for public key authentication is read.""" ), ), launch_command: str = typer.Option( @@ -72,7 +71,7 @@ def start( show_default=True, help='Which remote shell binary to use.', ), - version: typing.Optional[bool] = typer.Option( + version: bool | None = typer.Option( None, '--version', callback=version_callback, diff --git a/jupyter_forward/core.py b/jupyter_forward/core.py index 3bc813d..f325e42 100644 --- a/jupyter_forward/core.py +++ b/jupyter_forward/core.py @@ -8,7 +8,7 @@ import sys import textwrap import time -from typing import Callable +from collections.abc import Callable import invoke import paramiko @@ -38,13 +38,13 @@ class RemoteRunner: host: str port: int = 8888 - conda_env: str = None - notebook_dir: str = None - notebook: str = None + conda_env: str | None = None + notebook_dir: str | None = None + notebook: str | None = None port_forwarding: bool = True - launch_command: str = None - identity: str = None - shell: str = None + launch_command: str | None = None + identity: str | None = None + shell: str | None = None auth_handler: Callable = _authentication_handler fallback_auth_handler: Callable = getpass.getpass @@ -58,7 +58,7 @@ def __post_init__(self): if self.port_forwarding and not is_port_available(self.port): console.print( - f'''[bold red]:x: Specified port={self.port} is already in use on your local machine. Try a different port''' + f"""[bold red]:x: Specified port={self.port} is already in use on your local machine. Try a different port""" ) sys.exit(1) self._authenticate() diff --git a/jupyter_forward/helpers.py b/jupyter_forward/helpers.py index 91e6d22..79cf2c6 100644 --- a/jupyter_forward/helpers.py +++ b/jupyter_forward/helpers.py @@ -8,7 +8,12 @@ from .console import console -def open_browser(port: int = None, token: str = None, url: str = None, path=None) -> None: +def open_browser( + port: int | None = None, + token: str | None = None, + url: str | None = None, + path: str | None = None, +) -> None: """Opens notebook interface in a new browser window. Parameters diff --git a/jupyter_forward/py.typed b/jupyter_forward/py.typed new file mode 100644 index 0000000..e69de29 diff --git a/pyproject.toml b/pyproject.toml index 485ce31..c114bcd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,8 +1,75 @@ -[tool.black] -line-length = 100 -target-version = ['py38'] -skip-string-normalization = true - [build-system] requires = ["setuptools>=45", "wheel", "setuptools_scm>=6.2"] + + +[tool.ruff] +line-length = 100 +target-version = "py310" + +builtins = ["ellipsis"] +# Exclude a variety of commonly ignored directories. +exclude = [ + ".bzr", + ".direnv", + ".eggs", + ".git", + ".git-rewrite", + ".hg", + ".ipynb_checkpoints", + ".mypy_cache", + ".nox", + ".pants.d", + ".pyenv", + ".pytest_cache", + ".pytype", + ".ruff_cache", + ".svn", + ".tox", + ".venv", + ".vscode", + "__pypackages__", + "_build", + "buck-out", + "build", + "dist", + "node_modules", + "site-packages", + "venv", +] +[tool.ruff.lint] +per-file-ignores = {} +ignore = [ + "E721", # Comparing types instead of isinstance + "E741", # Ambiguous variable names + "E501", # Conflicts with ruff format +] +select = [ + # Pyflakes + "F", + # Pycodestyle + "E", + "W", + # isort + "I", + # Pyupgrade + "UP", +] + +[tool.ruff.lint.mccabe] +max-complexity = 18 + +[tool.ruff.lint.isort] +known-first-party = ["jupyter_forward"] + +[tool.ruff.format] +quote-style = "single" +docstring-code-format = true + +[tool.ruff.lint.pydocstyle] +convention = "numpy" + + +[tool.pytest.ini_options] +console_output_style = "count" +addopts = "--cov=./ --cov-report=xml --verbose" diff --git a/setup.py b/setup.py index 620d122..46290bb 100644 --- a/setup.py +++ b/setup.py @@ -2,25 +2,26 @@ """The setup script.""" +import pathlib + from setuptools import find_packages, setup with open('requirements.txt') as f: requirements = f.read().strip().split('\n') -with open('README.md') as f: - long_description = f.read() +long_description = pathlib.Path('README.md').read_text() setup( maintainer='Xdev', maintainer_email='xdev@ucar.edu', - python_requires='>=3.7', + python_requires='>=3.10', classifiers=[ 'Development Status :: 2 - Pre-Alpha', 'License :: OSI Approved :: Apache Software License', 'Natural Language :: English', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', 'Topic :: Scientific/Engineering', 'Operating System :: OS Independent', 'Intended Audience :: Science/Research',