diff --git a/.github/dependabot.yml b/.github/dependabot.yml index b1fa2b9..383b109 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -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: + - "*" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bdf0c93..565ac95 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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: | @@ -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" @@ -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 diff --git a/.github/workflows/zizmor.yml b/.github/workflows/zizmor.yml new file mode 100644 index 0000000..530a4d9 --- /dev/null +++ b/.github/workflows/zizmor.yml @@ -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 diff --git a/ipython_pygments_lexers.py b/ipython_pygments_lexers.py index c655e23..c17c9b0 100644 --- a/ipython_pygments_lexers.py +++ b/ipython_pygments_lexers.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ Defines a variety of Pygments lexers for highlighting IPython code. @@ -36,25 +35,27 @@ 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, @@ -62,19 +63,17 @@ Operator, Other, Text, - Error, ) - line_re = re.compile(".*?\n") __all__ = [ + "IPyLexer", "IPython3Lexer", + "IPythonConsoleLexer", "IPythonLexer", "IPythonPartialTracebackLexer", "IPythonTracebackLexer", - "IPythonConsoleLexer", - "IPyLexer", ] @@ -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) diff --git a/pyproject.toml b/pyproject.toml index dfd5ad0..facce4f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" @@ -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"] diff --git a/test_ipython_pygments_lexers.py b/test_ipython_pygments_lexers.py index dd95359..cb43fc6 100644 --- a/test_ipython_pygments_lexers.py +++ b/test_ipython_pygments_lexers.py @@ -53,9 +53,7 @@ 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:] @@ -63,7 +61,8 @@ def test_shell_commands(): (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 @@ -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 @@ -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:] @@ -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]