ptgit 1.0.0__py3-none-any.whl
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.
- ptgit/__configReader__.py +50 -0
- ptgit/__init__.py +1 -0
- ptgit/__main__.py +228 -0
- ptgit-1.0.0.dist-info/METADATA +39 -0
- ptgit-1.0.0.dist-info/RECORD +7 -0
- ptgit-1.0.0.dist-info/WHEEL +4 -0
- ptgit-1.0.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import json
|
|
3
|
+
from typing import Any
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
configuration = {"AllowPackagedFiles": False, "IgnoreWarning": False}
|
|
6
|
+
|
|
7
|
+
def checkOS()->str:
|
|
8
|
+
if (os.getenv("HOME") is None):
|
|
9
|
+
return "WINDOWS"
|
|
10
|
+
|
|
11
|
+
return "UNIX"
|
|
12
|
+
|
|
13
|
+
def readConfigFile()->configuration:
|
|
14
|
+
curOS = checkOS()
|
|
15
|
+
path = ""
|
|
16
|
+
if (curOS == "WINDOWS"):
|
|
17
|
+
path += os.getenv("APPDATA")
|
|
18
|
+
else:
|
|
19
|
+
path += os.getenv("HOME")
|
|
20
|
+
if (not Path(path + "/ptgit_config").exists()):
|
|
21
|
+
os.mkdir(path + "/ptgit_config")
|
|
22
|
+
writeConfigFile(configuration)
|
|
23
|
+
if (not Path(path + '/ptgit_config/config.json').exists()):
|
|
24
|
+
writeConfigFile(configuration)
|
|
25
|
+
file = open(path + "/ptgit_config/config.json", "r")
|
|
26
|
+
rawJson = file.read()
|
|
27
|
+
print(f"RawJson: {rawJson}")
|
|
28
|
+
|
|
29
|
+
return json.loads(rawJson)["config"]
|
|
30
|
+
|
|
31
|
+
def writeConfigFile(config:configuration):
|
|
32
|
+
curOS = checkOS()
|
|
33
|
+
path = ""
|
|
34
|
+
if (curOS == "WINDOWS"):
|
|
35
|
+
path += os.getenv("APPDATA")
|
|
36
|
+
else:
|
|
37
|
+
path += os.getenv("HOME")
|
|
38
|
+
file = open(path + "/ptgit_config/config.json", "w")
|
|
39
|
+
file.write(json.dumps({"config": config}, indent="\t"))
|
|
40
|
+
file.close()
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def setConfig(name:str, newValue:Any):
|
|
44
|
+
config = readConfigFile()
|
|
45
|
+
value = config["name"]
|
|
46
|
+
if (value is None):
|
|
47
|
+
return
|
|
48
|
+
|
|
49
|
+
config[name] = newValue
|
|
50
|
+
writeConfigFile(config)
|
ptgit/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Nothin here!
|
ptgit/__main__.py
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import os
|
|
3
|
+
from typing import Any
|
|
4
|
+
from urllib.parse import urlparse as parse
|
|
5
|
+
from .__configReader__ import readConfigFile, setConfig, checkOS
|
|
6
|
+
from subprocess import run
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from git import Repo
|
|
9
|
+
|
|
10
|
+
global packName
|
|
11
|
+
global URL
|
|
12
|
+
global branch
|
|
13
|
+
global build
|
|
14
|
+
global allowPrePackaged
|
|
15
|
+
|
|
16
|
+
packName = ""
|
|
17
|
+
URL = ""
|
|
18
|
+
branch = ""
|
|
19
|
+
build = False
|
|
20
|
+
allowPrePackaged = False
|
|
21
|
+
|
|
22
|
+
def processArg(arg:str, base:str = "") -> Any:
|
|
23
|
+
if (arg.lower() == "help"):
|
|
24
|
+
print("""PTGit (Pip Through Git)
|
|
25
|
+
|
|
26
|
+
Useage:
|
|
27
|
+
|
|
28
|
+
ptgit packagename packageURL <arguments> - Install a package from git.
|
|
29
|
+
|
|
30
|
+
Arguments:
|
|
31
|
+
--help: Displays this message
|
|
32
|
+
--branch="branchName" Determines which branch to install from
|
|
33
|
+
--autoinstall="[<packagenames>]" calls pip to install these packages if they are not included as a requirement in the package's repo
|
|
34
|
+
--config starts the configuration script""")
|
|
35
|
+
exit(0)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
if (arg.lower().startswith("branch=")):
|
|
39
|
+
return arg.split("=")[1]
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
print(f"Not a valid argument {base}{arg}! Use --help for information!")
|
|
43
|
+
|
|
44
|
+
def checkArgs():
|
|
45
|
+
arg_array = []
|
|
46
|
+
for item in args:
|
|
47
|
+
if (arg_array.__contains__(item) and ["--branch"].__contains__(item)):
|
|
48
|
+
print(f"You cannot call {item} twice!")
|
|
49
|
+
processArg("help")
|
|
50
|
+
arg_array.append(item)
|
|
51
|
+
|
|
52
|
+
def runConfigScript():
|
|
53
|
+
configFile = readConfigFile()
|
|
54
|
+
validOptions = {"1": "AllowPackagedFiles"}
|
|
55
|
+
result = input("From the following options choose one to switch\n1: Allow Potentially Unsafe Pre-Packaged files from git repositories: " + str(configFile["AllowPackagedFiles"]))
|
|
56
|
+
|
|
57
|
+
if (result == "1"):
|
|
58
|
+
setConfig("AllowPackagedFiles", (not configFile["AllowPackagedFiles"]))
|
|
59
|
+
|
|
60
|
+
if (not validOptions.__contains__(result)):
|
|
61
|
+
print("Invalid Option!")
|
|
62
|
+
runConfigScript()
|
|
63
|
+
|
|
64
|
+
print("Configuration saved! " + validOptions[result] + " set to " + configFile[validOptions[result]])
|
|
65
|
+
exit(0)
|
|
66
|
+
|
|
67
|
+
args = sys.argv
|
|
68
|
+
if (args[0].endswith(".py") or args[0] == "ptgit"):
|
|
69
|
+
args.remove(args[0])
|
|
70
|
+
|
|
71
|
+
if (args.__contains__("--config")):
|
|
72
|
+
runConfigScript()
|
|
73
|
+
|
|
74
|
+
if (args.__len__() < 2):
|
|
75
|
+
print("Invalid number of arguments!")
|
|
76
|
+
processArg("help")
|
|
77
|
+
|
|
78
|
+
config = readConfigFile()
|
|
79
|
+
if (config["AllowPackagedFiles"]):
|
|
80
|
+
i = input("WARNING: unsafe switch \"AllowPackagedFiles\" is enabled!\nThis may make it easy for malicious actors to install fake packages that comprimise your system!\nAlways check official sources before installng from a git repo!\nPress ENTER to continue, type IGNORE to permanently remove this warning.")
|
|
81
|
+
if (i.upper() == "IGNORE"):
|
|
82
|
+
setConfig("IgnoreWarning", True)
|
|
83
|
+
|
|
84
|
+
checkArgs()
|
|
85
|
+
|
|
86
|
+
result = parse(args[0])
|
|
87
|
+
|
|
88
|
+
if (all([result.scheme, result.netloc])):
|
|
89
|
+
print("Invalid arguments!")
|
|
90
|
+
processArg("help")
|
|
91
|
+
else:
|
|
92
|
+
packName = args[0]
|
|
93
|
+
|
|
94
|
+
result = parse(args[1])
|
|
95
|
+
|
|
96
|
+
if (not all([result.scheme, result.netloc])):
|
|
97
|
+
print("Invalid arguments!")
|
|
98
|
+
processArg("help")
|
|
99
|
+
else:
|
|
100
|
+
URL = args[1]
|
|
101
|
+
|
|
102
|
+
for item in args:
|
|
103
|
+
if (item.startswith("--")):
|
|
104
|
+
result = processArg(item.removeprefix("--"), "--")
|
|
105
|
+
if (isinstance(result, str)):
|
|
106
|
+
branch = result
|
|
107
|
+
if (isinstance(result, bool)):
|
|
108
|
+
build = True
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
br = ""
|
|
113
|
+
if (branch.__len__() > 0):
|
|
114
|
+
br = f" at branch {branch}"
|
|
115
|
+
|
|
116
|
+
curOS = checkOS()
|
|
117
|
+
|
|
118
|
+
path = ""
|
|
119
|
+
|
|
120
|
+
if (curOS == "WINDOWS"):
|
|
121
|
+
path += os.getenv("LOCALAPPDATA")
|
|
122
|
+
else:
|
|
123
|
+
path += os.getenv("HOME")
|
|
124
|
+
|
|
125
|
+
def showProg(op_code, cur_count, max_count=None, message=''):
|
|
126
|
+
finalStr = ""
|
|
127
|
+
|
|
128
|
+
match op_code:
|
|
129
|
+
case 0:
|
|
130
|
+
finalStr += "[Beginning Clone]: "
|
|
131
|
+
case 1:
|
|
132
|
+
finalStr += "[Finished Cloning]: "
|
|
133
|
+
case 2:
|
|
134
|
+
finalStr += "[Counting Objects]: "
|
|
135
|
+
case 3:
|
|
136
|
+
finalStr += "[Compressing Objects]: "
|
|
137
|
+
case 4:
|
|
138
|
+
finalStr += "[Writing objects]: "
|
|
139
|
+
case 5:
|
|
140
|
+
finalStr += "[Recieving Objects]: "
|
|
141
|
+
case 6:
|
|
142
|
+
finalStr += "[Unimplemented Code]: "
|
|
143
|
+
case 7:
|
|
144
|
+
finalStr += "[Unimplemented Code]:"
|
|
145
|
+
case 8:
|
|
146
|
+
finalStr += "[Checking Out Branch]"
|
|
147
|
+
|
|
148
|
+
finalStr += " | " + str(cur_count)
|
|
149
|
+
if (max_count is not None):
|
|
150
|
+
finalStr += " / " + str(max_count)
|
|
151
|
+
else:
|
|
152
|
+
finalStr += " / ?"
|
|
153
|
+
|
|
154
|
+
if (message is not None and message.__len__() > 0):
|
|
155
|
+
finalStr += "\n" + message
|
|
156
|
+
|
|
157
|
+
if (curOS == "WINDOWS"):
|
|
158
|
+
os.system("cls")
|
|
159
|
+
else:
|
|
160
|
+
os.system("clear")
|
|
161
|
+
|
|
162
|
+
print(f"Getting package {packName} from {URL}{br}.")
|
|
163
|
+
print(finalStr)
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
fullPath = path + "/Temp_ptgit/" + packName
|
|
168
|
+
|
|
169
|
+
if (Path(fullPath).exists()):
|
|
170
|
+
import shutil
|
|
171
|
+
shutil.rmtree(fullPath)
|
|
172
|
+
|
|
173
|
+
repo = Repo.clone_from(URL, fullPath, showProg)
|
|
174
|
+
|
|
175
|
+
zip_path = fullPath + "/" + packName + ".zip"
|
|
176
|
+
|
|
177
|
+
print(f'zip {zip_path} {os.curdir}')
|
|
178
|
+
os.chdir(fullPath)
|
|
179
|
+
if curOS == "WINDOWS":
|
|
180
|
+
input("You MUST have 7zip installed for this command to work, press ENTER to continue")
|
|
181
|
+
zip_process = run(["7z", "a", "-tzip", zip_path, ".\\"])
|
|
182
|
+
|
|
183
|
+
while zip_process.returncode is None:
|
|
184
|
+
from time import sleep
|
|
185
|
+
if (curOS == "WINDOWS"):
|
|
186
|
+
os.system("cls")
|
|
187
|
+
else:
|
|
188
|
+
os.system("clear")
|
|
189
|
+
|
|
190
|
+
print(zip_path.stdout.read())
|
|
191
|
+
|
|
192
|
+
sleep(0.01)
|
|
193
|
+
|
|
194
|
+
print(zip_process.returncode)
|
|
195
|
+
else:
|
|
196
|
+
zip_process = run(['zip', '-r', zip_path, "./"])
|
|
197
|
+
|
|
198
|
+
while zip_process.returncode is None:
|
|
199
|
+
from time import sleep
|
|
200
|
+
if (curOS == "WINDOWS"):
|
|
201
|
+
os.system("cls")
|
|
202
|
+
else:
|
|
203
|
+
os.system("clear")
|
|
204
|
+
|
|
205
|
+
print(zip_path.stdout.read())
|
|
206
|
+
|
|
207
|
+
sleep(0.01)
|
|
208
|
+
|
|
209
|
+
print(zip_process.returncode)
|
|
210
|
+
|
|
211
|
+
process = run(['pip', 'install', Path(zip_path).resolve().__str__()])
|
|
212
|
+
|
|
213
|
+
while process.returncode is None:
|
|
214
|
+
from time import sleep
|
|
215
|
+
if (curOS == "WINDOWS"):
|
|
216
|
+
os.system("cls")
|
|
217
|
+
else:
|
|
218
|
+
os.system("clear")
|
|
219
|
+
|
|
220
|
+
print(process.stdout.read())
|
|
221
|
+
|
|
222
|
+
sleep(0.01)
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
print("Cleaning up!")
|
|
226
|
+
|
|
227
|
+
import shutil
|
|
228
|
+
shutil.rmtree(path + "/Temp_ptgit/") # Remove any git dirs leftover.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ptgit
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Pip Through Git is a way to install python packages through git.
|
|
5
|
+
Project-URL: Homepage, https://github.com/CharGoldenYT/ptgit
|
|
6
|
+
Project-URL: Issues, https://github.com/CharGoldenYT/ptgit/issues
|
|
7
|
+
Author: CharGoldenYT
|
|
8
|
+
License-Expression: GPL-3.0-or-later
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Requires-Python: >=3.12
|
|
13
|
+
Requires-Dist: gitpython
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
# Python Packages through git repositories! | PTGit
|
|
17
|
+
|
|
18
|
+
PTGit (Pip through Git) is an alternative pip install method that allows you to install python packages directly through a git repository
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## Adding better compatibility with this tool
|
|
22
|
+
|
|
23
|
+
If you would like the tool to be able to run smoother with YOUR project, simply include a built package with the following structure in your project
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
Root
|
|
27
|
+
|
|
|
28
|
+
| packaged
|
|
29
|
+
|
|
|
30
|
+
|___ pgit.tar.gz
|
|
31
|
+
|
|
|
32
|
+
|___ pgit_details.whl (optional)
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Useage
|
|
36
|
+
|
|
37
|
+
`python -m ptgit packagename sourceURL`
|
|
38
|
+
|
|
39
|
+
Installs `packagename` from `sourceURL`
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
ptgit/__configReader__.py,sha256=md24NrTfb_weiSAi_85eB35ErvzDXNZF4YCLJ6Whv0o,1335
|
|
2
|
+
ptgit/__init__.py,sha256=cjxjLZ4zK5NOF0F5HqS1B5bsvapuAXqnk_KrUxOba9M,14
|
|
3
|
+
ptgit/__main__.py,sha256=ixtqvK45-l8OyV8aermmq9QRRIexMd_-6KVoWTmOQ8I,5992
|
|
4
|
+
ptgit-1.0.0.dist-info/METADATA,sha256=X-T0BuaX9LNL3nP2ZUvroOqHpvnkbSh7k0HDFyAjlus,1085
|
|
5
|
+
ptgit-1.0.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
|
|
6
|
+
ptgit-1.0.0.dist-info/licenses/LICENSE,sha256=awBs0tB8MeP1A6MylQEfaCThN4xA-jZdUib8zgbiG94,1061
|
|
7
|
+
ptgit-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Char
|
|
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.
|