Skip to content

Commit

Permalink
bump min python to 3.10
Browse files Browse the repository at this point in the history
drop black for ruff-format
  • Loading branch information
janosh committed Nov 12, 2023
1 parent b95f9ee commit 406c350
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 61 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ jobs:
- name: Check out repo
uses: actions/checkout@v3

- name: Set up Python 3.8
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: "3.10"
cache: pip
cache-dependency-path: pyproject.toml

- name: Install format-ipy-cells and test deps
run: pip install .[test]
Expand Down
17 changes: 7 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,20 @@ default_install_hook_types: [pre-commit, commit-msg]
exclude: tests/fixtures/raw_nb.py

repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.248
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.5
hooks:
- id: ruff
args: [--fix]

- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.0.1
rev: v1.7.0
hooks:
- id: mypy

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-case-conflict
- id: check-symlinks
Expand All @@ -34,7 +30,8 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/codespell-project/codespell
rev: v2.2.2
rev: v2.2.6
hooks:
- id: codespell
stages: [commit, commit-msg]
args: [--check-filenames]
9 changes: 6 additions & 3 deletions format_ipy_cells/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import importlib.metadata as md
from argparse import ArgumentParser
from typing import Sequence
from collections.abc import Sequence

from format_ipy_cells.helpers import (
delete_last_cell_if_empty,
Expand Down Expand Up @@ -49,7 +49,7 @@ def fix_file(filename: str) -> int:
return 0


def main(argv: Sequence[str] = None) -> int:
def main(argv: Sequence[str] | None = None) -> int:
"""The format-ipy-cells CLI interface.
Returns:
Expand All @@ -60,7 +60,10 @@ def main(argv: Sequence[str] = None) -> int:

pkg_version = md.version(pkg_name := "format-ipy-cells")
parser.add_argument(
"-v", "--version", action="version", version=f"{pkg_name} v{pkg_version}"
"-v",
"--version",
action="version",
version=f"{pkg_name} v{pkg_version}",
)
args = parser.parse_args(argv)

Expand Down
44 changes: 15 additions & 29 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,20 @@ authors = [{ name = "Janosh Riebesell", email = "janosh.riebesell@gmail.com" }]
license = { file = "license" }
readme = 'readme.md'
keywords = [
"code formatting",
"interactive",
"python",
"jupyter",
"ipython",
"code formatting",
"jupyter",
"pre-commit hook",
"python",
]
classifiers = [
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3.11",
]
requires-python = ">=3.8"
requires-python = ">=3.10"

[project.urls]
Homepage = "https://github.com/janosh/format-ipy-cells"
Expand Down Expand Up @@ -52,30 +51,17 @@ warn_unused_ignores = true
no_implicit_optional = false

[tool.ruff]
target-version = "py38"
select = [
"B", # flake8-bugbear
"D", # pydocstyle
"E", # pycodestyle
"ERA", # flake8-eradicate
"F", # pyflakes
"I", # isort
"PLE", # pylint error
"PLW", # pylint warning
"PYI", # flakes8-pyi
"Q", # flake8-quotes
"SIM", # flake8-simplify
"TID", # tidy imports
"UP", # pyupgrade
"W", # pycodestyle
"YTT", # flake8-2020
]
target-version = "py310"
select = ["ALL"]
ignore = [
"D100", # Missing docstring in public module
"D104", # Missing docstring in public package
"D205", # 1 blank line required between summary line and description
"D100", # Missing docstring in public module
"D104", # Missing docstring in public package
"D205", # 1 blank line required between summary line and description
"INP001", # implicit-namespace-packages
"PTH", # prefer pathlib over os.path
"T201", # print
]
pydocstyle.convention = "google"

[tool.ruff.per-file-ignores]
"tests/*" = ["D103"]
"tests/*" = ["D103", "S101"]
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Tests](https://github.com/janosh/format-ipy-cells/actions/workflows/test.yml/badge.svg)](https://github.com/janosh/format-ipy-cells/actions/workflows/test.yml)
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/janosh/format-ipy-cells/main.svg)](https://results.pre-commit.ci/latest/github/janosh/format-ipy-cells/main)
[![Requires Python 3.8+](https://img.shields.io/badge/Python-3.8+-blue.svg?logo=python&logoColor=white)](https://python.org/downloads)
[![Requires Python 3.10+](https://img.shields.io/badge/Python-3.10+-blue.svg?logo=python&logoColor=white)](https://python.org/downloads)
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)
[![PyPI](https://img.shields.io/pypi/v/format-ipy-cells?logo=pypi&logoColor=white)](https://pypi.org/project/format-ipy-cells)

Expand Down
18 changes: 9 additions & 9 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ def test_format_cell_delimiters(raw_delim: str) -> None:
assert format_cell_delimiters(raw_delim) == "# %%"


@pytest.mark.parametrize("input", ["# %%some comment", "# %% some comment"])
def test_format_comments_after_cell_delimiters(input: str) -> None:
assert format_comments_after_cell_delimiters(input) == "# %% some comment"
@pytest.mark.parametrize("line", ["# %%some comment", "# %% some comment"])
def test_format_comments_after_cell_delimiters(line: str) -> None:
assert format_comments_after_cell_delimiters(line) == "# %% some comment"


def test_remove_empty_cells() -> None:
Expand All @@ -39,7 +39,7 @@ def test_remove_empty_cells() -> None:


@pytest.mark.parametrize(
"input",
"line",
[
# cell with single blank line between delimiter and first code line
"# %%\n\nfoo = 'bar'",
Expand All @@ -49,8 +49,8 @@ def test_remove_empty_cells() -> None:
"# %%\n\t\t\n \n \nfoo = 'bar'",
],
)
def test_remove_empty_lines_starting_cell(input: str) -> None:
assert remove_empty_lines_starting_cell(input) == "# %%\nfoo = 'bar'"
def test_remove_empty_lines_starting_cell(line: str) -> None:
assert remove_empty_lines_starting_cell(line) == "# %%\nfoo = 'bar'"


def test_ensure_two_blank_lines_preceding_cell() -> None:
Expand All @@ -68,7 +68,7 @@ def test_ensure_two_blank_lines_preceding_cell() -> None:


@pytest.mark.parametrize(
"input",
"line",
[
# empty last cell containing single blank line
"\n# %%\na = 5\n\n\n# %%\n",
Expand All @@ -78,5 +78,5 @@ def test_ensure_two_blank_lines_preceding_cell() -> None:
"\n# %%\na = 5\n\n\n# %%\n\t \n\n \n",
],
)
def test_delete_last_cell_if_empty(input: str) -> None:
assert delete_last_cell_if_empty(input) == "\n# %%\na = 5\n"
def test_delete_last_cell_if_empty(line: str) -> None:
assert delete_last_cell_if_empty(line) == "\n# %%\na = 5\n"
10 changes: 4 additions & 6 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
from pathlib import Path

import pytest
from pytest import CaptureFixture

from format_ipy_cells.main import main


def test_main_format_cells(tmp_path: Path, capsys: CaptureFixture[str]) -> None:
def test_main_format_cells(tmp_path: Path, capsys: pytest.CaptureFixture[str]) -> None:
shutil.copy2("tests/fixtures/raw_nb.py", raw_tmp := str(tmp_path / "raw_nb.py"))
# test we leave clean file as is and don't print logs about it
clean_nb = "tests/fixtures/clean_nb.py"
Expand All @@ -31,10 +30,9 @@ def test_main_format_cells(tmp_path: Path, capsys: CaptureFixture[str]) -> None:
assert out == err == ""


def test_main_print_version(capsys: CaptureFixture[str]) -> None:
with pytest.raises(SystemExit):
ret_val = main(["-v"])
assert ret_val == 0
def test_main_print_version(capsys: pytest.CaptureFixture[str]) -> None:
with pytest.raises(SystemExit, match="^0$"):
main(["-v"])

stdout, stderr = capsys.readouterr()

Expand Down

0 comments on commit 406c350

Please sign in to comment.