cargopy 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.
cargopy-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,7 @@
1
+ Metadata-Version: 2.4
2
+ Name: cargopy
3
+ Version: 0.1.0
4
+ Summary: Rust Cargo-like project manager for Python
5
+ Project-URL: Homepage, https://github.com/Kopihue/Cargopy/
6
+ Author-email: Kopihue <kopihuegit@gmail.com>
7
+ Requires-Python: >=3.14
File without changes
@@ -0,0 +1,22 @@
1
+ [project]
2
+ name = "cargopy"
3
+ version = "0.1.0"
4
+ description = "Rust Cargo-like project manager for Python"
5
+ readme = "README.md"
6
+ requires-python = ">= 3.14"
7
+ authors = [
8
+ { name = "Kopihue", email = "kopihuegit@gmail.com" }
9
+ ]
10
+
11
+ [project.scripts]
12
+ cargopy = "cargopy.main:main"
13
+
14
+ [project.urls]
15
+ Homepage = "https://github.com/Kopihue/Cargopy/"
16
+
17
+ [build-system]
18
+ requires = ["hatchling"]
19
+ build-backend = "hatchling.build"
20
+
21
+ [tool.hatch.build.targets.wheel]
22
+ include = ["src/cargopy/**"]
@@ -0,0 +1,140 @@
1
+ #!/usr/bin/env python3
2
+
3
+ import sys
4
+ import structure
5
+ import utils
6
+
7
+ def main():
8
+ args = sys.argv[1:]
9
+
10
+ new = False
11
+ dir_name = None
12
+
13
+ cd = False
14
+
15
+ venv = False
16
+
17
+ run = False
18
+ file_name = None
19
+ file_args = None
20
+
21
+ pip = None
22
+ package = None
23
+ install = False
24
+ upgrade = False
25
+ uninstall = False
26
+ listed = False
27
+
28
+
29
+ while args:
30
+ arg = args.pop(0)
31
+
32
+ match arg:
33
+ case "help" | "--help":
34
+ print("Help panel deployed")
35
+
36
+ case "new":
37
+ new = True
38
+ try:
39
+ dir_name = args.pop(0)
40
+ except IndexError:
41
+ print("New action requires an argument!")
42
+
43
+ case "cd":
44
+ cd = True
45
+
46
+ case "venv":
47
+ venv = True
48
+
49
+ case "run":
50
+ run = True
51
+ try:
52
+ file_name = args.pop(0)
53
+ except IndexError:
54
+ print("Run action requires an argument!")
55
+
56
+ try:
57
+ are_there_arguments = args.pop(0)
58
+ if are_there_arguments == "--":
59
+ pass
60
+
61
+ else:
62
+ raise ValueError("Invalid action")
63
+ except IndexError:
64
+ file_args = []
65
+ else:
66
+ file_args = args
67
+
68
+ case "install":
69
+ pip = True
70
+ install = True
71
+ try:
72
+ package = args.pop(0)
73
+ except IndexError:
74
+ print("Add action requires an argument!")
75
+
76
+ case "upgrade":
77
+ pip = True
78
+ upgrade = True
79
+ try:
80
+ package = args.pop(0)
81
+ except IndexError:
82
+ print("Add action requires an argument!")
83
+
84
+ case "uninstall":
85
+ pip = True
86
+ uninstall = True
87
+ try:
88
+ package = args.pop(0)
89
+ except IndexError:
90
+ print("Add action requires an argument!")
91
+
92
+ case "list":
93
+ pip = True
94
+ listed = True
95
+
96
+ case _:
97
+ print("Unknown option")
98
+
99
+ if new or cd:
100
+ struct = structure.Structure()
101
+
102
+ if new:
103
+ if dir_name is None:
104
+ sys.exit(1)
105
+
106
+ struct.new(dir_name)
107
+
108
+ elif cd:
109
+ print(struct.cd())
110
+
111
+ if venv or run or pip:
112
+ project_utils = utils.Utils()
113
+
114
+ if venv:
115
+ project_utils.venv()
116
+
117
+ elif run:
118
+ if file_name is None:
119
+ sys.exit(1)
120
+
121
+ project_utils.run(file_name, file_args)
122
+
123
+ elif pip:
124
+ if package is None:
125
+ sys.exit(1)
126
+
127
+ if install:
128
+ project_utils.pip(package, "install")
129
+
130
+ elif upgrade:
131
+ project_utils.pip(package, "upgrade")
132
+
133
+ elif uninstall:
134
+ project_utils.pip(package, "uninstall")
135
+
136
+ elif listed:
137
+ project_utils.pip("", "list")
138
+
139
+ if __name__ == "__main__":
140
+ main()
@@ -0,0 +1,50 @@
1
+ from pathlib import Path
2
+ import sys
3
+
4
+ class Project:
5
+ @staticmethod
6
+ def get_project_root() -> Path | None:
7
+ pwd = Path.cwd()
8
+
9
+ while True:
10
+ if pwd == pwd.parent:
11
+ return None
12
+
13
+ if (pwd / "pyproject.toml").exists():
14
+ return pwd
15
+
16
+ else:
17
+ pwd = pwd.parent
18
+
19
+ @staticmethod
20
+ def check_venv_existence() -> bool | None:
21
+ pwd = Project.get_project_root()
22
+ if pwd is None:
23
+ return None
24
+
25
+ if (pwd / ".venv").exists():
26
+ return True
27
+
28
+ else:
29
+ return False
30
+
31
+ @staticmethod
32
+ def get_isolated_python() -> Path | None:
33
+ root_project = Project.get_project_root()
34
+
35
+ if root_project is None:
36
+ return None
37
+
38
+ isolated_python = (
39
+ root_project
40
+ / ".venv"
41
+ / "bin"
42
+ / "python"
43
+ )
44
+
45
+ if not isolated_python.exists():
46
+ print("Virtual Python doesn't exists")
47
+ print("Try running again \"cargopy venv\"")
48
+ sys.exit(1)
49
+
50
+ return isolated_python
@@ -0,0 +1,52 @@
1
+ from pathlib import Path
2
+ from project import Project
3
+ import sys
4
+ import shutil
5
+ import subprocess
6
+
7
+ class Structure(Project):
8
+ def __init__(self):
9
+ self.pwd = Path.cwd()
10
+ self.root_project = self.get_project_root()
11
+
12
+ def new(self, dir_name: str):
13
+ dir_path = self.pwd / dir_name
14
+
15
+ if dir_path.exists():
16
+ print("Project already exists")
17
+ sys.exit(1)
18
+
19
+ try:
20
+ dir_path.mkdir(exist_ok=True)
21
+ except Exception as e:
22
+ print("Exception", e)
23
+
24
+ (dir_path / "README.md").touch()
25
+ (dir_path / "pyproject.toml").touch()
26
+
27
+ src_dir = dir_path / "src"
28
+ tests_dir = dir_path / "tests"
29
+ src_dir.mkdir()
30
+ tests_dir.mkdir()
31
+
32
+ package_dir = src_dir / dir_name
33
+ package_dir.mkdir()
34
+ (package_dir / "__init__.py").touch()
35
+
36
+ print(f"Created project in {dir_name}")
37
+ if shutil.which("git") is not None:
38
+ subprocess.run(
39
+ ["git", "init"],
40
+ cwd=dir_path,
41
+ )
42
+
43
+ else:
44
+ print("Couldn't create git repository, git doesn't exists")
45
+
46
+ def cd(self) -> Path:
47
+ if self.root_project is None:
48
+ print("You haven't initialized a Python project!")
49
+ sys.exit(1)
50
+
51
+ else:
52
+ return self.root_project
@@ -0,0 +1,136 @@
1
+ from pathlib import Path
2
+ from structure import Structure
3
+ from project import Project
4
+ import subprocess
5
+ import sys
6
+
7
+ class Utils(Project):
8
+ def __init__(self):
9
+ self.struct = Structure()
10
+
11
+ self.pwd = Path.cwd()
12
+ self.root_project = self.get_project_root()
13
+
14
+ def venv(self):
15
+ check_venv = self.check_venv_existence()
16
+ if check_venv is None:
17
+ print("Not a Python project")
18
+ sys.exit(1)
19
+
20
+ if check_venv:
21
+ print(".venv already exists!")
22
+ sys.exit(1)
23
+
24
+ else:
25
+ command = ["python", "-m", "venv", ".venv"]
26
+ result = subprocess.run(
27
+ command,
28
+ capture_output=True,
29
+ text=True,
30
+ cwd=self.root_project
31
+ )
32
+
33
+ if result.returncode != 0:
34
+ print("The command has failed.")
35
+ print(result.stderr)
36
+
37
+ else:
38
+ print("Succesfully created .venv!")
39
+
40
+ def run(self, file_name: str, file_args: list[str] | None):
41
+ check_venv = self.check_venv_existence()
42
+ isolated_python = self.get_isolated_python()
43
+
44
+ if file_args is None:
45
+ sys.exit(1)
46
+
47
+ if (
48
+ check_venv is None
49
+ or self.root_project is None
50
+ or isolated_python is None
51
+ ):
52
+ print("Not a Python project")
53
+ sys.exit(1)
54
+
55
+ if not check_venv:
56
+ self.venv()
57
+ check_venv = True
58
+
59
+ if check_venv:
60
+ ignored_dirs = {".venv", "__pycache__"}
61
+ found_scripts = []
62
+ for path in self.root_project.rglob(file_name):
63
+ if not any(
64
+ ignored in path.parts
65
+ for ignored in ignored_dirs
66
+ ):
67
+ found_scripts.append(path.resolve())
68
+
69
+ if not found_scripts:
70
+ print(f"Didn't found script in {self.root_project}")
71
+ sys.exit(1)
72
+
73
+ command = [isolated_python, found_scripts[0], *file_args]
74
+ result = subprocess.run(
75
+ command,
76
+ capture_output=True,
77
+ text=True,
78
+ )
79
+
80
+ if result.returncode != 0:
81
+ print(f"Exception running {file_name}")
82
+ print(result.stderr)
83
+
84
+ def pip(self, package: str, action: str):
85
+ check_venv = self.check_venv_existence()
86
+ isolated_python = self.get_isolated_python()
87
+
88
+ if check_venv is None or isolated_python is None:
89
+ print("Not a Python project")
90
+ sys.exit(1)
91
+
92
+ if not check_venv:
93
+ self.venv()
94
+ check_venv = True
95
+
96
+ if check_venv:
97
+ if action == "upgrade":
98
+ command = [
99
+ isolated_python,
100
+ "-m",
101
+ "pip",
102
+ "install",
103
+ "--upgrade",
104
+ package,
105
+ ]
106
+
107
+ elif action == "list":
108
+ command = [
109
+ isolated_python,
110
+ "-m",
111
+ "pip",
112
+ action,
113
+ ]
114
+
115
+ elif action == "uninstall":
116
+ command = [
117
+ isolated_python,
118
+ "-m",
119
+ "pip",
120
+ action,
121
+ "-y",
122
+ package
123
+ ]
124
+
125
+ else:
126
+ command = [
127
+ isolated_python,
128
+ "-m",
129
+ "pip",
130
+ action,
131
+ package,
132
+ ]
133
+
134
+ subprocess.run(
135
+ command,
136
+ )
File without changes