ZedScripts 0.0.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ __version__ = "0.0.1"
ZedScripts/__init__.py ADDED
@@ -0,0 +1,38 @@
1
+ import os
2
+ import logging
3
+ from pathlib import Path
4
+
5
+ IS_DEBUG = os.getenv("ZEDSCRIPTS_DEBUG_MODE") == "1"
6
+
7
+ ZEDSCRIPT_CACHE_DIR = Path.home() / ".zedscripts"
8
+ """
9
+ Cache directory to hold various information related to ZedScripts.
10
+ """
11
+ ZEDSCRIPT_CACHE_DIR.mkdir(parents=True, exist_ok=True)
12
+
13
+ # config files
14
+ CONFIGURATION_FILE_NAME = ".zedscripts.json"
15
+ GLOBAL_CONFIGURATION_FILE = (ZEDSCRIPT_CACHE_DIR / CONFIGURATION_FILE_NAME).resolve()
16
+
17
+ # setup the logger
18
+ log_file = ZEDSCRIPT_CACHE_DIR / "server.log"
19
+
20
+ level = logging.DEBUG if IS_DEBUG else logging.INFO
21
+ logging.basicConfig(
22
+ filename=log_file,
23
+ level=level,
24
+ format="%(asctime)s %(levelname)s %(message)s",
25
+ filemode="w",
26
+ # force=True,
27
+ )
28
+
29
+ logging.info("ZedScripts logger initialized. Debug mode: %s", IS_DEBUG)
30
+
31
+ IDENTIFIER = "ZedScripts"
32
+ SOURCE = IDENTIFIER
33
+
34
+ SCRIPTS_DATA_MANIFEST = "https://raw.githubusercontent.com/PZ-Wiki-Modding/pz-scripts-data/refs/heads/main/manifest.json"
35
+ SCRIPTS_BLOCKS_DATA_LINK = "https://raw.githubusercontent.com/PZ-Wiki-Modding/pz-scripts-data/refs/tags/{best_tag}/out/scriptsBlocks.json"
36
+ ROOTS_DATA_LINK = "https://raw.githubusercontent.com/PZ-Wiki-Modding/pz-scripts-data/refs/tags/{best_tag}/out/roots.json"
37
+
38
+ SCRIPTSDOCS_LINK = "https://pz-wiki-modding.github.io/PZ-API-Docs/scripts/"
@@ -0,0 +1,165 @@
1
+ import enum
2
+ from typing import Any
3
+
4
+ from lsprotocol.types import DiagnosticSeverity, DiagnosticTag
5
+
6
+ from ..enums.SyntaxErrorType import SyntaxErrorType
7
+ from ..providers.diagnostics import DiagnosticDefinition
8
+
9
+
10
+ class DiagnosticType(enum.Enum):
11
+ @classmethod
12
+ def _missing_(cls, value: Any) -> 'DiagnosticType | None':
13
+ if isinstance(value, SyntaxErrorType):
14
+ return cls["PARSER_" + value.name]
15
+ return None
16
+
17
+ # syntax diagnostics
18
+ PARSER_TOO_MANY_CLOSING_BRACKETS = enum.auto()
19
+ PARSER_BLOCK_MISSING_TYPE = enum.auto()
20
+ PARSER_BLOCK_NOT_CLOSED = enum.auto()
21
+ PARSER_UNPARSED_TOKENS = enum.auto()
22
+
23
+ # block diagnostics
24
+ BLOCK_UNKNOWN_BLOCK = enum.auto()
25
+
26
+ # ID related diagnostics
27
+ BLOCK_UNEXPECTED_ID = enum.auto()
28
+ BLOCK_MISSING_ID = enum.auto()
29
+ BLOCK_HAS_ID_IN_PARENT = enum.auto()
30
+ BLOCK_ID_CANNOT_CONTAIN_SPACES = enum.auto()
31
+ BLOCK_INVALID_ID = enum.auto()
32
+ BLOCK_FORBIDDEN_ID = enum.auto()
33
+
34
+ # parameters diagnostics
35
+ VALUE_UNKNOWN_PARAMETER = enum.auto()
36
+ VALUE_DEPRECATED_REPLACEMENT_VERSION = enum.auto()
37
+ VALUE_DEPRECATED_REPLACEMENT = enum.auto()
38
+ VALUE_DEPRECATED_VERSION = enum.auto()
39
+ VALUE_DEPRECATED = enum.auto()
40
+ VALUE_DUPLICATE = enum.auto()
41
+ VALUE_MISSING = enum.auto()
42
+ VALUE_FORBIDDEN = enum.auto()
43
+ VALUE_INVALID_TYPE = enum.auto()
44
+ VALUE_INVALID_OBJECT_FORMAT = enum.auto()
45
+ VALUE_INVALID_OBJECT_KEY_TYPE = enum.auto()
46
+ VALUE_INVALID_OBJECT_VALUE_TYPE = enum.auto()
47
+ VALUE_WRONGLY_FORMATTED_KEY_VALUE_PAIR = enum.auto()
48
+ VALUE_WITH_NEWLINE = enum.auto()
49
+ VALUE_INVALID_BLOCK_REFERENCE = enum.auto()
50
+ VALUE_CANNOT_PROVIDE_MODULE = enum.auto()
51
+ VALUE_BLOCK_REF_CANNOT_BE_EMPTY = enum.auto()
52
+ VALUE_UNMATCHED_BLOCK_REF = enum.auto()
53
+ VALUE_MULTIPLE_BLOCK_REFS = enum.auto()
54
+
55
+
56
+ # syntax diagnostics
57
+ DiagnosticDefinition(DiagnosticType.PARSER_TOO_MANY_CLOSING_BRACKETS,
58
+ DiagnosticSeverity.Error)
59
+ DiagnosticDefinition(DiagnosticType.PARSER_BLOCK_MISSING_TYPE,
60
+ DiagnosticSeverity.Error)
61
+ DiagnosticDefinition(DiagnosticType.PARSER_BLOCK_NOT_CLOSED,
62
+ DiagnosticSeverity.Warning)
63
+ DiagnosticDefinition(DiagnosticType.PARSER_UNPARSED_TOKENS,
64
+ DiagnosticSeverity.Error)
65
+
66
+ # block diagnostics
67
+ DiagnosticDefinition(DiagnosticType.BLOCK_UNKNOWN_BLOCK,
68
+ DiagnosticSeverity.Error,
69
+ args={"type": str},
70
+ tags=[DiagnosticTag.Unnecessary])
71
+
72
+ # ID related diagnostics
73
+ DiagnosticDefinition(DiagnosticType.BLOCK_UNEXPECTED_ID,
74
+ DiagnosticSeverity.Error,
75
+ args={"type": str, "id": str},
76
+ tags=[DiagnosticTag.Unnecessary])
77
+ DiagnosticDefinition(DiagnosticType.BLOCK_MISSING_ID,
78
+ DiagnosticSeverity.Error,
79
+ args={"type": str, "id": str})
80
+ DiagnosticDefinition(DiagnosticType.BLOCK_HAS_ID_IN_PARENT,
81
+ DiagnosticSeverity.Error,
82
+ args={"type": str, "parent_type": str, "invalid_blocks": list},
83
+ tags=[DiagnosticTag.Unnecessary])
84
+ DiagnosticDefinition(DiagnosticType.BLOCK_ID_CANNOT_CONTAIN_SPACES,
85
+ DiagnosticSeverity.Error,
86
+ args={"type": str, "id": str})
87
+ DiagnosticDefinition(DiagnosticType.BLOCK_INVALID_ID,
88
+ DiagnosticSeverity.Error,
89
+ args={"type": str, "id": str, "validIDs": list})
90
+ DiagnosticDefinition(DiagnosticType.BLOCK_FORBIDDEN_ID,
91
+ DiagnosticSeverity.Error,
92
+ args={"type": str, "id": str, "forbiddenIDs": list})
93
+
94
+ # parameter diagnostics
95
+ DiagnosticDefinition(DiagnosticType.VALUE_UNKNOWN_PARAMETER,
96
+ DiagnosticSeverity.Hint,
97
+ args={"type": str, "key": str},
98
+ tags=[DiagnosticTag.Unnecessary])
99
+ DiagnosticDefinition(DiagnosticType.VALUE_DEPRECATED_REPLACEMENT_VERSION,
100
+ DiagnosticSeverity.Warning,
101
+ args={"description": str, "replacement": str, "version": str},
102
+ tags=[DiagnosticTag.Deprecated])
103
+ DiagnosticDefinition(DiagnosticType.VALUE_DEPRECATED_REPLACEMENT,
104
+ DiagnosticSeverity.Warning,
105
+ args={"description": str, "replacement": str},
106
+ tags=[DiagnosticTag.Deprecated])
107
+ DiagnosticDefinition(DiagnosticType.VALUE_DEPRECATED_VERSION,
108
+ DiagnosticSeverity.Warning,
109
+ args={"description": str, "version": str},
110
+ tags=[DiagnosticTag.Deprecated])
111
+ DiagnosticDefinition(DiagnosticType.VALUE_DEPRECATED,
112
+ DiagnosticSeverity.Warning,
113
+ args={"description": str},
114
+ tags=[DiagnosticTag.Deprecated])
115
+ DiagnosticDefinition(DiagnosticType.VALUE_DUPLICATE,
116
+ DiagnosticSeverity.Warning,
117
+ args={"type": str, "key": str})
118
+ DiagnosticDefinition(DiagnosticType.VALUE_MISSING,
119
+ DiagnosticSeverity.Warning,
120
+ args={"type": str, "key": str})
121
+ DiagnosticDefinition(DiagnosticType.VALUE_FORBIDDEN,
122
+ DiagnosticSeverity.Warning,
123
+ args={"type": str, "key": str, "forbidden_values": list, "accepted_values": list})
124
+ DiagnosticDefinition(DiagnosticType.VALUE_INVALID_TYPE,
125
+ DiagnosticSeverity.Error,
126
+ args={"key": str, "value": str, "expected_type": str, "actual_type": str})
127
+ DiagnosticDefinition(DiagnosticType.VALUE_INVALID_OBJECT_FORMAT,
128
+ DiagnosticSeverity.Error,
129
+ args={"type": str, "key": str, "key_value_separator": str})
130
+ DiagnosticDefinition(DiagnosticType.VALUE_INVALID_OBJECT_KEY_TYPE,
131
+ DiagnosticSeverity.Error,
132
+ args={"obj_key": str, "key": str, "expected_type": str, "actual_type": str})
133
+ DiagnosticDefinition(DiagnosticType.VALUE_INVALID_OBJECT_VALUE_TYPE,
134
+ DiagnosticSeverity.Error,
135
+ args={"obj_value": str, "key": str, "expected_type": str, "actual_type": str})
136
+ DiagnosticDefinition(DiagnosticType.VALUE_WRONGLY_FORMATTED_KEY_VALUE_PAIR,
137
+ DiagnosticSeverity.Warning,
138
+ args={"type": str, "key": str, "value": str})
139
+ DiagnosticDefinition(DiagnosticType.VALUE_WITH_NEWLINE,
140
+ DiagnosticSeverity.Information,
141
+ args={"type": str, "key": str, "value": str})
142
+ DiagnosticDefinition(DiagnosticType.VALUE_INVALID_BLOCK_REFERENCE,
143
+ DiagnosticSeverity.Error,
144
+ args={"value": str})
145
+ DiagnosticDefinition(DiagnosticType.VALUE_CANNOT_PROVIDE_MODULE,
146
+ DiagnosticSeverity.Error,
147
+ args={"value": str, "module": str})
148
+ DiagnosticDefinition(DiagnosticType.VALUE_BLOCK_REF_CANNOT_BE_EMPTY,
149
+ DiagnosticSeverity.Error,
150
+ args={"value": str})
151
+ DiagnosticDefinition(DiagnosticType.VALUE_UNMATCHED_BLOCK_REF,
152
+ DiagnosticSeverity.Error,
153
+ args={"value": str, "parameter": str, "expected_block": str})
154
+ DiagnosticDefinition(DiagnosticType.VALUE_MULTIPLE_BLOCK_REFS,
155
+ DiagnosticSeverity.Error,
156
+ args={"value": str, "parameter": str, "expected_block": str})
157
+
158
+
159
+ # ensure that all diagnostic types have a corresponding definition
160
+ for diagnostic_type in DiagnosticType:
161
+ assert diagnostic_type in DiagnosticDefinition.by_type, f"Missing definition for diagnostic type: {diagnostic_type}"
162
+
163
+
164
+
165
+
@@ -0,0 +1,7 @@
1
+ import enum
2
+
3
+ class SyntaxErrorType(enum.Enum):
4
+ TOO_MANY_CLOSING_BRACKETS = enum.auto()
5
+ BLOCK_MISSING_TYPE = enum.auto()
6
+ BLOCK_NOT_CLOSED = enum.auto()
7
+ UNPARSED_TOKENS = enum.auto()
@@ -0,0 +1,33 @@
1
+ import enum
2
+
3
+
4
+ class WorkspaceType(enum.StrEnum):
5
+ """Represents different types of workspace folders."""
6
+ LIBRARY = enum.auto()
7
+ """A library defined by the user to reference things from.
8
+ No validation should be performed on it."""
9
+ PROJECT = enum.auto()
10
+ """A workspace folder."""
11
+ SOLITARY = enum.auto()
12
+ """Files that are not opened as part of a workspace
13
+ or library but should still be validated.
14
+
15
+ This workspace always exists and just holds solitary files."""
16
+
17
+ class VersionType(enum.StrEnum):
18
+ """Represents different version types the workspace folders follow."""
19
+ PRE_42 = enum.auto()
20
+ """Modded pre-42 folder structure."""
21
+ VERSIONING = enum.auto()
22
+ """Modded versioning folder.
23
+
24
+ https://pzwiki.net/wiki/Mod_structure#Common_and_versioning_folders"""
25
+ COMMON = enum.auto()
26
+ """Modded folder `common`.
27
+
28
+ https://pzwiki.net/wiki/Mod_structure#Common_and_versioning_folders"""
29
+ OTHER = enum.auto()
30
+ """Other uncategorized version."""
31
+ BASE_GAME = enum.auto()
32
+ """Base game files (e.g., `ProjectZomboid/media`)."""
33
+
@@ -0,0 +1,82 @@
1
+ import logging
2
+ import enum
3
+ from pathlib import Path
4
+ from typing import Optional
5
+ from pydantic import BaseModel, Field
6
+
7
+ from ..scripts.version import DataVersion
8
+
9
+
10
+ class DatasetTag(enum.Enum):
11
+ LATEST = "latest"
12
+ STABLE = "stable"
13
+
14
+
15
+
16
+ class ReleaseModel(BaseModel):
17
+ major: int = Field(
18
+ description="Build game version number.",
19
+ ge=42,
20
+ )
21
+ minor: int = Field(
22
+ description="Minor game version number.",
23
+ ge=0,
24
+ )
25
+ patch: int = Field(
26
+ description="Patch game version number.",
27
+ ge=0,
28
+ )
29
+ version: Optional[int] = Field(
30
+ description="Dataset version number for the provided Build release (major.minor.patch). This is incremented whenever the dataset for a specific version is updated.",
31
+ default=None,
32
+ ge=0,
33
+ )
34
+
35
+ class DatasetModel(BaseModel):
36
+ release: Optional[ReleaseModel] = Field(
37
+ description="Provides a configuration for the dataset version to use for validation. This overrides the `latest` and `stable` fields if set.",
38
+ default=None,
39
+ )
40
+ latest: Optional[bool] = Field(
41
+ description="Indicates whether to use the latest dataset version for validation. This is ignored if `release` is set. Overrides the `stable` field if set.",
42
+ default=False,
43
+ )
44
+ stable: Optional[bool] = Field(
45
+ description="Provides a configuration for the stable dataset version to use for validation. Ignored if `release` or `latest` is set.",
46
+ default=True,
47
+ )
48
+
49
+ def to_data_version(self) -> DataVersion | DatasetTag:
50
+ if self.release is None:
51
+ if self.latest:
52
+ return DatasetTag.LATEST
53
+ if self.stable:
54
+ return DatasetTag.STABLE
55
+ logging.warning("No dataset version specified, defaulting to 'stable'.")
56
+ return DatasetTag.STABLE
57
+ from ..scripts.dataset import Manifest
58
+ try:
59
+ return Manifest.from_release_model(self.release)
60
+ except Exception as e:
61
+ logging.error(f"Failed to get data version from release model: {e}. Defaulting to 'stable'.")
62
+ return DatasetTag.STABLE
63
+
64
+
65
+ class ConfigurationModel(BaseModel):
66
+ """Represents the content of the configuration files for workspace environments."""
67
+ dataset: DatasetModel = Field(
68
+ description="Provides configuration for the dataset version to use for diagnostics.",
69
+ default_factory=DatasetModel,
70
+ )
71
+ libraries: set[Path] = Field(
72
+ description="Set of library folders to reference. Usually this should contain the base game folder.",
73
+ default_factory=set,
74
+ )
75
+ ignored: set[str] = Field(
76
+ description="Regex patterns for files and folders to ignore in the workspace.",
77
+ default=set([
78
+ r"tileGeometry\.txt",
79
+ r"tileDepthTextureAssignments\.txt",
80
+ r".+\.tiles\.txt"
81
+ ]),
82
+ )