Skip to content

Commit ba18cf9

Browse files
committed
modernize repo
1 parent 5fc68a3 commit ba18cf9

5 files changed

Lines changed: 137 additions & 38 deletions

File tree

‎.github/dependabot.yml‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
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: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,63 @@ on:
77
pull_request:
88
branches: [ main ]
99

10+
permissions:
11+
contents: read
12+
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.ref }}
15+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
16+
1017
jobs:
11-
tests:
18+
lint:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
23+
with:
24+
persist-credentials: false
25+
26+
- name: Set up Python
27+
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
28+
with:
29+
python-version: "3.15"
1230

31+
- name: Install dependencies
32+
run: |
33+
python3 -m pip install --upgrade pip
34+
python3 -m pip install . --group lint
35+
36+
- name: Ruff lint
37+
run: python3 -m ruff check --output-format=github .
38+
39+
- name: Ruff format
40+
run: python3 -m ruff format --check --diff .
41+
42+
- name: Mypy
43+
run: python3 -m mypy
44+
45+
tests:
1346
runs-on: ubuntu-latest
1447
strategy:
48+
fail-fast: false
1549
matrix:
16-
python-version: ["3.11", "3.12", "3.13"]
50+
python-version: ["3.11", "3.12", "3.13", "3.14", "3.15"]
1751

1852
steps:
1953
- name: Checkout
20-
uses: actions/checkout@v4
54+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
55+
with:
56+
persist-credentials: false
2157

2258
- name: Set up Python ${{ matrix.python-version }}
23-
uses: actions/setup-python@v5
59+
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
2460
with:
2561
python-version: ${{ matrix.python-version }}
2662

27-
- uses: actions/cache@v4
28-
with:
29-
path: ~/.cache/pip
30-
key: ${{ runner.os }}-${{ matrix.python-version }}-pip-${{ hashFiles('pyproject.toml') }}
31-
3263
- name: Install dependencies
3364
run: |
3465
python3 -m pip install --upgrade pip
35-
python3 -m pip install "." pytest
66+
python3 -m pip install . --group test
3667
3768
- name: Test with pytest
3869
run: |
@@ -41,16 +72,18 @@ jobs:
4172
publish:
4273
runs-on: ubuntu-latest
4374
if: ${{ startsWith(github.ref, 'refs/tags/') }}
44-
needs: tests
75+
needs: [lint, tests]
4576
permissions:
4677
id-token: write # OIDC for uploading to PyPI
4778

4879
steps:
4980
- name: Checkout
50-
uses: actions/checkout@v4
81+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
82+
with:
83+
persist-credentials: false
5184

5285
- name: Set up Python
53-
uses: actions/setup-python@v5
86+
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
5487
with:
5588
python-version: "3.11"
5689

@@ -60,4 +93,4 @@ jobs:
6093
python3 -m build
6194
6295
- name: Publish package distributions to PyPI
63-
uses: pypa/gh-action-pypi-publish@release/v1
96+
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: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,25 @@ readme = "README.md"
1111
classifiers = [
1212
"Framework :: IPython",
1313
"License :: OSI Approved :: BSD License",
14+
"Programming Language :: Python :: 3",
15+
"Programming Language :: Python :: 3 :: Only",
16+
"Programming Language :: Python :: 3.11",
17+
"Programming Language :: Python :: 3.12",
18+
"Programming Language :: Python :: 3.13",
19+
"Programming Language :: Python :: 3.14",
20+
"Programming Language :: Python :: 3.15",
1421
]
1522
requires-python=">=3.11"
1623
dependencies = [
1724
"pygments"
1825
]
1926
dynamic=["version", "description"]
2027

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

‎test_ipython_pygments_lexers.py‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# Distributed under the terms of the Modified BSD License.
55

66
from pygments import __version__ as pygments_version
7-
from pygments.token import Token
87
from pygments.lexers import BashLexer
8+
from pygments.token import Token
99

1010
import ipython_pygments_lexers as lexers
1111

@@ -40,17 +40,16 @@ def test_shell_commands():
4040
assert bash_tokens[:-1] == ipylex_token[:-1]
4141

4242
fragment_2 = "!" + fragment
43-
tokens_2 = [
44-
(Token.Operator, "!!"),
45-
] + bash_tokens[1:]
43+
tokens_2 = [(Token.Operator, "!!"), *bash_tokens[1:]]
4644
assert tokens_2[:-1] == list(lexer.get_tokens(fragment_2))[:-1]
4745

4846
fragment_2 = "\t %%!\n" + fragment[1:]
4947
tokens_2 = [
5048
(Token.Text, "\t "),
5149
(Token.Operator, "%%!"),
5250
(Token.Text, "\n"),
53-
] + bash_tokens[1:]
51+
*bash_tokens[1:],
52+
]
5453
assert tokens_2 == list(lexer.get_tokens(fragment_2))
5554

5655
fragment_2 = "x = " + fragment
@@ -59,7 +58,8 @@ def test_shell_commands():
5958
(Token.Text, " "),
6059
(Token.Operator, "="),
6160
(Token.Text, " "),
62-
] + bash_tokens
61+
*bash_tokens,
62+
]
6363
assert tokens_2[:-1] == list(lexer.get_tokens(fragment_2))[:-1]
6464

6565
fragment_2 = "x, = " + fragment
@@ -69,7 +69,8 @@ def test_shell_commands():
6969
(Token.Text, " "),
7070
(Token.Operator, "="),
7171
(Token.Text, " "),
72-
] + bash_tokens
72+
*bash_tokens,
73+
]
7374
assert tokens_2[:-1] == list(lexer.get_tokens(fragment_2))[:-1]
7475

7576
fragment_2 = "x, = %sx " + fragment[1:]
@@ -82,7 +83,8 @@ def test_shell_commands():
8283
(Token.Operator, "%"),
8384
(Token.Keyword, "sx"),
8485
(TOKEN_WS, " "),
85-
] + bash_tokens[1:]
86+
*bash_tokens[1:],
87+
]
8688
assert tokens_2[:-1] == list(lexer.get_tokens(fragment_2))[:-1]
8789

8890

0 commit comments

Comments
 (0)