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