bcmd 0.2.8__tar.gz → 0.4.6__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.
Potentially problematic release.
This version of bcmd might be problematic. Click here for more details.
- {bcmd-0.2.8 → bcmd-0.4.6}/PKG-INFO +1 -1
- bcmd-0.4.6/bcmd/common/func.py +11 -0
- bcmd-0.4.6/bcmd/resources/project/.vscode/settings.json +11 -0
- {bcmd-0.2.8/bcmd/resources/project/src → bcmd-0.4.6/bcmd/resources/project}/.vscode/tasks.json +4 -4
- {bcmd-0.2.8 → bcmd-0.4.6}/bcmd/tasks/lib.py +14 -14
- {bcmd-0.2.8 → bcmd-0.4.6}/bcmd/tasks/proxy.py +1 -1
- bcmd-0.4.6/bcmd/tasks/venv.py +183 -0
- {bcmd-0.2.8 → bcmd-0.4.6}/bcmd.egg-info/PKG-INFO +1 -1
- {bcmd-0.2.8 → bcmd-0.4.6}/bcmd.egg-info/SOURCES.txt +5 -4
- {bcmd-0.2.8 → bcmd-0.4.6}/pyproject.toml +1 -1
- bcmd-0.2.8/bcmd/resources/project/src/.vscode/settings.json +0 -7
- bcmd-0.2.8/bcmd/tasks/venv.py +0 -128
- {bcmd-0.2.8 → bcmd-0.4.6}/MANIFEST.in +0 -0
- {bcmd-0.2.8 → bcmd-0.4.6}/README.md +0 -0
- {bcmd-0.2.8 → bcmd-0.4.6}/bcmd/__init__.py +0 -0
- {bcmd-0.2.8 → bcmd-0.4.6}/bcmd/common/__init__.py +0 -0
- {bcmd-0.2.8 → bcmd-0.4.6}/bcmd/common/password.py +0 -0
- {bcmd-0.2.8 → bcmd-0.4.6}/bcmd/main.py +0 -0
- {bcmd-0.2.8 → bcmd-0.4.6}/bcmd/resources/project/.gitignore +0 -0
- {bcmd-0.2.8/bcmd/resources/project/src → bcmd-0.4.6/bcmd/resources/project}/.vscode/launch.json +0 -0
- {bcmd-0.2.8/bcmd/resources/project/src → bcmd-0.4.6/bcmd/resources/project}/main.py +0 -0
- {bcmd-0.2.8 → bcmd-0.4.6}/bcmd/tasks/__init__.py +0 -0
- {bcmd-0.2.8 → bcmd-0.4.6}/bcmd/tasks/bin.py +0 -0
- {bcmd-0.2.8 → bcmd-0.4.6}/bcmd/tasks/code.py +0 -0
- {bcmd-0.2.8 → bcmd-0.4.6}/bcmd/tasks/crypto.py +0 -0
- {bcmd-0.2.8 → bcmd-0.4.6}/bcmd/tasks/debian.py +0 -0
- {bcmd-0.2.8 → bcmd-0.4.6}/bcmd/tasks/download.py +0 -0
- {bcmd-0.2.8 → bcmd-0.4.6}/bcmd/tasks/image.py +0 -0
- {bcmd-0.2.8 → bcmd-0.4.6}/bcmd/tasks/json.py +0 -0
- {bcmd-0.2.8 → bcmd-0.4.6}/bcmd/tasks/math.py +0 -0
- {bcmd-0.2.8 → bcmd-0.4.6}/bcmd/tasks/mirror.py +0 -0
- {bcmd-0.2.8 → bcmd-0.4.6}/bcmd/tasks/project.py +0 -0
- {bcmd-0.2.8 → bcmd-0.4.6}/bcmd/tasks/time.py +0 -0
- {bcmd-0.2.8 → bcmd-0.4.6}/bcmd.egg-info/dependency_links.txt +0 -0
- {bcmd-0.2.8 → bcmd-0.4.6}/bcmd.egg-info/entry_points.txt +0 -0
- {bcmd-0.2.8 → bcmd-0.4.6}/bcmd.egg-info/requires.txt +0 -0
- {bcmd-0.2.8 → bcmd-0.4.6}/bcmd.egg-info/top_level.txt +0 -0
- {bcmd-0.2.8 → bcmd-0.4.6}/setup.cfg +0 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
from beni import btask
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def checkFileOrNotExists(file: Path):
|
|
7
|
+
btask.check(file.is_file() or not file.exists(), f'必须是文件 {file}')
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def checkPathOrNotExists(folder: Path):
|
|
11
|
+
btask.check(folder.is_dir() or not folder.exists(), f'必须是目录 {folder}')
|
{bcmd-0.2.8/bcmd/resources/project/src → bcmd-0.4.6/bcmd/resources/project}/.vscode/tasks.json
RENAMED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"command": "TortoiseGitProc.exe",
|
|
8
8
|
"args": [
|
|
9
9
|
"/command:commit",
|
|
10
|
-
"/path:${workspaceFolder}
|
|
10
|
+
"/path:${workspaceFolder}/",
|
|
11
11
|
],
|
|
12
12
|
},
|
|
13
13
|
{
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"command": "TortoiseGitProc.exe",
|
|
26
26
|
"args": [
|
|
27
27
|
"/command:revert",
|
|
28
|
-
"/path:${workspaceFolder}
|
|
28
|
+
"/path:${workspaceFolder}/",
|
|
29
29
|
],
|
|
30
30
|
},
|
|
31
31
|
{
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"command": "TortoiseGitProc.exe",
|
|
44
44
|
"args": [
|
|
45
45
|
"/command:sync",
|
|
46
|
-
"/path:${workspaceFolder}
|
|
46
|
+
"/path:${workspaceFolder}/",
|
|
47
47
|
],
|
|
48
48
|
},
|
|
49
49
|
{
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"command": "TortoiseGitProc.exe",
|
|
53
53
|
"args": [
|
|
54
54
|
"/command:log",
|
|
55
|
-
"/path:${workspaceFolder}
|
|
55
|
+
"/path:${workspaceFolder}/",
|
|
56
56
|
],
|
|
57
57
|
},
|
|
58
58
|
{
|
|
@@ -7,7 +7,8 @@ import typer
|
|
|
7
7
|
from beni import bcolor, bfile, bpath, btask
|
|
8
8
|
from beni.bfunc import syncCall
|
|
9
9
|
|
|
10
|
-
from
|
|
10
|
+
from ..common import password
|
|
11
|
+
from .venv import getPackageList
|
|
11
12
|
|
|
12
13
|
app: Final = btask.newSubApp('lib 工具')
|
|
13
14
|
|
|
@@ -23,10 +24,10 @@ async def tidy_dependencies(
|
|
|
23
24
|
workspace_path = Path.cwd()
|
|
24
25
|
pyprojectTomlFile = workspace_path / 'pyproject.toml'
|
|
25
26
|
btask.check(pyprojectTomlFile.is_file(), 'pyproject.toml 不存在', pyprojectTomlFile)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
libAry =
|
|
27
|
+
venvFile = bpath.get(workspace_path, f'.venv')
|
|
28
|
+
btask.check(venvFile.is_file(), '.venv 不存在', venvFile)
|
|
29
|
+
basePackages, lockPackages = await getPackageList(venvFile)
|
|
30
|
+
libAry = lockPackages if with_version else basePackages
|
|
30
31
|
oldContent = await bfile.readText(pyprojectTomlFile)
|
|
31
32
|
ignoreLibAry = _getIgnoreLibAry(oldContent)
|
|
32
33
|
ignoreLibAry = sorted(list(set(ignoreLibAry) & set(libAry)))
|
|
@@ -79,7 +80,7 @@ async def update_version(
|
|
|
79
80
|
@app.command()
|
|
80
81
|
@syncCall
|
|
81
82
|
async def build(
|
|
82
|
-
|
|
83
|
+
workspace_path: Path = typer.Argument(None, help='workspace 路径'),
|
|
83
84
|
keep_build_files: bool = typer.Option(False, '--keep-build-files', '-k', help='是否保留构建文件'),
|
|
84
85
|
):
|
|
85
86
|
'发布项目'
|
|
@@ -87,22 +88,21 @@ async def build(
|
|
|
87
88
|
# 获取用户名和密码
|
|
88
89
|
u, p = await password.getPypi()
|
|
89
90
|
|
|
90
|
-
if not
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
if not workspace_path:
|
|
92
|
+
workspace_path = Path.cwd()
|
|
93
|
+
workspace_path = workspace_path.resolve()
|
|
93
94
|
|
|
94
95
|
def removeUnusedPath():
|
|
95
|
-
bpath.remove(
|
|
96
|
-
paths = bpath.listDir(
|
|
96
|
+
bpath.remove(workspace_path / 'dist')
|
|
97
|
+
paths = bpath.listDir(workspace_path)
|
|
97
98
|
for x in paths:
|
|
98
99
|
if x.name.endswith('.egg-info'):
|
|
99
100
|
bpath.remove(x)
|
|
100
101
|
|
|
101
102
|
try:
|
|
102
|
-
with bpath.changePath(
|
|
103
|
+
with bpath.changePath(workspace_path):
|
|
103
104
|
removeUnusedPath()
|
|
104
|
-
scriptPath = (
|
|
105
|
-
os.system(f'{scriptPath / "pip.exe"} install setuptools -U -i https://mirrors.aliyun.com/pypi/simple')
|
|
105
|
+
scriptPath = (workspace_path / './venv/Scripts').resolve()
|
|
106
106
|
os.system(f'{scriptPath / "python.exe"} -m build')
|
|
107
107
|
os.system(f'{scriptPath / "twine.exe"} upload dist/* -u {u} -p {p}')
|
|
108
108
|
finally:
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import importlib.resources
|
|
2
|
+
import os
|
|
3
|
+
import platform
|
|
4
|
+
import re
|
|
5
|
+
import sys
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Final
|
|
8
|
+
|
|
9
|
+
import typer
|
|
10
|
+
from beni import bcolor, bexecute, bfile, bhttp, bpath, btask
|
|
11
|
+
from beni.bfunc import syncCall
|
|
12
|
+
from beni.btype import Null
|
|
13
|
+
from prettytable import PrettyTable
|
|
14
|
+
|
|
15
|
+
from bcmd.common import password
|
|
16
|
+
from bcmd.common.func import checkFileOrNotExists, checkPathOrNotExists
|
|
17
|
+
|
|
18
|
+
from . import bin
|
|
19
|
+
|
|
20
|
+
app: Final = btask.app
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@app.command()
|
|
24
|
+
@syncCall
|
|
25
|
+
async def venv(
|
|
26
|
+
packages: list[str] = typer.Argument(None),
|
|
27
|
+
path: Path = typer.Option(None, '--path', help='指定路径,默认当前目录'),
|
|
28
|
+
isOfficial: bool = typer.Option(False, '--official', help='是否使用官方地址安装(https://pypi.org/simple)'),
|
|
29
|
+
isNewProject: bool = typer.Option(False, '--new-project', help='是否新建项目'),
|
|
30
|
+
isForceBase: bool = typer.Option(False, '--force-base', help='是否强制使用基础库去安装'),
|
|
31
|
+
isFullBase: bool = typer.Option(False, '--full-base', help='是否先清空venv目录再使用基础库去安装'),
|
|
32
|
+
):
|
|
33
|
+
'python 虚拟环境配置'
|
|
34
|
+
btask.check(not (isForceBase == isFullBase == True), '不能同时使用 --force-base 和 --full-base')
|
|
35
|
+
path = path or Path(os.getcwd())
|
|
36
|
+
binPath = path / 'bin'
|
|
37
|
+
binListFile = bpath.get(path, 'bin.list')
|
|
38
|
+
venvPath = bpath.get(path, 'venv')
|
|
39
|
+
checkPathOrNotExists(venvPath)
|
|
40
|
+
venvFile = bpath.get(path, '.venv')
|
|
41
|
+
checkFileOrNotExists(venvFile)
|
|
42
|
+
await _inputQiniuPassword(binListFile, binPath)
|
|
43
|
+
if isFullBase:
|
|
44
|
+
bpath.remove(venvPath)
|
|
45
|
+
btask.check(not venvPath.exists(), f'无法删除 venv 目录 {venvPath}')
|
|
46
|
+
packages = packages or []
|
|
47
|
+
for i in range(len(packages)):
|
|
48
|
+
package = packages[i]
|
|
49
|
+
if package.endswith('==now'):
|
|
50
|
+
ary = package.split('==')
|
|
51
|
+
packages[i] = f'{ary[0]}=={await _getPackageLatestVersion(ary[0])}'
|
|
52
|
+
if not venvPath.exists():
|
|
53
|
+
await bexecute.run(f'python -m venv {venvPath}')
|
|
54
|
+
if not venvFile.exists():
|
|
55
|
+
await bfile.writeText(venvFile, '')
|
|
56
|
+
basePackages, lockPackages = await getPackageList(venvFile)
|
|
57
|
+
if isForceBase or isFullBase:
|
|
58
|
+
installPackages = _mergePackageList(basePackages, packages)
|
|
59
|
+
else:
|
|
60
|
+
installPackages = _mergePackageList(lockPackages or basePackages, packages)
|
|
61
|
+
installPackages = sorted(list(set(installPackages)))
|
|
62
|
+
if sys.platform.startswith('win'):
|
|
63
|
+
pip = bpath.get(venvPath, 'Scripts/pip.exe')
|
|
64
|
+
else:
|
|
65
|
+
pip = bpath.get(venvPath, 'bin/pip')
|
|
66
|
+
await _pipInstall(pip, installPackages, isOfficial)
|
|
67
|
+
with bpath.useTempFile() as tempFile:
|
|
68
|
+
await bexecute.run(f'{pip} freeze > {tempFile}')
|
|
69
|
+
basePackages = _mergePackageList(basePackages, packages)
|
|
70
|
+
lockPackages = (await bfile.readText(tempFile)).strip().split('\n')
|
|
71
|
+
await updatePackageList(venvFile, basePackages, lockPackages)
|
|
72
|
+
|
|
73
|
+
# 下载 bin 文件
|
|
74
|
+
if binListFile.exists():
|
|
75
|
+
bin.download(
|
|
76
|
+
names=Null,
|
|
77
|
+
file=binListFile,
|
|
78
|
+
output=binPath,
|
|
79
|
+
)
|
|
80
|
+
# 新建项目
|
|
81
|
+
if isNewProject:
|
|
82
|
+
with importlib.resources.path('bcmd.resources', 'project') as sourceProjectPath:
|
|
83
|
+
for p in bpath.listPath(sourceProjectPath):
|
|
84
|
+
bpath.copy(p, path / p.name)
|
|
85
|
+
bcolor.printGreen('OK')
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
async def _pipInstall(pip: Path, installPackages: list[str], disabled_mirror: bool):
|
|
89
|
+
python = pip.with_stem('python')
|
|
90
|
+
btask.check(python.is_file(), f'无法找到指定文件 {python}')
|
|
91
|
+
btask.check(pip.is_file(), f'无法找到指定文件 {pip}')
|
|
92
|
+
indexUrl = '-i https://pypi.org/simple' if disabled_mirror else ''
|
|
93
|
+
with bpath.useTempFile() as file:
|
|
94
|
+
await bfile.writeText(file, '\n'.join(installPackages))
|
|
95
|
+
table = PrettyTable()
|
|
96
|
+
table.add_column(
|
|
97
|
+
bcolor.yellow('#'),
|
|
98
|
+
[x + 1 for x in range(len(installPackages))],
|
|
99
|
+
)
|
|
100
|
+
table.add_column(
|
|
101
|
+
bcolor.yellow('安装库'),
|
|
102
|
+
[x for x in installPackages],
|
|
103
|
+
'l',
|
|
104
|
+
)
|
|
105
|
+
print(table.get_string())
|
|
106
|
+
|
|
107
|
+
btask.check(
|
|
108
|
+
not await bexecute.run(f'{python} -m pip install --upgrade pip {indexUrl}'),
|
|
109
|
+
'更新 pip 失败',
|
|
110
|
+
)
|
|
111
|
+
btask.check(
|
|
112
|
+
not await bexecute.run(f'{pip} install -r {file} {indexUrl}'),
|
|
113
|
+
'执行失败',
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
async def _getPackageDict(venvFile: Path):
|
|
118
|
+
content = await bfile.readText(venvFile)
|
|
119
|
+
pattern = r'\[\[ (.*?) \]\]\n(.*?)(?=\n\[\[|\Z)'
|
|
120
|
+
matches: list[tuple[str, str]] = re.findall(pattern, content.strip(), re.DOTALL)
|
|
121
|
+
return {match[0]: [line.strip() for line in match[1].strip().split('\n') if line.strip()] for match in matches}
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
_baseName: Final[str] = 'venv'
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def _getLockName():
|
|
128
|
+
systemName = platform.system()
|
|
129
|
+
return f'{_baseName}-{systemName}'
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
async def getPackageList(venvFile: Path):
|
|
133
|
+
result = await _getPackageDict(venvFile)
|
|
134
|
+
lockName = _getLockName()
|
|
135
|
+
return result.get(_baseName, []), result.get(lockName, [])
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
async def updatePackageList(venvFile: Path, packages: list[str], lockPackages: list[str]):
|
|
139
|
+
packageDict = await _getPackageDict(venvFile)
|
|
140
|
+
lockName = _getLockName()
|
|
141
|
+
packages.sort(key=lambda x: x.lower())
|
|
142
|
+
lockPackages.sort(key=lambda x: x.lower())
|
|
143
|
+
packageDict[_baseName] = packages
|
|
144
|
+
packageDict[lockName] = lockPackages
|
|
145
|
+
content = '\n'.join([f'\n[[ {key} ]]\n{'\n'.join(value)}' for key, value in packageDict.items()]).strip()
|
|
146
|
+
await bfile.writeText(venvFile, content)
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
async def _getPackageLatestVersion(package: str):
|
|
150
|
+
'获取指定包的最新版本'
|
|
151
|
+
data = await bhttp.getJson(
|
|
152
|
+
f'https://pypi.org/pypi/{package}/json'
|
|
153
|
+
)
|
|
154
|
+
return data['info']['version']
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def _mergePackageList(basePackages: list[str], addPackages: list[str]):
|
|
158
|
+
basePackagesDict = {_getPackageName(x): x for x in basePackages}
|
|
159
|
+
addPackagesDict = {_getPackageName(x): x for x in addPackages}
|
|
160
|
+
packagesDict = basePackagesDict | addPackagesDict
|
|
161
|
+
return sorted([x for x in packagesDict.values()])
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def _getPackageName(package: str):
|
|
165
|
+
if '==' in package:
|
|
166
|
+
package = package.split('==')[0]
|
|
167
|
+
elif '>' in package:
|
|
168
|
+
package = package.split('>')[0]
|
|
169
|
+
elif '<' in package:
|
|
170
|
+
package = package.split('<')[0]
|
|
171
|
+
package = package.strip()
|
|
172
|
+
if package.startswith('#'):
|
|
173
|
+
package = package.replace('#', '', 1).strip()
|
|
174
|
+
return package
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
async def _inputQiniuPassword(binListFile: Path, binPath: Path) -> None:
|
|
178
|
+
'根据需要输入七牛云密码'
|
|
179
|
+
if binListFile.exists():
|
|
180
|
+
aaSet = set([x.strip() for x in (await bfile.readText(binListFile)).strip().split('\n') if x.strip()])
|
|
181
|
+
bbSet = set([x.name for x in bpath.listFile(binPath)])
|
|
182
|
+
if aaSet != bbSet:
|
|
183
|
+
await password.getQiniu()
|
|
@@ -10,12 +10,13 @@ bcmd.egg-info/entry_points.txt
|
|
|
10
10
|
bcmd.egg-info/requires.txt
|
|
11
11
|
bcmd.egg-info/top_level.txt
|
|
12
12
|
bcmd/common/__init__.py
|
|
13
|
+
bcmd/common/func.py
|
|
13
14
|
bcmd/common/password.py
|
|
14
15
|
bcmd/resources/project/.gitignore
|
|
15
|
-
bcmd/resources/project/
|
|
16
|
-
bcmd/resources/project
|
|
17
|
-
bcmd/resources/project
|
|
18
|
-
bcmd/resources/project
|
|
16
|
+
bcmd/resources/project/main.py
|
|
17
|
+
bcmd/resources/project/.vscode/launch.json
|
|
18
|
+
bcmd/resources/project/.vscode/settings.json
|
|
19
|
+
bcmd/resources/project/.vscode/tasks.json
|
|
19
20
|
bcmd/tasks/__init__.py
|
|
20
21
|
bcmd/tasks/bin.py
|
|
21
22
|
bcmd/tasks/code.py
|
bcmd-0.2.8/bcmd/tasks/venv.py
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import importlib.resources
|
|
2
|
-
import os
|
|
3
|
-
import sys
|
|
4
|
-
from pathlib import Path
|
|
5
|
-
from typing import Final
|
|
6
|
-
|
|
7
|
-
import typer
|
|
8
|
-
from beni import bcolor, bexecute, bfile, bhttp, binput, bpath, btask
|
|
9
|
-
from beni.bfunc import syncCall
|
|
10
|
-
from beni.btype import Null
|
|
11
|
-
|
|
12
|
-
from bcmd.common import password
|
|
13
|
-
|
|
14
|
-
from . import bin
|
|
15
|
-
|
|
16
|
-
app: Final = btask.app
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
@app.command()
|
|
20
|
-
@syncCall
|
|
21
|
-
async def venv(
|
|
22
|
-
packages: list[str] = typer.Argument(None),
|
|
23
|
-
path: Path = typer.Option(None, '--path', '-p', help='指定路径,默认当前目录'),
|
|
24
|
-
disabled_mirror: bool = typer.Option(False, '--disabled-mirror', '-d', help='是否禁用镜像'),
|
|
25
|
-
new_project: bool = typer.Option(False, '--new-project', '-n', help='是否新建项目'),
|
|
26
|
-
quiet: bool = typer.Option(False, '--quiet', '-q', help='是否安静模式'),
|
|
27
|
-
):
|
|
28
|
-
'python 虚拟环境配置'
|
|
29
|
-
path = path or Path(os.getcwd())
|
|
30
|
-
binPath = path / 'bin'
|
|
31
|
-
binListFile = bpath.get(path, 'bin.list')
|
|
32
|
-
await _inputQiniuPassword(binListFile, binPath)
|
|
33
|
-
packages = packages or []
|
|
34
|
-
for i in range(len(packages)):
|
|
35
|
-
package = packages[i]
|
|
36
|
-
if package.endswith('==now'):
|
|
37
|
-
ary = package.split('==')
|
|
38
|
-
packages[i] = f'{ary[0]}=={await _getPackageLatestVersion(ary[0])}'
|
|
39
|
-
venvPath = bpath.get(path, 'venv')
|
|
40
|
-
assertPath(venvPath)
|
|
41
|
-
if not venvPath.exists() and not quiet:
|
|
42
|
-
await binput.confirm('指定目录为非venv目录,是否确认新创建?')
|
|
43
|
-
if not venvPath.exists():
|
|
44
|
-
await bexecute.run(f'python -m venv {venvPath}')
|
|
45
|
-
venvLockFile = bpath.get(path, 'venv.lock')
|
|
46
|
-
assertFile(venvLockFile)
|
|
47
|
-
venvListFile = bpath.get(path, 'venv.list')
|
|
48
|
-
assertFile(venvListFile)
|
|
49
|
-
if not venvListFile.exists():
|
|
50
|
-
await bfile.writeText(venvListFile, '')
|
|
51
|
-
await tidyVenvFile(venvListFile, packages)
|
|
52
|
-
if venvLockFile.exists():
|
|
53
|
-
await tidyVenvFile(venvLockFile, packages)
|
|
54
|
-
targetFile = venvLockFile
|
|
55
|
-
else:
|
|
56
|
-
targetFile = venvListFile
|
|
57
|
-
if sys.platform.startswith('win'):
|
|
58
|
-
pip = bpath.get(venvPath, 'Scripts/pip.exe')
|
|
59
|
-
else:
|
|
60
|
-
pip = bpath.get(venvPath, 'bin/pip')
|
|
61
|
-
await pipInstall(pip, targetFile, disabled_mirror)
|
|
62
|
-
await bexecute.run(f'{pip} freeze > {venvLockFile}')
|
|
63
|
-
# 下载 bin 文件
|
|
64
|
-
if binListFile.exists():
|
|
65
|
-
bin.download(
|
|
66
|
-
names=Null,
|
|
67
|
-
file=binListFile,
|
|
68
|
-
output=binPath,
|
|
69
|
-
)
|
|
70
|
-
# 新建项目
|
|
71
|
-
if new_project:
|
|
72
|
-
with bpath.changePath(path):
|
|
73
|
-
await bexecute.run('beni venv --quiet')
|
|
74
|
-
with importlib.resources.path('bcmd.resources', 'project') as sourceProjectPath:
|
|
75
|
-
for p in bpath.listDir(sourceProjectPath):
|
|
76
|
-
bpath.copy(p, path / p.name)
|
|
77
|
-
bcolor.printGreen('OK')
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
async def pipInstall(pip: Path, file: Path, disabled_mirror: bool):
|
|
81
|
-
python = pip.with_stem('python')
|
|
82
|
-
btask.check(python.is_file(), '无法找到指定文件', python)
|
|
83
|
-
btask.check(pip.is_file(), '无法找到指定文件', pip)
|
|
84
|
-
indexUrl = '-i https://pypi.org/simple' if disabled_mirror else ''
|
|
85
|
-
btask.check(not await bexecute.run(f'{python} -m pip install --upgrade pip {indexUrl}'), '更新 pip 失败')
|
|
86
|
-
btask.check(not await bexecute.run(f'{pip} install -r {file} {indexUrl}'), '执行失败')
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
async def tidyVenvFile(file: Path, packages: list[str]):
|
|
90
|
-
packageNames = [getPackageName(x) for x in packages]
|
|
91
|
-
ary = (await bfile.readText(file)).strip().replace('\r', '').split('\n')
|
|
92
|
-
ary = list(filter(lambda x: getPackageName(x) not in packageNames, ary))
|
|
93
|
-
ary.extend(packages)
|
|
94
|
-
ary.sort()
|
|
95
|
-
await bfile.writeText(file, '\n'.join(ary).strip())
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
def getPackageName(value: str):
|
|
99
|
-
sep_ary = ['>', '<', '=']
|
|
100
|
-
for sep in sep_ary:
|
|
101
|
-
if sep in value:
|
|
102
|
-
return value.split(sep)[0]
|
|
103
|
-
return value
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
def assertFile(file: Path):
|
|
107
|
-
btask.check(file.is_file() or not file.exists(), '必须是文件', file)
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
def assertPath(folder: Path):
|
|
111
|
-
btask.check(folder.is_dir() or not folder.exists(), '必须是目录', folder)
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
async def _getPackageLatestVersion(package: str):
|
|
115
|
-
'获取指定包的最新版本'
|
|
116
|
-
data = await bhttp.getJson(
|
|
117
|
-
f'https://pypi.org/pypi/{package}/json'
|
|
118
|
-
)
|
|
119
|
-
return data['info']['version']
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
async def _inputQiniuPassword(binListFile: Path, binPath: Path) -> None:
|
|
123
|
-
'根据需要输入七牛云密码'
|
|
124
|
-
if binListFile.exists():
|
|
125
|
-
aaSet = set([x.strip() for x in (await bfile.readText(binListFile)).strip().split('\n') if x.strip()])
|
|
126
|
-
bbSet = set([x.name for x in bpath.listFile(binPath)])
|
|
127
|
-
if aaSet != bbSet:
|
|
128
|
-
await password.getQiniu()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{bcmd-0.2.8/bcmd/resources/project/src → bcmd-0.4.6/bcmd/resources/project}/.vscode/launch.json
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|