ilinstall 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.
@@ -0,0 +1,21 @@
1
+ GPL-3.0 License
2
+
3
+ Copyright (c) 2025 [Ndrzy]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,16 @@
1
+ Metadata-Version: 2.4
2
+ Name: ilinstall
3
+ Version: 0.1.0
4
+ Summary: python package manager
5
+ Author-email: ndrzy <dandan0019@outlook.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/meatdumplings0019/ilpm
8
+ Requires-Python: >=3.10
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE.txt
11
+ Requires-Dist: rushlib
12
+ Requires-Dist: rushdata
13
+ Requires-Dist: rushclis
14
+ Dynamic: license-file
15
+
16
+ # IlPm
@@ -0,0 +1 @@
1
+ # IlPm
File without changes
@@ -0,0 +1,6 @@
1
+ from rushdata.data import BaseData
2
+
3
+
4
+ class IlPMData(BaseData):
5
+ def is_file(self):
6
+ return self.path.exists()
@@ -0,0 +1,169 @@
1
+ import re
2
+ import subprocess
3
+ from abc import ABC, abstractmethod
4
+ from pathlib import Path
5
+ from typing import Optional
6
+
7
+ from rushlib.output import print_red
8
+ from rushlib.system import SystemConsole
9
+
10
+ from ilinstall.data import IlPMData
11
+ from ilinstall.libs.package import is_package_installed
12
+ from ilinstall.libs.pip import pip_command
13
+ from ilinstall.libs.version import get_package_version
14
+
15
+
16
+ class PackageInfo:
17
+ def __init__(self, name, version):
18
+ self.name = name
19
+ self.version = version
20
+
21
+ def __str__(self) -> str:
22
+ return f'{self.name}{f"=={self.version}" if self.version else ""}'
23
+
24
+
25
+ class IlPM(ABC):
26
+ def __init__(self, path=Path.cwd()):
27
+ self.path = path
28
+
29
+ self.data = self.from_data(str(path))
30
+
31
+ @staticmethod
32
+ @abstractmethod
33
+ def from_data(path: str) -> Optional[IlPMData]:
34
+ pass
35
+
36
+ @property
37
+ def dependencies(self) -> dict:
38
+ return self.data.get("dependencies", {})
39
+
40
+ @property
41
+ @abstractmethod
42
+ def url(self) -> str:
43
+ pass
44
+
45
+ @property
46
+ @abstractmethod
47
+ def venv(self) -> str:
48
+ pass
49
+
50
+ @property
51
+ def dev_dependencies(self) -> dict:
52
+ return self.data.get("devDependencies", {})
53
+
54
+ def get_dependencies(self, name, dev: bool = False) -> str:
55
+ return self.dependencies.get(name, None) if not dev else self.get_dev_dependencies(name)
56
+
57
+ def get_dev_dependencies(self, name) -> str:
58
+ return self.dev_dependencies.get(name, None)
59
+
60
+ def get_all_dependencies(self) -> list[str]:
61
+ return [i for i in self.dependencies.keys()]
62
+
63
+ def get_all_dev_dependencies(self) -> list[str]:
64
+ return [i for i in self.dev_dependencies.keys()]
65
+
66
+ def _collect(self, packages, dev):
67
+ to_install = []
68
+
69
+ for pkg in packages:
70
+ match = re.match(r"([a-zA-Z0-9_-]+)(.*)", pkg)
71
+ if match:
72
+ pkg_name = match.group(1)
73
+ version_spec = match.group(2).strip()
74
+ if not version_spec:
75
+ version = self.get_dependencies(pkg_name, dev)
76
+ version_spec = f'{f"{version}" if version else ""}'
77
+
78
+ to_install.append(PackageInfo(pkg_name, version_spec))
79
+ else:
80
+ raise ValueError(f"{pkg} is not a valid package name")
81
+
82
+ return to_install
83
+
84
+ def install(self, packages, dev: bool = False):
85
+ to_install = self._collect(packages, dev)
86
+
87
+ total = len(to_install)
88
+
89
+ def _install(pkgs):
90
+ sources = []
91
+
92
+ for p in pkgs:
93
+ if is_package_installed(self.venv, str(p)):
94
+ if p.version == get_package_version(self.venv, p.name) or not p.version:
95
+ sources.append((p, False))
96
+ else:
97
+ sources.append((p, True))
98
+
99
+ return sources
100
+
101
+ to_install = _install(to_install)
102
+
103
+ if len(to_install) <= 0:
104
+ return
105
+
106
+ installed = 0
107
+
108
+ for p, i in to_install:
109
+ if i:
110
+ installed += 1
111
+
112
+ print(f"共有 {total} 个包, 已安装 {total - installed} 个包, 将安装 {installed} 个包")
113
+
114
+ for pkg, i in to_install:
115
+ if i:
116
+ cmd = [
117
+ *pip_command(self.venv),
118
+ "install",
119
+ *str(pkg),
120
+ "-i",
121
+ self.url
122
+ ]
123
+
124
+ try:
125
+ SystemConsole.execute(cmd, capture_output=True, check=True)
126
+ print(f"Collecting {pkg.name}")
127
+ except subprocess.CalledProcessError:
128
+ print_red("发生错误.")
129
+ return
130
+ else:
131
+ print(f"Requirement already satisfied {pkg.name}")
132
+
133
+ print(f"安装完成, 已安装 {", ".join([i.name for i, j in to_install])}")
134
+
135
+ for pkg in [i.name for i, j in to_install]:
136
+ self.data.write(f"{"dependencies" if not dev else "devDependencies"}", get_package_version(self.venv, pkg),
137
+ pkg)
138
+
139
+ def for_package(self):
140
+ self.install(self.get_all_dependencies(), False)
141
+ self.install(self.get_all_dev_dependencies(), True)
142
+
143
+ def uninstall(self, packages, dev: bool = False):
144
+ to_uninstall = self._collect(packages, dev)
145
+
146
+ total = len(to_uninstall)
147
+
148
+ print(f"将卸载 {total} 个包.")
149
+
150
+ for pkg in to_uninstall:
151
+ cmd = [
152
+ *pip_command(self.venv),
153
+ "uninstall",
154
+ *pkg.name,
155
+ "-y"
156
+ ]
157
+
158
+ try:
159
+ SystemConsole.execute(cmd, capture_output=True, check=True)
160
+ print(f"Uninstalling {pkg.name}")
161
+ except subprocess.CalledProcessError:
162
+ print_red(f"发生错误")
163
+ return
164
+
165
+ print(f"卸载完成, 已卸载 {", ".join([i.name for i in to_uninstall])}")
166
+
167
+ for pkg in [i.name for i in to_uninstall]:
168
+ if not self.get_dependencies(pkg, dev) is None:
169
+ self.data.delete(f"{"dependencies" if not dev else "devDependencies"}", pkg)
@@ -0,0 +1,12 @@
1
+ from pathlib import Path
2
+
3
+ from rushlib.system import SystemConsole
4
+
5
+
6
+ def venv_path(venv: str = ".venv") -> Path:
7
+ python = SystemConsole.python_venv(Path.cwd() / venv)
8
+
9
+ if python.exists():
10
+ return python
11
+
12
+ return Path(SystemConsole.run_python(["-c", "import sys; print(sys.executable)"])[1])
@@ -0,0 +1,11 @@
1
+ import subprocess
2
+
3
+ from ilinstall.libs.version import get_package_version
4
+
5
+
6
+ def is_package_installed(venv, pkg):
7
+ try:
8
+ get_package_version(venv, pkg)
9
+ return True
10
+ except (subprocess.CalledProcessError, FileNotFoundError):
11
+ return False
@@ -0,0 +1,7 @@
1
+ from ilinstall.libs import venv_path
2
+
3
+
4
+ def pip_command(venv: str = ".venv") -> list[str]:
5
+ python = venv_path(venv)
6
+
7
+ return [f"{python}", "-m", "pip"]
@@ -0,0 +1,6 @@
1
+ from rushlib.system import SystemConsole
2
+ from ilinstall.libs import venv_path
3
+
4
+ def get_package_version(venv, pkg):
5
+ return SystemConsole.execute([f"{venv_path(venv)}", "-c", f"from importlib.metadata import version;print(version(\"{pkg.split("==")[0]}\"))"], shell=True, capture_output=True, check=True).stdout.strip()
6
+
@@ -0,0 +1 @@
1
+ __version__ = "0.1.0"
@@ -0,0 +1,16 @@
1
+ Metadata-Version: 2.4
2
+ Name: ilinstall
3
+ Version: 0.1.0
4
+ Summary: python package manager
5
+ Author-email: ndrzy <dandan0019@outlook.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/meatdumplings0019/ilpm
8
+ Requires-Python: >=3.10
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE.txt
11
+ Requires-Dist: rushlib
12
+ Requires-Dist: rushdata
13
+ Requires-Dist: rushclis
14
+ Dynamic: license-file
15
+
16
+ # IlPm
@@ -0,0 +1,27 @@
1
+ LICENSE.txt
2
+ README.md
3
+ pyproject.toml
4
+ ilinstall/__init__.py
5
+ ilinstall/data.py
6
+ ilinstall/install.py
7
+ ilinstall/version.py
8
+ ilinstall.egg-info/PKG-INFO
9
+ ilinstall.egg-info/SOURCES.txt
10
+ ilinstall.egg-info/dependency_links.txt
11
+ ilinstall.egg-info/requires.txt
12
+ ilinstall.egg-info/top_level.txt
13
+ ilinstall/libs/__init__.py
14
+ ilinstall/libs/package.py
15
+ ilinstall/libs/pip.py
16
+ ilinstall/libs/version.py
17
+ ilinstall_cli/__init__.py
18
+ ilinstall_cli/add.py
19
+ ilinstall_cli/data.py
20
+ ilinstall_cli/init.py
21
+ ilinstall_cli/install.py
22
+ ilinstall_cli/installer.py
23
+ ilinstall_cli/uninstall.py
24
+ scripts/build.py
25
+ scripts/install.py
26
+ scripts/upload.py
27
+ test/install.py
@@ -0,0 +1,3 @@
1
+ rushlib
2
+ rushdata
3
+ rushclis
@@ -0,0 +1,7 @@
1
+ build
2
+ dist
3
+ ilbuilder-build
4
+ ilinstall
5
+ ilinstall_cli
6
+ scripts
7
+ test
@@ -0,0 +1,11 @@
1
+ from rushclis import RushCli
2
+
3
+ from ilinstall.version import __version__
4
+ from ilinstall_cli.add import add
5
+
6
+
7
+ class Cli(RushCli):
8
+ def __init__(self):
9
+ super().__init__("ilinstall", __version__)
10
+
11
+ add(self)
@@ -0,0 +1,28 @@
1
+ from ilinstall_cli.init import init_command
2
+ from ilinstall_cli.install import install_command
3
+ from ilinstall_cli.uninstall import uninstall_command
4
+
5
+
6
+ def add(app):
7
+ def init():
8
+ app.add_command("init", "🛠️ 初始化项目配置")
9
+ app.add_sub_argument("init", "path", default=".", nargs="?")
10
+ app.add_sub_argument("init", "--force", "-f", "store_true", default=False)
11
+
12
+ app.set_sub_main_func("init", init_command, app)
13
+
14
+ def install():
15
+ app.add_command("install", "💿 安装python包")
16
+ app.add_sub_argument("install", "packages", nargs="+")
17
+
18
+ app.set_sub_main_func("install", install_command, app)
19
+
20
+ def uninstall():
21
+ app.add_command("uninstall", "💿 卸载python包")
22
+ app.add_sub_argument("uninstall", "packages", nargs="+")
23
+
24
+ app.set_sub_main_func("uninstall", uninstall_command, app)
25
+
26
+ init()
27
+ install()
28
+ uninstall()
@@ -0,0 +1,23 @@
1
+ from ilinstall.data import IlPMData
2
+
3
+
4
+ class PackageData(IlPMData):
5
+ FILENAME = "ilinstall-package.json"
6
+
7
+ PROPERTY = {
8
+ "venv": {
9
+ "type": "str",
10
+ "generate": True,
11
+ "default": ".venv"
12
+ },
13
+ "dependencies": {
14
+ "type": "dict",
15
+ "generate": True,
16
+ "default": {}
17
+ },
18
+ "devDependencies": {
19
+ "type": "dict",
20
+ "generate": True,
21
+ "default": {}
22
+ }
23
+ }
@@ -0,0 +1,16 @@
1
+ from pathlib import Path
2
+
3
+ from rushlib.file import FolderStream
4
+
5
+ from ilinstall_cli.data import PackageData
6
+
7
+
8
+ def init_command(args, app):
9
+ path = Path(getattr(args, "path", Path.cwd()))
10
+
11
+ fs = FolderStream(path).create()
12
+
13
+ package = PackageData(path)
14
+ package.create(path, getattr(args, "force", False))
15
+
16
+ print("创建成功!\n")
@@ -0,0 +1,13 @@
1
+ from ilinstall_cli.installer import PackageManager
2
+
3
+
4
+ def install_command(args, app):
5
+ installer = PackageManager()
6
+
7
+ packages = getattr(args, "packages", [])
8
+
9
+ if not packages:
10
+ installer.for_package()
11
+ return
12
+
13
+ installer.install(packages)
@@ -0,0 +1,25 @@
1
+ from typing import Optional
2
+
3
+ from ilinstall.data import IlPMData
4
+ from ilinstall.install import IlPM
5
+ from ilinstall_cli.data import PackageData
6
+
7
+
8
+ class PackageManager(IlPM):
9
+ @staticmethod
10
+ def from_data(path: str) -> Optional[IlPMData]:
11
+ package_config = PackageData(path)
12
+
13
+ if not package_config.is_file():
14
+ raise FileNotFoundError(f"{package_config.path} dont exist!")
15
+
16
+ return package_config
17
+
18
+ @property
19
+ def url(self) -> str:
20
+ return "https://pypi.org/simple"
21
+
22
+
23
+ @property
24
+ def venv(self) -> str:
25
+ return self.data.get("venv", ".venv")
@@ -0,0 +1,12 @@
1
+ from ilinstall_cli.installer import PackageManager
2
+
3
+
4
+ def uninstall_command(args, app):
5
+ installer = PackageManager()
6
+
7
+ packages = getattr(args, "packages", [])
8
+
9
+ if not packages:
10
+ return
11
+
12
+ installer.uninstall(packages)
@@ -0,0 +1,25 @@
1
+ [build-system]
2
+ requires = ["setuptools >= 48.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "ilinstall"
7
+ version = "0.1.0"
8
+ description = "python package manager"
9
+ authors = [
10
+ { name = "ndrzy", email = "dandan0019@outlook.com" }
11
+ ]
12
+ readme = { file = "README.md", content-type = "text/markdown" }
13
+ requires-python = ">=3.10"
14
+ license = { text = "MIT" }
15
+ dependencies = [
16
+ 'rushlib',
17
+ 'rushdata',
18
+ 'rushclis'
19
+ ]
20
+
21
+ [project.urls]
22
+ Homepage = "https://github.com/meatdumplings0019/ilpm"
23
+
24
+ [tool.setuptools]
25
+ packages = { find = { } }
@@ -0,0 +1,4 @@
1
+ import os
2
+
3
+ if __name__ == '__main__':
4
+ os.system('python -m build')
@@ -0,0 +1,5 @@
1
+ import os
2
+
3
+ if __name__ == '__main__':
4
+ os.system('pip install -r requirements.txt')
5
+ print("\nAll packages installed")
@@ -0,0 +1,4 @@
1
+ import os
2
+
3
+ if __name__ == '__main__':
4
+ os.system('twine.exe upload .\dist\*')
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,27 @@
1
+ from typing import Optional
2
+
3
+ from ilinstall.data import IlPMData
4
+ from ilinstall.install import IlPM
5
+
6
+
7
+ class TmpData(IlPMData):
8
+ FILENAME = "tmp.json"
9
+
10
+ class TmpInstall(IlPM):
11
+ @property
12
+ def url(self) -> str:
13
+ return "https://pypi.org/simple"
14
+
15
+ @property
16
+ def venv(self) -> str:
17
+ return ".venv"
18
+
19
+ @staticmethod
20
+ def from_data(path: str) -> Optional[IlPMData]:
21
+ return TmpData()
22
+
23
+ TmpData().create()
24
+
25
+ tmp = TmpInstall()
26
+ tmp.for_package()
27
+ tmp.uninstall(["build"])