Skip to content

Commit 667721a

Browse files
Add packaging setup (#3)
* delete .github/workflows directory * task: create pyproject.toml * split-up lexer and style * fix module imports * fix `wheel` build target This has started raising an error since Hatchling v1.19.0
1 parent b8d2e31 commit 667721a

5 files changed

Lines changed: 73 additions & 84 deletions

File tree

.github/workflows/pypi-package.yml

Lines changed: 0 additions & 44 deletions
This file was deleted.

gdscript.py renamed to gdscript_lexer.py

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1-
from pygments import highlight, lexers
2-
from pygments.style import Style
3-
from pygments.formatters import HtmlFormatter
41
from pygments.lexer import RegexLexer, include, bygroups, words, combined
52
from pygments.token import (
63
Keyword,
74
Name,
85
Comment,
96
String,
10-
Error,
117
Number,
128
Operator,
139
Whitespace,
1410
Punctuation,
1511
)
1612

17-
__all__ = ["GDScriptLexer", "GDScriptStyle"]
18-
1913
class GDScriptLexer(RegexLexer):
2014
"""
2115
For GDScript source code.
@@ -181,36 +175,4 @@ def innerstring_rules(ttype):
181175
include("name"),
182176
include("numbers"),
183177
],
184-
}
185-
186-
class GDScriptStyle(Style):
187-
background_color = "#1d2229"
188-
189-
styles = {
190-
Whitespace: "#bbbbbb", # for whitespace
191-
Comment: "#cdcfd2", # any kind of comments
192-
Punctuation: "#abc9ff", # punctuation (e.g. [!.,])
193-
194-
Keyword: "#ff7085", # Any kind of keyword; especially if it doesn’t match any of the subtypes
195-
196-
Operator: "#abc9ff", # For any punctuation operator (e.g. +, -)
197-
Operator.Word: "#ff7085", # For any operator that is a word (e.g. not, in)
198-
199-
Name.Builtin: "#42ffc2", # names that are available in the global namespace (NOT USED)
200-
Name.Builtin.Type: "#42ffc2", # types that are available in the global namespace
201-
Name.Builtin.Function: "#a3a3f5", # functions that are available in the global namespace
202-
Name.Function: "#57b3ff", # function names
203-
Name.Class: "#42ffc2", # class names / declarations
204-
Name.Variable: "#bce0ff", # variable names
205-
Name.Constant: "#bce0ff", # constant names
206-
Name.Decorator: "#ffb373", # decorators / annotations (TODO)
207-
208-
String: "#ffeda1", # string literals
209-
String.Doc: "#ffeda1", # doc string literal
210-
String.Interpol: "#ffeda1", # interpolated parts (e.g. %s)
211-
String.Escape: "#ffeda1", # escape sequences
212-
213-
Number: "#a1ffe0", # number literal
214-
215-
Error: "border:#FF0000" # represents lexer errors (very useful for debugging)
216-
}
178+
}

gdscript_style.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from pygments.style import Style
2+
from pygments.token import (
3+
Keyword,
4+
Name,
5+
Comment,
6+
String,
7+
Error,
8+
Number,
9+
Operator,
10+
Whitespace,
11+
Punctuation,
12+
)
13+
14+
15+
class GDScriptStyle(Style):
16+
background_color = "#1d2229"
17+
18+
styles = {
19+
Whitespace: "#bbbbbb", # for whitespace
20+
Comment: "#cdcfd2", # any kind of comments
21+
Punctuation: "#abc9ff", # punctuation (e.g. [!.,])
22+
23+
Keyword: "#ff7085", # Any kind of keyword; especially if it doesn’t match any of the subtypes
24+
25+
Operator: "#abc9ff", # For any punctuation operator (e.g. +, -)
26+
Operator.Word: "#ff7085", # For any operator that is a word (e.g. not, in)
27+
28+
Name.Builtin: "#42ffc2", # names that are available in the global namespace (NOT USED)
29+
Name.Builtin.Type: "#42ffc2", # types that are available in the global namespace
30+
Name.Builtin.Function: "#a3a3f5", # functions that are available in the global namespace
31+
Name.Function: "#57b3ff", # function names
32+
Name.Class: "#42ffc2", # class names / declarations
33+
Name.Variable: "#bce0ff", # variable names
34+
Name.Constant: "#bce0ff", # constant names
35+
Name.Decorator: "#ffb373", # decorators / annotations (TODO)
36+
37+
String: "#ffeda1", # string literals
38+
String.Doc: "#ffeda1", # doc string literal
39+
String.Interpol: "#ffeda1", # interpolated parts (e.g. %s)
40+
String.Escape: "#ffeda1", # escape sequences
41+
42+
Number: "#a1ffe0", # number literal
43+
44+
Error: "border:#FF0000" # represents lexer errors (very useful for debugging)
45+
}

pyproject.toml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[build-system]
2+
requires = ["hatchling"]
3+
build-backend = "hatchling.build"
4+
5+
[tool.hatch.build.targets.wheel]
6+
packages = ["."]
7+
8+
[project]
9+
name = "pygments-gdscript"
10+
description = "An updated Pygments GDScript lexer"
11+
version = "1.0.0"
12+
requires-python = ">=3.8" # enforced due to Pygments
13+
dependencies = ["pygments"]
14+
15+
[project.urls]
16+
Repository = "https://github.com/GodotModding/pygments-gdscript"
17+
Issues = "https://github.com/GodotModding/pygments-gdscript/issues"
18+
19+
# extend Pygments without hacking the sources
20+
# see: https://pygments.org/docs/plugins/
21+
[project.entry-points."pygments.lexers"]
22+
gdscript-lexer = "gdscript_lexer:GDScriptLexer"
23+
24+
[project.entry-points."pygments.style"]
25+
gdscript-style = "gdscript_style:GDScriptStyle"

test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from pygments import highlight
22
from pygments.formatters import HtmlFormatter
3-
from gdscript import GDScriptLexer, GDScriptStyle
3+
from gdscript_lexer import GDScriptLexer
4+
from gdscript_style import GDScriptStyle
45

56
with open("test.gd") as f:
67
code = f.read()

0 commit comments

Comments
 (0)