Skip to content

Commit 86fd574

Browse files
authored
Merge pull request #1 from sudo-jarvis/main
Merge main into create-lexer
2 parents 25e2897 + 5216541 commit 86fd574

File tree

7 files changed

+34
-27
lines changed

7 files changed

+34
-27
lines changed

.github/workflows/ci.yml

+10-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@ name: CI
22

33
on:
44
push:
5+
branches-ignore:
6+
- "wip*"
7+
tags:
8+
- "v*"
59
pull_request:
610
release:
711
types: [published]
812
schedule:
913
# Daily at 7:37
1014
- cron: "37 7 * * *"
15+
workflow_dispatch:
1116

1217
env:
1318
PIP_DISABLE_PIP_VERSION_CHECK: "1"
@@ -19,7 +24,7 @@ jobs:
1924
outputs:
2025
noxenvs: ${{ steps.noxenvs-matrix.outputs.noxenvs }}
2126
steps:
22-
- uses: actions/checkout@v3
27+
- uses: actions/checkout@v4
2328
- name: Set up nox
2429
uses: wntrblm/[email protected]
2530
- id: noxenvs-matrix
@@ -43,7 +48,7 @@ jobs:
4348
posargs: coverage github
4449

4550
steps:
46-
- uses: actions/checkout@v3
51+
- uses: actions/checkout@v4
4752
- name: Install dependencies
4853
run: sudo apt-get update && sudo apt-get install -y libenchant-2-dev
4954
if: runner.os == 'Linux' && startsWith(matrix.noxenv, 'docs')
@@ -77,10 +82,11 @@ jobs:
7782
id-token: write
7883

7984
steps:
80-
- uses: actions/checkout@v3
85+
- uses: actions/checkout@v4
8186
- name: Set up Python
82-
uses: actions/setup-python@v4
87+
uses: actions/setup-python@v5
8388
with:
89+
cache: pip
8490
python-version: "3.x"
8591
- name: Install dependencies
8692
run: python -m pip install build

README.rst

+2-4
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
Introduction
2020
------------
2121

22-
`jsonschema-lexer` is a Python package that provides a JSON Schema lexer for syntax highlighting JSON Schema documents based on the `2020-12 dialect`.
23-
It utilizes Pygments, a syntax highlighting library, to tokenize JSON Schema documents according to the JSON Schema specification.
22+
`jsonschema-lexer` provides a lexer for syntax highlighting JSON Schema documents via `Pygments <https://pygments.org/>`_.
2423

2524
Usage
2625
-----
@@ -31,8 +30,7 @@ Here's a simple example:
3130

3231
.. code-block:: python
3332
34-
# Import the JSONSchemaLexer class from the package
35-
from jsonschema_lexer.lexer import JSONSchemaLexer
33+
from jsonschema_lexer import JSONSchemaLexer
3634
3735
from rich.console import Console
3836
from rich.syntax import Syntax

jsonschema_lexer/__init__.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
"""
2-
Provides the JSONSchema Lexer.
2+
A JSON Schema lexer for Pygments.
33
"""
4+
5+
from jsonschema_lexer._lexer import JSONSchemaLexer
6+
7+
__all__ = ["JSONSchemaLexer"]

jsonschema_lexer/lexer.py renamed to jsonschema_lexer/_lexer.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@
1212

1313
class JSONSchemaLexer(JsonLexer):
1414
"""
15-
For JSONSchema.
15+
A Pygments lexer for dialects of the JSON Schema specification.
1616
"""
1717

18-
name = "JSON Schema Lexer"
18+
name = "JSON Schema"
19+
url = "https://json-schema.org"
20+
aliases: ClassVar[list[str]] = ["jsonschema", "json-schema"]
21+
mimetypes: ClassVar[list[str]] = [
22+
"application/schema+json",
23+
"application/schema-instance+json",
24+
]
1925

2026
data_types: ClassVar[list[str]] = [
2127
"object",

jsonschema_lexer/tests/test_integration.py

+8-13
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
"""
2-
JSON Schema Lexer tests
2+
JSON Schema Lexer tests
33
"""
44

55
from pygments.token import Token
66
import pytest
77

8-
from jsonschema_lexer.lexer import JSONSchemaLexer
9-
10-
# Test helpers.
8+
from jsonschema_lexer import JSONSchemaLexer
119

1210

1311
@pytest.fixture()
@@ -26,27 +24,24 @@ def keywords():
2624

2725

2826
def assert_single_token(lexer, s, token):
29-
"""Show that a given string generates only one token."""
27+
"""
28+
Assert a given string generates only one token.
29+
"""
3030
tokens = list(lexer.get_tokens_unprocessed(s))
3131
assert len(tokens) == 1
3232
assert s == tokens[0][2]
3333
assert token == tokens[0][1]
3434

3535

3636
def assert_tokens(lexer, string, expected_tokens):
37-
"""Show that a given string generates the expected tokens."""
37+
"""
38+
Assert a given string generates the expected tokens.
39+
"""
3840
tokens = list(lexer.get_tokens_unprocessed(string))
3941
parsed_tokens = [t[1] for t in tokens]
4042
assert parsed_tokens == expected_tokens
4143

4244

43-
# Tests
44-
45-
46-
def test_it_imports():
47-
import jsonschema_lexer # noqa: F401
48-
49-
5045
def test_data_type_tokens(lexer, data_types):
5146
for data_type in data_types:
5247
assert_single_token(lexer, data_type, Token.Name.Decorator)

noxfile.py

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
ROOT = Path(__file__).parent
88
PYPROJECT = ROOT / "pyproject.toml"
9-
DOCS = ROOT / "docs"
109

1110
PACKAGE = ROOT / "jsonschema_lexer"
1211

pyproject.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ classifiers = [
3030
]
3131
dynamic = ["version"]
3232
dependencies = [
33-
"Pygments==2.17.2"
33+
"Pygments>=2.17.2"
3434
]
3535

3636
[project.urls]
@@ -137,5 +137,4 @@ from-first = true
137137

138138
[tool.ruff.lint.per-file-ignores]
139139
"noxfile.py" = ["ANN", "D100", "S101", "T201"]
140-
"docs/*" = ["ANN", "D", "INP001"]
141140
"jsonschema_lexer/tests/*" = ["ANN", "BLE001", "D", "PERF", "S"]

0 commit comments

Comments
 (0)