netherframe.codec.autoid 0.3.0__tar.gz → 0.5.0__tar.gz
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.
- {netherframe_codec_autoid-0.3.0 → netherframe_codec_autoid-0.5.0}/PKG-INFO +7 -2
- {netherframe_codec_autoid-0.3.0 → netherframe_codec_autoid-0.5.0}/netherframe/codec/autoid/codec_registration.py +1 -2
- {netherframe_codec_autoid-0.3.0 → netherframe_codec_autoid-0.5.0}/netherframe/codec/autoid/preprocessor.py +33 -13
- netherframe_codec_autoid-0.5.0/nf/codec/autoid/__init__.py +21 -0
- netherframe_codec_autoid-0.5.0/nf/codec/autoid/codec_registration.py +21 -0
- netherframe_codec_autoid-0.5.0/nf/codec/autoid/preprocessor.py +21 -0
- {netherframe_codec_autoid-0.3.0 → netherframe_codec_autoid-0.5.0}/pyproject.toml +11 -2
- {netherframe_codec_autoid-0.3.0 → netherframe_codec_autoid-0.5.0}/pyproject.toml.orig +10 -2
- netherframe_codec_autoid-0.3.0/data/purelib/nf_codec_autoid_autoregister.pth +0 -1
- netherframe_codec_autoid-0.3.0/nf/codec/autoid/__init__.py +0 -4
- netherframe_codec_autoid-0.3.0/nf/codec/autoid/codec_registration.py +0 -4
- netherframe_codec_autoid-0.3.0/nf/codec/autoid/preprocessor.py +0 -4
- {netherframe_codec_autoid-0.3.0 → netherframe_codec_autoid-0.5.0}/LICENSE +0 -0
- {netherframe_codec_autoid-0.3.0 → netherframe_codec_autoid-0.5.0}/README.md +0 -0
- {netherframe_codec_autoid-0.3.0 → netherframe_codec_autoid-0.5.0}/data/purelib/nf_codec_autoid_autoregister.start +0 -0
- {netherframe_codec_autoid-0.3.0 → netherframe_codec_autoid-0.5.0}/netherframe/codec/autoid/__init__.py +0 -0
- {netherframe_codec_autoid-0.3.0 → netherframe_codec_autoid-0.5.0}/netherframe/codec/autoid/py.typed +0 -0
- {netherframe_codec_autoid-0.3.0 → netherframe_codec_autoid-0.5.0}/nf/codec/autoid/py.typed +0 -0
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: netherframe.codec.autoid
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: Auto-ID codec and preprocessor for Netherframe
|
|
5
|
+
Author: Sourabh Cheedella
|
|
6
|
+
Author-email: Sourabh Cheedella <cheedella.sourabh@gmail.com>
|
|
5
7
|
License-Expression: MIT
|
|
6
8
|
License-File: LICENSE
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
7
12
|
Requires-Dist: libcst>=1.9.0
|
|
8
|
-
Requires-Python: >=3.
|
|
13
|
+
Requires-Python: >=3.15
|
|
9
14
|
Project-URL: Homepage, https://netherframe.arsenal.sh
|
|
10
15
|
Project-URL: Repository, https://github.com/arsenal-sh/netherframe
|
|
11
16
|
Description-Content-Type: text/markdown
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"""Register the nf_autoid source codec without importing the preprocessor.
|
|
2
2
|
|
|
3
|
-
This module is loaded by a .start entry point (
|
|
4
|
-
at every interpreter start, so it must stay cheap: libcst and the preprocessor
|
|
3
|
+
This module is loaded by a .start entry point (PEP 829) at every interpreter start, so it must stay cheap: libcst and the preprocessor
|
|
5
4
|
load only when a source file actually declares ``# coding: nf_autoid``.
|
|
6
5
|
"""
|
|
7
6
|
|
|
@@ -5,8 +5,8 @@ injects variable names into Netherframe construct instantiations using LibCST
|
|
|
5
5
|
and registers a custom codec for transparent preprocessing during imports.
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
-
from collections.abc import Buffer
|
|
9
8
|
import codecs
|
|
9
|
+
from collections.abc import Buffer
|
|
10
10
|
|
|
11
11
|
import libcst as cst
|
|
12
12
|
|
|
@@ -19,18 +19,24 @@ class LibCSTTransformer(cst.CSTTransformer):
|
|
|
19
19
|
def __init__(self) -> None:
|
|
20
20
|
super().__init__()
|
|
21
21
|
|
|
22
|
+
def _is_bind_name(self, expr: cst.BaseExpression) -> bool:
|
|
23
|
+
if isinstance(expr, cst.Name):
|
|
24
|
+
return expr.value == "Bind"
|
|
25
|
+
if isinstance(expr, cst.Attribute):
|
|
26
|
+
return expr.attr.value == "Bind"
|
|
27
|
+
return False
|
|
28
|
+
|
|
22
29
|
def _has_bind_annotation(self, annotation: cst.Annotation | None) -> bool:
|
|
23
|
-
"""Check if annotation indicates Bind."""
|
|
30
|
+
"""Check if annotation indicates Bind (including qualified forms like nf.Bind or Bind[T])."""
|
|
24
31
|
if not annotation:
|
|
25
32
|
return False
|
|
26
33
|
|
|
27
34
|
ann = annotation.annotation
|
|
28
35
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return ann.value.value == "Bind"
|
|
36
|
+
if self._is_bind_name(ann):
|
|
37
|
+
return True
|
|
38
|
+
if isinstance(ann, cst.Subscript) and self._is_bind_name(ann.value):
|
|
39
|
+
return True
|
|
34
40
|
|
|
35
41
|
return False
|
|
36
42
|
|
|
@@ -262,6 +268,8 @@ class LibCSTTransformer(cst.CSTTransformer):
|
|
|
262
268
|
# So we don't wrap these automatically
|
|
263
269
|
return updated_node
|
|
264
270
|
|
|
271
|
+
_NON_CONSTRUCT_BUILTINS = frozenset({"open", "dict", "list", "set", "tuple", "str", "int", "float", "bool", "bytes", "object", "range", "enumerate", "zip", "map", "filter", "iter"})
|
|
272
|
+
|
|
265
273
|
def leave_With(self, original_node: cst.With, updated_node: cst.With) -> cst.With:
|
|
266
274
|
"""Transform context manager assignments when BindContext is present."""
|
|
267
275
|
has_bind_context = any(self._is_bind_context(item.item) for item in updated_node.items)
|
|
@@ -270,11 +278,15 @@ class LibCSTTransformer(cst.CSTTransformer):
|
|
|
270
278
|
|
|
271
279
|
new_items = []
|
|
272
280
|
for item in updated_node.items:
|
|
273
|
-
if item.asname and isinstance(item.item, cst.Call):
|
|
281
|
+
if item.asname and isinstance(item.item, cst.Call) and not self._is_bind_context(item.item):
|
|
282
|
+
callee = item.item.func
|
|
283
|
+
if isinstance(callee, cst.Name) and callee.value in self._NON_CONSTRUCT_BUILTINS:
|
|
284
|
+
new_items.append(item)
|
|
285
|
+
continue
|
|
274
286
|
var_name = self._extract_asname(item.asname)
|
|
275
287
|
if var_name:
|
|
276
|
-
|
|
277
|
-
|
|
288
|
+
new_items.append(item.with_changes(item=self._inject_nf_id(item.item, var_name)))
|
|
289
|
+
continue
|
|
278
290
|
new_items.append(item)
|
|
279
291
|
|
|
280
292
|
return updated_node.with_changes(items=new_items)
|
|
@@ -321,9 +333,17 @@ def preprocess_source(source: str) -> str:
|
|
|
321
333
|
|
|
322
334
|
# Return the modified code
|
|
323
335
|
return modified_tree.code
|
|
324
|
-
except
|
|
325
|
-
#
|
|
326
|
-
|
|
336
|
+
except cst.ParserSyntaxError:
|
|
337
|
+
# Return original source so Python's own parser raises a SyntaxError with exact location.
|
|
338
|
+
return source
|
|
339
|
+
except Exception as exc:
|
|
340
|
+
import warnings
|
|
341
|
+
|
|
342
|
+
warnings.warn(
|
|
343
|
+
f"nf_autoid preprocessor failed to transform source ({type(exc).__name__}: {exc}); returning unmodified source",
|
|
344
|
+
RuntimeWarning,
|
|
345
|
+
stacklevel=2,
|
|
346
|
+
)
|
|
327
347
|
return source
|
|
328
348
|
|
|
329
349
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Generated nf.* alias shim (netherframe.generation.nf_alias_shims); do not edit.
|
|
2
|
+
"""Type-checker view of ``nf.codec.autoid``; at runtime it is ``netherframe.codec.autoid`` itself."""
|
|
3
|
+
|
|
4
|
+
from typing import TYPE_CHECKING
|
|
5
|
+
|
|
6
|
+
if TYPE_CHECKING:
|
|
7
|
+
from netherframe.codec.autoid import * # noqa: F403
|
|
8
|
+
else:
|
|
9
|
+
# Runs only without the import hook (python -S, zipimport, some bundlers): install it, so
|
|
10
|
+
# nf.* imports from now on, this module's submodules included, return the netherframe.*
|
|
11
|
+
# modules, and return the netherframe.* module for this import too.
|
|
12
|
+
import importlib as _importlib
|
|
13
|
+
import sys as _sys
|
|
14
|
+
|
|
15
|
+
try:
|
|
16
|
+
import netherframe_nf_alias as _nf_alias
|
|
17
|
+
except ImportError: # netherframe.core, which ships the hook, is not installed
|
|
18
|
+
pass
|
|
19
|
+
else:
|
|
20
|
+
_nf_alias.install()
|
|
21
|
+
_sys.modules[__name__] = _importlib.import_module("netherframe.codec.autoid")
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Generated nf.* alias shim (netherframe.generation.nf_alias_shims); do not edit.
|
|
2
|
+
"""Type-checker view of ``nf.codec.autoid.codec_registration``; at runtime it is ``netherframe.codec.autoid.codec_registration`` itself."""
|
|
3
|
+
|
|
4
|
+
from typing import TYPE_CHECKING
|
|
5
|
+
|
|
6
|
+
if TYPE_CHECKING:
|
|
7
|
+
from netherframe.codec.autoid.codec_registration import * # noqa: F403
|
|
8
|
+
else:
|
|
9
|
+
# Runs only without the import hook (python -S, zipimport, some bundlers): install it, so
|
|
10
|
+
# nf.* imports from now on, this module's submodules included, return the netherframe.*
|
|
11
|
+
# modules, and return the netherframe.* module for this import too.
|
|
12
|
+
import importlib as _importlib
|
|
13
|
+
import sys as _sys
|
|
14
|
+
|
|
15
|
+
try:
|
|
16
|
+
import netherframe_nf_alias as _nf_alias
|
|
17
|
+
except ImportError: # netherframe.core, which ships the hook, is not installed
|
|
18
|
+
pass
|
|
19
|
+
else:
|
|
20
|
+
_nf_alias.install()
|
|
21
|
+
_sys.modules[__name__] = _importlib.import_module("netherframe.codec.autoid.codec_registration")
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Generated nf.* alias shim (netherframe.generation.nf_alias_shims); do not edit.
|
|
2
|
+
"""Type-checker view of ``nf.codec.autoid.preprocessor``; at runtime it is ``netherframe.codec.autoid.preprocessor`` itself."""
|
|
3
|
+
|
|
4
|
+
from typing import TYPE_CHECKING
|
|
5
|
+
|
|
6
|
+
if TYPE_CHECKING:
|
|
7
|
+
from netherframe.codec.autoid.preprocessor import * # noqa: F403
|
|
8
|
+
else:
|
|
9
|
+
# Runs only without the import hook (python -S, zipimport, some bundlers): install it, so
|
|
10
|
+
# nf.* imports from now on, this module's submodules included, return the netherframe.*
|
|
11
|
+
# modules, and return the netherframe.* module for this import too.
|
|
12
|
+
import importlib as _importlib
|
|
13
|
+
import sys as _sys
|
|
14
|
+
|
|
15
|
+
try:
|
|
16
|
+
import netherframe_nf_alias as _nf_alias
|
|
17
|
+
except ImportError: # netherframe.core, which ships the hook, is not installed
|
|
18
|
+
pass
|
|
19
|
+
else:
|
|
20
|
+
_nf_alias.install()
|
|
21
|
+
_sys.modules[__name__] = _importlib.import_module("netherframe.codec.autoid.preprocessor")
|
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "netherframe.codec.autoid"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.5.0"
|
|
4
4
|
description = "Auto-ID codec and preprocessor for Netherframe"
|
|
5
5
|
readme = "README.md"
|
|
6
|
-
requires-python = ">=3.
|
|
6
|
+
requires-python = ">=3.15"
|
|
7
|
+
classifiers = [
|
|
8
|
+
"Development Status :: 4 - Beta",
|
|
9
|
+
"Intended Audience :: Developers",
|
|
10
|
+
"Programming Language :: Python :: 3.15",
|
|
11
|
+
]
|
|
7
12
|
license = "MIT"
|
|
8
13
|
license-files = ["LICENSE"]
|
|
9
14
|
dependencies = ["libcst>=1.9.0"]
|
|
10
15
|
|
|
16
|
+
[[project.authors]]
|
|
17
|
+
name = "Sourabh Cheedella"
|
|
18
|
+
email = "cheedella.sourabh@gmail.com"
|
|
19
|
+
|
|
11
20
|
[project.urls]
|
|
12
21
|
Homepage = "https://netherframe.arsenal.sh"
|
|
13
22
|
Repository = "https://github.com/arsenal-sh/netherframe"
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "netherframe.codec.autoid"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.5.0"
|
|
4
4
|
description = "Auto-ID codec and preprocessor for Netherframe"
|
|
5
|
+
authors = [
|
|
6
|
+
{name = "Sourabh Cheedella", email = "cheedella.sourabh@gmail.com"},
|
|
7
|
+
]
|
|
5
8
|
readme = "README.md"
|
|
6
|
-
requires-python = ">=3.
|
|
9
|
+
requires-python = ">=3.15"
|
|
10
|
+
classifiers = [
|
|
11
|
+
"Development Status :: 4 - Beta",
|
|
12
|
+
"Intended Audience :: Developers",
|
|
13
|
+
"Programming Language :: Python :: 3.15",
|
|
14
|
+
]
|
|
7
15
|
license = "MIT"
|
|
8
16
|
license-files = ["LICENSE"]
|
|
9
17
|
dependencies = [
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import netherframe.codec.autoid.codec_registration
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
# Generated nf.* alias shim (netherframe.generation.nf_alias_shims); do not edit.
|
|
2
|
-
"""Type-checker view of ``nf.codec.autoid.codec_registration``; at runtime it is ``netherframe.codec.autoid.codec_registration`` itself."""
|
|
3
|
-
|
|
4
|
-
from netherframe.codec.autoid.codec_registration import * # noqa: F403
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
# Generated nf.* alias shim (netherframe.generation.nf_alias_shims); do not edit.
|
|
2
|
-
"""Type-checker view of ``nf.codec.autoid.preprocessor``; at runtime it is ``netherframe.codec.autoid.preprocessor`` itself."""
|
|
3
|
-
|
|
4
|
-
from netherframe.codec.autoid.preprocessor import * # noqa: F403
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{netherframe_codec_autoid-0.3.0 → netherframe_codec_autoid-0.5.0}/netherframe/codec/autoid/py.typed
RENAMED
|
File without changes
|
|
File without changes
|