kuvy 0.1.0__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.
kuvy/__init__.py ADDED
File without changes
kuvy/actions.py ADDED
@@ -0,0 +1,176 @@
1
+ from pathlib import Path
2
+ from textwrap import dedent
3
+ import venv
4
+ import tomllib
5
+ import tomli_w
6
+ import subprocess
7
+
8
+ class ActionsUtils:
9
+ def __init__(self):
10
+ current = Path().cwd()
11
+
12
+ venv = None
13
+ for dir in [current, *current.parents]:
14
+ dir = dir.joinpath(".venv")
15
+
16
+ if dir.exists():
17
+ venv = dir
18
+ break
19
+
20
+ if not venv:
21
+ raise FileExistsError("Not in a Python virtual environment!")
22
+
23
+ self.venv = venv
24
+ self.project = self.venv.parent
25
+ self.project_name = self.project.name
26
+ self.pyproject = self.project.joinpath("pyproject.toml")
27
+ self.python = self.venv.joinpath("bin", "python3")
28
+
29
+ with open(self.pyproject, "rb") as f:
30
+ self.pyproject_data = tomllib.load(f)
31
+
32
+ def get_kuvy_field(self) -> dict:
33
+ try:
34
+ return self.pyproject_data["tool"]["kuvy"]
35
+ except KeyError:
36
+ self.generate_kuvy_field()
37
+ return self.pyproject_data["tool"]["kuvy"]
38
+
39
+ def generate_kuvy_field(self):
40
+ field = {
41
+ "tool": {
42
+ "kuvy": {
43
+ "run": {
44
+ "main": f"src/{self.project_name}/main.py",
45
+ "tests": "tests/tests.py"
46
+ }
47
+ }
48
+ }
49
+ }
50
+
51
+ self.pyproject_data.update(field)
52
+ with open(self.pyproject, "wb") as f:
53
+ tomli_w.dump(self.pyproject_data, f)
54
+
55
+ def generate_content_kuvy_field(self, content: dict):
56
+ kuvy = self.pyproject_data
57
+ kuvy.update(content)
58
+
59
+ with open(self.pyproject, "wb") as f:
60
+ tomli_w.dump(kuvy, f)
61
+
62
+ class Actions(ActionsUtils):
63
+ def __init__(self):
64
+ super().__init__()
65
+
66
+ def run(self, file: str, args: list[str] = []):
67
+ try:
68
+ run = self.get_kuvy_field()["run"]
69
+ except KeyError:
70
+ self.generate_content_kuvy_field({
71
+ "tool": {
72
+ "kuvy": {
73
+ "run": {
74
+ "main": f"src/{self.project_name}/main.py",
75
+ "tests": "tests/tests.py"
76
+ }
77
+ }
78
+ }
79
+ })
80
+ run = self.get_kuvy_field()["run"]
81
+
82
+ try:
83
+ file = run[file]
84
+ except KeyError:
85
+ raise ValueError(f"{file} to execute is not in tool.kuvy.run!")
86
+
87
+ subprocess.run([self.python, file, *args])
88
+
89
+ def new(name: str):
90
+ MAIN = dedent(
91
+ f"""\
92
+ import sys
93
+
94
+ def main() -> int:
95
+ print("hola, mundo.")
96
+
97
+ return 0;
98
+
99
+ if __name__ == "__main__":
100
+ sys.exit(main())
101
+ """
102
+ )
103
+
104
+ PYPROJECT = dedent(
105
+ f"""\
106
+ [build-system]
107
+ requires = ["hatchling"]
108
+ build-backend = "hatchling.build"
109
+
110
+ [project]
111
+ name = "{name}"
112
+ version = "0.1.0"
113
+ description = ""
114
+ readme = "README.md"
115
+ requires-python = ""
116
+ dependencies = [
117
+
118
+ ]
119
+
120
+ [project.scripts]
121
+ {name} = "{name}:main.main"
122
+
123
+ [tool.kuvy.run]
124
+ main = "src/{name}/main.py"
125
+ tests = "tests/tests.py"
126
+ """
127
+ )
128
+
129
+ README = dedent(
130
+ f"""\
131
+ # {name}
132
+ """
133
+ )
134
+
135
+ project = Path.cwd().joinpath(name)
136
+
137
+ if project.exists():
138
+ raise FileExistsError(f"Project already exists at: {project}")
139
+
140
+ dirs = [
141
+ project.joinpath("src", name),
142
+ project.joinpath("tests"),
143
+ ]
144
+
145
+ files = [
146
+ project.joinpath("src", name, "main.py"),
147
+ project.joinpath("src", name, "__init__.py"),
148
+ project.joinpath("pyproject.toml"),
149
+ project.joinpath("tests", "tests.py"),
150
+ project.joinpath("README.md"),
151
+ project.joinpath(".gitignore"),
152
+ ]
153
+
154
+ for dir in dirs:
155
+ dir.mkdir(parents=True)
156
+
157
+ for file in files:
158
+ file.touch()
159
+
160
+ if file.name == "pyproject.toml":
161
+ with open(file, "w") as f:
162
+ f.write(PYPROJECT)
163
+
164
+ if file.name == "main.py":
165
+ with open(file, "w") as f:
166
+ f.write(MAIN)
167
+
168
+ if file.name == "README.md":
169
+ with open(file, "w") as f:
170
+ f.write(README)
171
+
172
+ virtualenv = venv.EnvBuilder()
173
+ virtualenv.create(project.joinpath(".venv"))
174
+
175
+ def help():
176
+ print("Usage: kuvy [action] [args]")
kuvy/args.py ADDED
@@ -0,0 +1,51 @@
1
+ from typing import (
2
+ Iterator,
3
+ )
4
+ import sys
5
+
6
+ class Args:
7
+ def __init__(self):
8
+ self.help: bool = False
9
+ self.new: str = ""
10
+ self.run: str = ""
11
+ self.run_args: list[str] = []
12
+ self.install: list[str] = []
13
+ self.uninstall: list[str] = []
14
+ self.update: list[str] = []
15
+ self.build: bool = False
16
+ self.upload: bool = False
17
+
18
+ self.unknown: bool = False
19
+
20
+ def read(self):
21
+ def get_arg(args: Iterator) -> None | str:
22
+ try:
23
+ return next(args)
24
+ except StopIteration:
25
+ return None
26
+
27
+ args = iter(sys.argv[1:])
28
+
29
+ while arg := get_arg(args):
30
+ match arg:
31
+ case "help":
32
+ self.help = True
33
+
34
+ case "new":
35
+ if arg := get_arg(args):
36
+ self.new = arg
37
+
38
+ case "run":
39
+ self.run = "main"
40
+
41
+ while arg := get_arg(args):
42
+ if arg == "--":
43
+ while arg := get_arg(args):
44
+ self.run_args.append(arg)
45
+ return
46
+
47
+ else:
48
+ self.run = arg
49
+
50
+ case _:
51
+ self.unknown = True
kuvy/main.py ADDED
@@ -0,0 +1,38 @@
1
+ from kuvy.args import Args
2
+ from kuvy.actions import (
3
+ Actions,
4
+ help,
5
+ new,
6
+ )
7
+
8
+ import sys
9
+
10
+ def main() -> int:
11
+ args = Args()
12
+ args.read()
13
+
14
+ if args.help:
15
+ print("help")
16
+ return 0
17
+
18
+ elif args.new:
19
+ try:
20
+ new(args.new)
21
+ except FileExistsError as e:
22
+ print(e)
23
+ return 1
24
+
25
+ print(f"Succesfully created {args.new}!")
26
+ return 0
27
+
28
+ actions = Actions()
29
+ if args.run:
30
+ try:
31
+ actions.run(args.run, args=args.run_args)
32
+ except ValueError as e:
33
+ print(e)
34
+
35
+ return 0
36
+
37
+ if __name__ == "__main__":
38
+ sys.exit(main())
@@ -0,0 +1,9 @@
1
+ Metadata-Version: 2.5
2
+ Name: kuvy
3
+ Version: 0.1.0
4
+ Summary: Lightweight project manager for Python, inspired in Cargo.
5
+ Requires-Python: >=3.11
6
+ Requires-Dist: tomli-w
7
+ Description-Content-Type: text/markdown
8
+
9
+ # Kuvy
@@ -0,0 +1,8 @@
1
+ kuvy/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ kuvy/actions.py,sha256=nlD2lkfHndpbRa7pChfHFrsG1ClsQ5FSAqKDGXYAhys,4412
3
+ kuvy/args.py,sha256=D671Uf4UduSs9qUzyS4oyaZW17ZJCNdFAakKEXHrQ3Y,1421
4
+ kuvy/main.py,sha256=zuXFvfJoAeZ18ClKIhhpg8tpG9CgyIMxoDIuX7qse4o,643
5
+ kuvy-0.1.0.dist-info/METADATA,sha256=iC-X2u7vu3sppxE-w_HfHuLm1qiD5rlqR3o9EgGZnRY,211
6
+ kuvy-0.1.0.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
7
+ kuvy-0.1.0.dist-info/entry_points.txt,sha256=-0WzrAS2ImxAxe0l_Cy2RUOvWRJ7QdSu4Mrb49zQP34,40
8
+ kuvy-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.32.4
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ kuvy = kuvy:main.main