kowy 0.1.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.
- kowy-0.1.0/PKG-INFO +4 -0
- kowy-0.1.0/pyproject.toml +13 -0
- kowy-0.1.0/src/kowy/__init__.py +0 -0
- kowy-0.1.0/src/kowy/exceptions.py +2 -0
- kowy-0.1.0/src/kowy/lib.py +98 -0
- kowy-0.1.0/src/kowy/main.py +103 -0
- kowy-0.1.0/src/kowy.egg-info/PKG-INFO +4 -0
- kowy-0.1.0/src/kowy.egg-info/SOURCES.txt +11 -0
- kowy-0.1.0/src/kowy.egg-info/dependency_links.txt +1 -0
- kowy-0.1.0/src/kowy.egg-info/entry_points.txt +2 -0
- kowy-0.1.0/src/kowy.egg-info/requires.txt +1 -0
- kowy-0.1.0/src/kowy.egg-info/top_level.txt +1 -0
- kowy-0.1.0/tests/tests.py +0 -0
kowy-0.1.0/PKG-INFO
ADDED
|
File without changes
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
from .exceptions import NotInVenvError
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
import textwrap
|
|
5
|
+
import sys
|
|
6
|
+
import venv
|
|
7
|
+
import tomllib
|
|
8
|
+
import subprocess
|
|
9
|
+
|
|
10
|
+
class Kovy:
|
|
11
|
+
def __init__(self):
|
|
12
|
+
if sys.prefix == sys.base_prefix:
|
|
13
|
+
raise NotInVenvError("Cannot initialize kovy outside a python venv!")
|
|
14
|
+
|
|
15
|
+
self.root_dir = Path(sys.prefix).parent
|
|
16
|
+
self.python_exec = self.root_dir / ".venv" / "bin" / "python"
|
|
17
|
+
self.pyproject_file = self.root_dir / "pyproject.toml"
|
|
18
|
+
|
|
19
|
+
with open(self.pyproject_file, "rb") as f:
|
|
20
|
+
self.pyproject_data = tomllib.load(f)
|
|
21
|
+
|
|
22
|
+
def run(self, args: list = []):
|
|
23
|
+
try:
|
|
24
|
+
path: str = next(iter(self.pyproject_data["project"]["scripts"].values()))
|
|
25
|
+
decomposed_path = path.split(":")[0].split(".")
|
|
26
|
+
decomposed_path[-1] = decomposed_path[-1] + ".py"
|
|
27
|
+
|
|
28
|
+
exec_path = self.root_dir / "src"
|
|
29
|
+
for element in decomposed_path:
|
|
30
|
+
exec_path /= element
|
|
31
|
+
|
|
32
|
+
subprocess.run([self.python_exec, exec_path])
|
|
33
|
+
|
|
34
|
+
except KeyError:
|
|
35
|
+
# alternative way
|
|
36
|
+
pass
|
|
37
|
+
|
|
38
|
+
except StopIteration:
|
|
39
|
+
raise ValueError("Path script not found int [project.scripts]")
|
|
40
|
+
|
|
41
|
+
@staticmethod
|
|
42
|
+
def project_create(
|
|
43
|
+
project_name: str,
|
|
44
|
+
project_path: Path,
|
|
45
|
+
):
|
|
46
|
+
project_path.mkdir(parents=True)
|
|
47
|
+
venv.create(project_path / ".venv", with_pip=True, upgrade_deps=True)
|
|
48
|
+
|
|
49
|
+
directories = [
|
|
50
|
+
project_path / "src" / project_name,
|
|
51
|
+
project_path / "tests",
|
|
52
|
+
]
|
|
53
|
+
|
|
54
|
+
pyproject_content = textwrap.dedent(
|
|
55
|
+
f"""\
|
|
56
|
+
[build-system]
|
|
57
|
+
requires = ["hatchling"]
|
|
58
|
+
build-backend = "hatchling.build"
|
|
59
|
+
|
|
60
|
+
[project]
|
|
61
|
+
name = "{project_name}"
|
|
62
|
+
version = "0.1.0"
|
|
63
|
+
dependencies = [
|
|
64
|
+
]
|
|
65
|
+
|
|
66
|
+
[project.scripts]
|
|
67
|
+
{project_name} = "{project_name}.main:main"
|
|
68
|
+
"""
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
mainpy_content = textwrap.dedent(
|
|
72
|
+
f"""\
|
|
73
|
+
import sys
|
|
74
|
+
|
|
75
|
+
def main() -> int:
|
|
76
|
+
print("Hola, mundo!")
|
|
77
|
+
|
|
78
|
+
return 0
|
|
79
|
+
|
|
80
|
+
if __name__ == "__main__":
|
|
81
|
+
sys.exit(main())
|
|
82
|
+
"""
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
files = {
|
|
86
|
+
project_path / "pyproject.toml": pyproject_content,
|
|
87
|
+
project_path / "src" / project_name / "main.py": mainpy_content,
|
|
88
|
+
project_path / "src" / project_name / "__init__.py": "",
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
for dir in directories:
|
|
92
|
+
dir.mkdir(parents=True)
|
|
93
|
+
|
|
94
|
+
for file, content in files.items():
|
|
95
|
+
file.touch()
|
|
96
|
+
|
|
97
|
+
with open(file, "w") as f:
|
|
98
|
+
f.write(content)
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
from kopilogs.logs import Log
|
|
4
|
+
from kopilogs.paint import paint
|
|
5
|
+
|
|
6
|
+
from typing import Any, Iterator
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
import sys
|
|
9
|
+
|
|
10
|
+
from .lib import Kovy
|
|
11
|
+
from .exceptions import NotInVenvError
|
|
12
|
+
|
|
13
|
+
def main() -> int:
|
|
14
|
+
action_new, action_new_name = False, None
|
|
15
|
+
run, run_args = False, []
|
|
16
|
+
|
|
17
|
+
if not sys.argv[1:]:
|
|
18
|
+
print("Help: help")
|
|
19
|
+
|
|
20
|
+
args = iter(sys.argv[1:])
|
|
21
|
+
|
|
22
|
+
while arg := get_arg(args):
|
|
23
|
+
match arg:
|
|
24
|
+
case "new":
|
|
25
|
+
action_new = True
|
|
26
|
+
|
|
27
|
+
if name := get_arg(args):
|
|
28
|
+
action_new_name = name
|
|
29
|
+
|
|
30
|
+
else:
|
|
31
|
+
Log("\"new\" action requires an argument!", force_icon=True).error()
|
|
32
|
+
|
|
33
|
+
case "run":
|
|
34
|
+
run = True
|
|
35
|
+
|
|
36
|
+
try:
|
|
37
|
+
if next(args) == "--":
|
|
38
|
+
while arg := get_arg(args):
|
|
39
|
+
run_args.append(arg)
|
|
40
|
+
|
|
41
|
+
except StopIteration:
|
|
42
|
+
pass
|
|
43
|
+
|
|
44
|
+
case "help":
|
|
45
|
+
print("Invkoing hekp panel")
|
|
46
|
+
|
|
47
|
+
case _:
|
|
48
|
+
Log("Unknown option!", force_icon=True).warning()
|
|
49
|
+
Log("Try \"help\"", force_icon=True).info()
|
|
50
|
+
return 0
|
|
51
|
+
|
|
52
|
+
if action_new and action_new_name:
|
|
53
|
+
path: Path = Path(".") / action_new_name
|
|
54
|
+
|
|
55
|
+
try:
|
|
56
|
+
Kovy.project_create(action_new_name, path)
|
|
57
|
+
|
|
58
|
+
except FileExistsError:
|
|
59
|
+
message = paint(
|
|
60
|
+
"Project:",
|
|
61
|
+
str(paint(action_new_name).bold().yellow()),
|
|
62
|
+
"already exists in:",
|
|
63
|
+
str(paint(path.resolve()).bold()),
|
|
64
|
+
)
|
|
65
|
+
Log(str(message), force_icon=True).warning()
|
|
66
|
+
|
|
67
|
+
else:
|
|
68
|
+
message = paint(
|
|
69
|
+
"Created:",
|
|
70
|
+
str(paint(action_new_name).bold().green()),
|
|
71
|
+
"in:",
|
|
72
|
+
str(paint(path.resolve()).bold()),
|
|
73
|
+
)
|
|
74
|
+
Log(str(message), force_icon=True).success()
|
|
75
|
+
|
|
76
|
+
return 0
|
|
77
|
+
|
|
78
|
+
try:
|
|
79
|
+
kovy = Kovy()
|
|
80
|
+
except NotInVenvError as e:
|
|
81
|
+
Log(str(e), force_icon=True).error()
|
|
82
|
+
Log("Try the \"new\" action!", force_icon=True).info()
|
|
83
|
+
return 0
|
|
84
|
+
|
|
85
|
+
if run:
|
|
86
|
+
if run_args:
|
|
87
|
+
kovy.run(args=run_args)
|
|
88
|
+
else:
|
|
89
|
+
kovy.run()
|
|
90
|
+
|
|
91
|
+
return 0
|
|
92
|
+
|
|
93
|
+
def get_arg(args: Iterator) -> None | Any:
|
|
94
|
+
try:
|
|
95
|
+
arg = next(args)
|
|
96
|
+
|
|
97
|
+
except StopIteration:
|
|
98
|
+
return None
|
|
99
|
+
|
|
100
|
+
return arg
|
|
101
|
+
|
|
102
|
+
if __name__ == "__main__":
|
|
103
|
+
sys.exit(main())
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
pyproject.toml
|
|
2
|
+
src/kowy/exceptions.py
|
|
3
|
+
src/kowy/lib.py
|
|
4
|
+
src/kowy/main.py
|
|
5
|
+
src/kowy.egg-info/PKG-INFO
|
|
6
|
+
src/kowy.egg-info/SOURCES.txt
|
|
7
|
+
src/kowy.egg-info/dependency_links.txt
|
|
8
|
+
src/kowy.egg-info/entry_points.txt
|
|
9
|
+
src/kowy.egg-info/requires.txt
|
|
10
|
+
src/kowy.egg-info/top_level.txt
|
|
11
|
+
tests/tests.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
kopilogs>=0.1.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
kowy
|
|
File without changes
|