Skip to content

Commit 4bc2697

Browse files
committed
modernize repo
1 parent 933babc commit 4bc2697

5 files changed

Lines changed: 129 additions & 41 deletions

File tree

‎.github/dependabot.yml‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
version: 2
22
updates:
3-
# Maintain dependencies for GitHub Actions
43
- package-ecosystem: "github-actions"
54
directory: "/"
65
schedule:
7-
interval: "weekly"
6+
interval: "monthly"
7+
cooldown:
8+
default-days: 7
9+
groups:
10+
actions:
11+
patterns:
12+
- "*"
13+
14+
- package-ecosystem: "pip"
15+
directory: "/"
16+
schedule:
17+
interval: "monthly"
18+
cooldown:
19+
default-days: 7
20+
groups:
21+
python:
22+
patterns:
23+
- "*"

‎.github/workflows/test.yml‎

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,63 @@ on:
88
branches: [ main ]
99
workflow_dispatch:
1010

11+
permissions:
12+
contents: read
13+
1114
concurrency:
1215
group: ${{ github.workflow }}-${{ github.ref }}
13-
cancel-in-progress: true
16+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
1417

1518
jobs:
16-
tests:
19+
lint:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
24+
with:
25+
persist-credentials: false
26+
27+
- name: Set up Python
28+
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
29+
with:
30+
python-version: "3.15"
31+
32+
- name: Install dependencies
33+
run: |
34+
python3 -m pip install --upgrade pip
35+
python3 -m pip install . --group lint
36+
37+
- name: Ruff lint
38+
run: python3 -m ruff check --output-format=github .
39+
40+
- name: Ruff format
41+
run: python3 -m ruff format --check --diff .
42+
43+
- name: Mypy
44+
run: python3 -m mypy
1745

46+
tests:
1847
runs-on: ubuntu-latest
1948
strategy:
49+
fail-fast: false
2050
matrix:
21-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
51+
python-version: ["3.11", "3.12", "3.13", "3.14", "3.15"]
2252

2353
steps:
2454
- name: Checkout
25-
uses: actions/checkout@v6
55+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
56+
with:
57+
persist-credentials: false
2658

2759
- name: Set up Python ${{ matrix.python-version }}
28-
uses: actions/setup-python@v6
60+
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
2961
with:
3062
python-version: ${{ matrix.python-version }}
3163

32-
- uses: actions/cache@v5
33-
with:
34-
path: ~/.cache/pip
35-
key: ${{ runner.os }}-${{ matrix.python-version }}-pip-${{ hashFiles('pyproject.toml') }}
36-
3764
- name: Install dependencies
3865
run: |
3966
python3 -m pip install --upgrade pip
40-
python3 -m pip install "." pytest
67+
python3 -m pip install . --group test
4168
4269
- name: Test with pytest
4370
run: |
@@ -46,16 +73,18 @@ jobs:
4673
publish:
4774
runs-on: ubuntu-latest
4875
if: ${{ startsWith(github.ref, 'refs/tags/') }}
49-
needs: tests
76+
needs: [lint, tests]
5077
permissions:
5178
id-token: write # OIDC for uploading to PyPI
5279

5380
steps:
5481
- name: Checkout
55-
uses: actions/checkout@v6
82+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
83+
with:
84+
persist-credentials: false
5685

5786
- name: Set up Python
58-
uses: actions/setup-python@v6
87+
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
5988
with:
6089
python-version: "3.11"
6190

@@ -65,4 +94,4 @@ jobs:
6594
python3 -m build
6695
6796
- name: Publish package distributions to PyPI
68-
uses: pypa/gh-action-pypi-publish@release/v1
97+
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3

‎ipython_pygments_lexers.py‎

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
"""
32
Defines a variety of Pygments lexers for highlighting IPython code.
43
@@ -36,45 +35,45 @@
3635
import re
3736

3837
# Third party
38+
# do_insertions is missing from types-Pygments
39+
from pygments.lexer import ( # type: ignore[attr-defined]
40+
DelegatingLexer,
41+
Lexer,
42+
RegexLexer,
43+
bygroups,
44+
do_insertions,
45+
using,
46+
)
3947
from pygments.lexers import (
4048
BashLexer,
4149
HtmlLexer,
4250
JavascriptLexer,
43-
RubyLexer,
4451
PerlLexer,
4552
Python2Lexer,
4653
Python3Lexer,
54+
RubyLexer,
4755
TexLexer,
4856
)
49-
from pygments.lexer import (
50-
Lexer,
51-
DelegatingLexer,
52-
RegexLexer,
53-
do_insertions,
54-
bygroups,
55-
using,
56-
)
5757
from pygments.token import (
58+
Error,
5859
Generic,
5960
Keyword,
6061
Literal,
6162
Name,
6263
Operator,
6364
Other,
6465
Text,
65-
Error,
6666
)
6767

68-
6968
line_re = re.compile(".*?\n")
7069

7170
__all__ = [
71+
"IPyLexer",
7272
"IPython3Lexer",
73+
"IPythonConsoleLexer",
7374
"IPythonLexer",
7475
"IPythonPartialTracebackLexer",
7576
"IPythonTracebackLexer",
76-
"IPythonConsoleLexer",
77-
"IPyLexer",
7877
]
7978

8079

@@ -578,5 +577,4 @@ def get_tokens_unprocessed(self, text):
578577
lex = self.IPythonConsoleLexer
579578
else:
580579
lex = self.IPythonLexer
581-
for token in lex.get_tokens_unprocessed(text):
582-
yield token
580+
yield from lex.get_tokens_unprocessed(text)

‎pyproject.toml‎

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,25 @@ license = {file = "LICENSE"}
1212
classifiers = [
1313
"Framework :: IPython",
1414
"License :: OSI Approved :: BSD License",
15+
"Programming Language :: Python :: 3",
16+
"Programming Language :: Python :: 3 :: Only",
17+
"Programming Language :: Python :: 3.11",
18+
"Programming Language :: Python :: 3.12",
19+
"Programming Language :: Python :: 3.13",
20+
"Programming Language :: Python :: 3.14",
21+
"Programming Language :: Python :: 3.15",
1522
]
16-
requires-python=">=3.8"
23+
requires-python=">=3.11"
1724
dependencies = [
1825
"pygments"
1926
]
2027
dynamic=["version", "description"]
2128

29+
[dependency-groups]
30+
test = ["pytest"]
31+
lint = ["ruff", "mypy", "types-Pygments"]
32+
dev = [{include-group = "test"}, {include-group = "lint"}]
33+
2234
[project.entry-points."pygments.lexers"]
2335
ipythonconsole = "ipython_pygments_lexers:IPythonConsoleLexer"
2436
ipython = "ipython_pygments_lexers:IPythonLexer"
@@ -31,3 +43,34 @@ Source = "https://github.com/ipython/ipython-pygments-lexers"
3143
include = [
3244
"test_*.py",
3345
]
46+
47+
[tool.ruff]
48+
target-version = "py311"
49+
50+
[tool.ruff.lint]
51+
extend-select = [
52+
"I", # isort
53+
"UP", # pyupgrade
54+
"B", # flake8-bugbear
55+
"C4", # flake8-comprehensions
56+
"PIE", # flake8-pie
57+
"PGH", # pygrep-hooks
58+
"RUF", # ruff-specific
59+
]
60+
ignore = [
61+
"RUF012", # Pygments lexers declare aliases/tokens as plain class attributes
62+
]
63+
64+
[tool.mypy]
65+
python_version = "3.11"
66+
files = ["ipython_pygments_lexers.py", "test_ipython_pygments_lexers.py"]
67+
warn_unused_configs = true
68+
warn_redundant_casts = true
69+
warn_unused_ignores = true
70+
strict_equality = true
71+
extra_checks = true
72+
73+
[tool.pytest.ini_options]
74+
addopts = ["-ra", "--strict-markers", "--strict-config"]
75+
xfail_strict = true
76+
filterwarnings = ["error"]

‎test_ipython_pygments_lexers.py‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,16 @@ def test_shell_commands():
5353
assert bash_tokens[:-1] == ipylex_token[:-1]
5454

5555
fragment_2 = "!" + fragment
56-
tokens_2 = [
57-
(Token.Operator, "!!"),
58-
] + bash_tokens[1:]
56+
tokens_2 = [(Token.Operator, "!!"), *bash_tokens[1:]]
5957
assert tokens_2[:-1] == list(lexer.get_tokens(fragment_2))[:-1]
6058

6159
fragment_2 = "\t %%!\n" + fragment[1:]
6260
tokens_2 = [
6361
(Token.Text, "\t "),
6462
(Token.Operator, "%%!"),
6563
(Token.Text, "\n"),
66-
] + bash_tokens[1:]
64+
*bash_tokens[1:],
65+
]
6766
assert tokens_2 == list(lexer.get_tokens(fragment_2))
6867

6968
fragment_2 = "x = " + fragment
@@ -72,7 +71,8 @@ def test_shell_commands():
7271
(Token.Text, " "),
7372
(Token.Operator, "="),
7473
(Token.Text, " "),
75-
] + bash_tokens
74+
*bash_tokens,
75+
]
7676
assert tokens_2[:-1] == list(lexer.get_tokens(fragment_2))[:-1]
7777

7878
fragment_2 = "x, = " + fragment
@@ -82,7 +82,8 @@ def test_shell_commands():
8282
(Token.Text, " "),
8383
(Token.Operator, "="),
8484
(Token.Text, " "),
85-
] + bash_tokens
85+
*bash_tokens,
86+
]
8687
assert tokens_2[:-1] == list(lexer.get_tokens(fragment_2))[:-1]
8788

8889
fragment_2 = "x, = %sx " + fragment[1:]
@@ -95,7 +96,8 @@ def test_shell_commands():
9596
(Token.Operator, "%"),
9697
(Token.Keyword, "sx"),
9798
(TOKEN_WS, " "),
98-
] + bash_tokens[1:]
99+
*bash_tokens[1:],
100+
]
99101
assert tokens_2[:-1] == list(lexer.get_tokens(fragment_2))[:-1]
100102

101103

0 commit comments

Comments
 (0)