makora 0.0.0.dev1__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.
makora/__init__.py ADDED
@@ -0,0 +1,53 @@
1
+ from .utils import (
2
+ static_property,
3
+ add_module_properties,
4
+ )
5
+
6
+
7
+ def _get_version() -> str:
8
+ from . import version
9
+
10
+ return version.version
11
+
12
+
13
+ def _get_has_repo() -> bool:
14
+ from . import version
15
+
16
+ return version.has_repo
17
+
18
+
19
+ def _get_repo() -> str:
20
+ from . import version
21
+
22
+ return version.repo
23
+
24
+
25
+ def _get_commit() -> str:
26
+ from . import version
27
+
28
+ return version.commit
29
+
30
+
31
+ __version__: str
32
+ __has_repo__: bool
33
+ __repo__: str
34
+ __commit__: str
35
+
36
+
37
+ __all__ = [
38
+ "__version__",
39
+ "__has_repo__",
40
+ "__repo__",
41
+ "__commit__",
42
+ ]
43
+
44
+
45
+ add_module_properties(
46
+ __name__,
47
+ {
48
+ "__version__": static_property(staticmethod(_get_version)),
49
+ "__has_repo__": static_property(staticmethod(_get_has_repo)),
50
+ "__repo__": static_property(staticmethod(_get_repo)),
51
+ "__commit__": static_property(staticmethod(_get_commit)),
52
+ },
53
+ )
makora/_dist_info.py ADDED
@@ -0,0 +1,4 @@
1
+ version = '0.0.0dev1'
2
+ repo = 'git@github.com:makodevai/makora.git'
3
+ commit = '75f0a326d4cdb4935fd5cfc10bc4e4f80b9306ef'
4
+ has_repo = False
makora/py.typed ADDED
File without changes
makora/utils.py ADDED
@@ -0,0 +1,86 @@
1
+ import sys
2
+ import types
3
+ from typing import Any, Callable, Iterable
4
+
5
+
6
+ class static_property(property):
7
+ def __init__(
8
+ self,
9
+ fget: Callable[[], Any] | None = None,
10
+ fset: Callable[[Any], None] | None = None,
11
+ fdel: Callable[[], None] | None = None,
12
+ doc: str | None = None,
13
+ ) -> None:
14
+ if fget is not None and not isinstance(fget, staticmethod):
15
+ fget = staticmethod(fget)
16
+ if fset is not None and not isinstance(fset, staticmethod):
17
+ fset = staticmethod(fset)
18
+ if fdel is not None and not isinstance(fdel, staticmethod):
19
+ fdel = staticmethod(fdel)
20
+ super().__init__(fget, fset, fdel, doc) # type: ignore
21
+
22
+ def __get__(self, inst: Any, cls: type | None = None) -> Any:
23
+ if inst is None:
24
+ return self
25
+ if self.fget is None:
26
+ raise AttributeError("unreadable attribute")
27
+ return self.fget.__get__(inst, cls)() # pylint: disable=no-member
28
+
29
+ def __set__(self, inst: Any, val: Any) -> None:
30
+ if self.fset is None:
31
+ raise AttributeError("can't set attribute")
32
+
33
+ # pylint: disable=no-member
34
+ return self.fset.__get__(inst)(val) # type: ignore
35
+
36
+ def __delete__(self, inst: Any) -> None:
37
+ if self.fdel is None:
38
+ raise AttributeError("can't delete attribute")
39
+ # pylint: disable=no-member
40
+ return self.fdel.__get__(inst)() # type: ignore
41
+
42
+
43
+ class LazyModuleType(types.ModuleType):
44
+ def __init__(self, name: str) -> None:
45
+ super().__init__(name)
46
+
47
+ def __getattribute__(self, name: str) -> Any:
48
+ _props = super().__getattribute__("_props")
49
+ if name in _props:
50
+ return object.__getattribute__(self, name)
51
+ else:
52
+ return types.ModuleType.__getattribute__(self, name)
53
+
54
+ def __dir__(self) -> Iterable[str]:
55
+ ret = super().__dir__()
56
+ ret.extend(self._props) # type: ignore
57
+ return ret
58
+
59
+
60
+ def add_module_properties(module_name: str, properties: dict[str, Any]) -> None:
61
+ module = sys.modules[module_name]
62
+ replace = False
63
+ if isinstance(module, LazyModuleType):
64
+ hacked_type = type(module)
65
+ else:
66
+ hacked_type = type(
67
+ "LazyModuleType__{}".format(module_name.replace(".", "_")),
68
+ (LazyModuleType,),
69
+ {"_props": set()},
70
+ )
71
+ replace = True
72
+
73
+ for name, prop in properties.items():
74
+ if not isinstance(prop, property):
75
+ prop = property(prop)
76
+ setattr(hacked_type, name, prop)
77
+ hacked_type._props.add(name) # type: ignore
78
+
79
+ if replace:
80
+ new_module = hacked_type(module_name)
81
+ spec = getattr(module, "__spec__", None)
82
+ module.__class__ = new_module.__class__
83
+ module.__name__ = new_module.__name__
84
+ module.__dict__.update(new_module.__dict__)
85
+ module.__spec__ = spec
86
+
makora/version.py ADDED
@@ -0,0 +1,59 @@
1
+ from typing import Any
2
+
3
+ version = "0.0.0dev1"
4
+ repo = "unknown"
5
+ commit = "unknown"
6
+ has_repo = False
7
+
8
+ try:
9
+ import git
10
+ from pathlib import Path
11
+
12
+ try:
13
+ r = git.Repo(Path(__file__).parents[1])
14
+ has_repo = True
15
+
16
+ if not r.remotes:
17
+ repo = "local"
18
+ else:
19
+ repo = r.remotes.origin.url
20
+
21
+ commit = r.head.commit.hexsha # cSpell: disable-line
22
+ status = []
23
+ if r.is_dirty():
24
+ status.append("dirty")
25
+ if r.untracked_files:
26
+ status.append(f"+{len(r.untracked_files)} untracked")
27
+ if status:
28
+ commit += f" ({','.join(status)})"
29
+ except git.InvalidGitRepositoryError:
30
+ raise ImportError()
31
+ except ImportError:
32
+ pass
33
+
34
+ try:
35
+ import importlib.util
36
+ from pathlib import Path
37
+
38
+ _dist_info_file = Path(__file__).parent.joinpath("_dist_info.py")
39
+ if _dist_info_file.exists():
40
+ _spec = importlib.util.spec_from_file_location("_dist_info", _dist_info_file)
41
+ assert _spec is not None
42
+ _dist_info = importlib.util.module_from_spec(_spec)
43
+ assert _dist_info is not None
44
+ assert _spec.loader is not None
45
+ _spec.loader.exec_module(_dist_info)
46
+ assert not has_repo, "_dist_info should not exist when repo is in place"
47
+ assert version == _dist_info.version
48
+ repo = _dist_info.repo
49
+ commit = _dist_info.commit
50
+ except (ImportError, SystemError):
51
+ pass
52
+
53
+
54
+ def info() -> dict[str, Any]:
55
+ g = globals()
56
+ return {k: g[k] for k in __all__}
57
+
58
+
59
+ __all__ = ["version", "repo", "commit", "has_repo"]
@@ -0,0 +1,15 @@
1
+ Metadata-Version: 2.4
2
+ Name: makora
3
+ Version: 0.0.0.dev1
4
+ Home-page:
5
+ Download-URL:
6
+ Author:
7
+ Author-email:
8
+ Requires-Python: >=3.10.0
9
+ Description-Content-Type: text/markdown
10
+ Dynamic: description
11
+ Dynamic: description-content-type
12
+ Dynamic: requires-python
13
+
14
+ # Basic package template
15
+
@@ -0,0 +1,9 @@
1
+ makora/__init__.py,sha256=c284sGf0sOAGjNSXuj_0rOWKdwz8traj9obHjC8JPwE,875
2
+ makora/_dist_info.py,sha256=hGCUf3mt6SNjG8_jkcLs2FSk7xQf5s4S0fiYZ43goaw,136
3
+ makora/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ makora/utils.py,sha256=0ChJUbXpIW3LO_DEsIABjN4U32lt4v7FWAaytYsvq48,2899
5
+ makora/version.py,sha256=HHh8nAju23ldB8M8aQCrVAr1gVlogYPcE-uV6YDEDqE,1588
6
+ makora-0.0.0.dev1.dist-info/METADATA,sha256=s_ziZlb-2XkFQ50vj952naQBjgoIIJMwoWiK3sp-_S4,279
7
+ makora-0.0.0.dev1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
+ makora-0.0.0.dev1.dist-info/top_level.txt,sha256=USKXcpUEUD5MjOYt0Nt7F0Levj3b50kmnF32LtozClw,7
9
+ makora-0.0.0.dev1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ makora