Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
interval: "monthly"
cooldown:
default-days: 7
groups:
actions:
patterns:
- "*"

- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "monthly"
cooldown:
default-days: 7
groups:
python:
patterns:
- "*"
59 changes: 44 additions & 15 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,63 @@ on:
branches: [ main ]
workflow_dispatch:

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
tests:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Set up Python
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: "3.15"

- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install . --group lint

- name: Ruff lint
run: python3 -m ruff check --output-format=github .

- name: Ruff format
run: python3 -m ruff format --check --diff .

- name: Mypy
run: python3 -m mypy

tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
python-version: ["3.11", "3.12", "3.13", "3.14", "3.15"]

steps:
- name: Checkout
uses: actions/checkout@v6
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: ${{ matrix.python-version }}

- uses: actions/cache@v5
with:
path: ~/.cache/pip
key: ${{ runner.os }}-${{ matrix.python-version }}-pip-${{ hashFiles('pyproject.toml') }}

- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install "." pytest
python3 -m pip install . --group test

- name: Test with pytest
run: |
Expand All @@ -46,16 +73,18 @@ jobs:
publish:
runs-on: ubuntu-latest
if: ${{ startsWith(github.ref, 'refs/tags/') }}
needs: tests
needs: [lint, tests]
permissions:
id-token: write # OIDC for uploading to PyPI

steps:
- name: Checkout
uses: actions/checkout@v6
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Set up Python
uses: actions/setup-python@v6
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: "3.11"

Expand All @@ -65,4 +94,4 @@ jobs:
python3 -m build

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
25 changes: 25 additions & 0 deletions .github/workflows/zizmor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: GitHub Actions Security Analysis with zizmor

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

permissions:
contents: read

jobs:
zizmor:
runs-on: ubuntu-latest
permissions:
contents: read
# Needed to upload the results to the code-scanning dashboard.
security-events: write
actions: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- name: Run zizmor
uses: zizmorcore/zizmor-action@85b2b9fb8e3325e7a23d7d0a9d7ba5ae0f999e3e # v0.7.1
30 changes: 14 additions & 16 deletions ipython_pygments_lexers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
Defines a variety of Pygments lexers for highlighting IPython code.

Expand Down Expand Up @@ -36,45 +35,45 @@
import re

# Third party
# do_insertions is missing from types-Pygments
from pygments.lexer import ( # type: ignore[attr-defined]
DelegatingLexer,
Lexer,
RegexLexer,
bygroups,
do_insertions,
using,
)
from pygments.lexers import (
BashLexer,
HtmlLexer,
JavascriptLexer,
RubyLexer,
PerlLexer,
Python2Lexer,
Python3Lexer,
RubyLexer,
TexLexer,
)
from pygments.lexer import (
Lexer,
DelegatingLexer,
RegexLexer,
do_insertions,
bygroups,
using,
)
from pygments.token import (
Error,
Generic,
Keyword,
Literal,
Name,
Operator,
Other,
Text,
Error,
)


line_re = re.compile(".*?\n")

__all__ = [
"IPyLexer",
"IPython3Lexer",
"IPythonConsoleLexer",
"IPythonLexer",
"IPythonPartialTracebackLexer",
"IPythonTracebackLexer",
"IPythonConsoleLexer",
"IPyLexer",
]


Expand Down Expand Up @@ -578,5 +577,4 @@ def get_tokens_unprocessed(self, text):
lex = self.IPythonConsoleLexer
else:
lex = self.IPythonLexer
for token in lex.get_tokens_unprocessed(text):
yield token
yield from lex.get_tokens_unprocessed(text)
45 changes: 44 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,25 @@ license = {file = "LICENSE"}
classifiers = [
"Framework :: IPython",
"License :: OSI Approved :: BSD License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
"Programming Language :: Python :: 3.15",
]
requires-python=">=3.8"
requires-python=">=3.11"
dependencies = [
"pygments"
]
dynamic=["version", "description"]

[dependency-groups]
test = ["pytest"]
lint = ["ruff", "mypy", "types-Pygments", {include-group = "test"}]
dev = [{include-group = "lint"}]

[project.entry-points."pygments.lexers"]
ipythonconsole = "ipython_pygments_lexers:IPythonConsoleLexer"
ipython = "ipython_pygments_lexers:IPythonLexer"
Expand All @@ -31,3 +43,34 @@ Source = "https://github.com/ipython/ipython-pygments-lexers"
include = [
"test_*.py",
]

[tool.ruff]
target-version = "py311"

[tool.ruff.lint]
extend-select = [
"I", # isort
"UP", # pyupgrade
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"PIE", # flake8-pie
"PGH", # pygrep-hooks
"RUF", # ruff-specific
]
ignore = [
"RUF012", # Pygments lexers declare aliases/tokens as plain class attributes
]

[tool.mypy]
python_version = "3.11"
files = ["ipython_pygments_lexers.py", "test_ipython_pygments_lexers.py"]
warn_unused_configs = true
warn_redundant_casts = true
warn_unused_ignores = true
strict_equality = true
extra_checks = true

[tool.pytest.ini_options]
addopts = ["-ra", "--strict-markers", "--strict-config"]
xfail_strict = true
filterwarnings = ["error"]
16 changes: 9 additions & 7 deletions test_ipython_pygments_lexers.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,16 @@ def test_shell_commands():
assert bash_tokens[:-1] == ipylex_token[:-1]

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

fragment_2 = "\t %%!\n" + fragment[1:]
tokens_2 = [
(Token.Text, "\t "),
(Token.Operator, "%%!"),
(Token.Text, "\n"),
] + bash_tokens[1:]
*bash_tokens[1:],
]
assert tokens_2 == list(lexer.get_tokens(fragment_2))

fragment_2 = "x = " + fragment
Expand All @@ -72,7 +71,8 @@ def test_shell_commands():
(Token.Text, " "),
(Token.Operator, "="),
(Token.Text, " "),
] + bash_tokens
*bash_tokens,
]
assert tokens_2[:-1] == list(lexer.get_tokens(fragment_2))[:-1]

fragment_2 = "x, = " + fragment
Expand All @@ -82,7 +82,8 @@ def test_shell_commands():
(Token.Text, " "),
(Token.Operator, "="),
(Token.Text, " "),
] + bash_tokens
*bash_tokens,
]
assert tokens_2[:-1] == list(lexer.get_tokens(fragment_2))[:-1]

fragment_2 = "x, = %sx " + fragment[1:]
Expand All @@ -95,7 +96,8 @@ def test_shell_commands():
(Token.Operator, "%"),
(Token.Keyword, "sx"),
(TOKEN_WS, " "),
] + bash_tokens[1:]
*bash_tokens[1:],
]
assert tokens_2[:-1] == list(lexer.get_tokens(fragment_2))[:-1]


Expand Down