Sadr 0.1.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.
- sadr/__init__.py +8 -0
- sadr/pypi.py +83 -0
- sadr-0.1.0.dist-info/METADATA +35 -0
- sadr-0.1.0.dist-info/RECORD +6 -0
- sadr-0.1.0.dist-info/WHEEL +5 -0
- sadr-0.1.0.dist-info/top_level.txt +1 -0
sadr/__init__.py
ADDED
sadr/pypi.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
import subprocess as sp
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
class PyPI:
|
|
6
|
+
def __init__(self, pr_dir="."):
|
|
7
|
+
self.pr_dir = Path(pr_dir).resolve()
|
|
8
|
+
self.dist_dir = self.pr_dir / "dist"
|
|
9
|
+
|
|
10
|
+
def _run(self, *cmd):
|
|
11
|
+
return sp.run(
|
|
12
|
+
[sys.executable, *cmd],
|
|
13
|
+
cwd=self.pr_dir,
|
|
14
|
+
check=True
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
def validate(self):
|
|
18
|
+
required = ["pyproject.toml", "README.md"]
|
|
19
|
+
missing = [
|
|
20
|
+
file for file in required
|
|
21
|
+
if not (self.pr_dir / file).is_file()
|
|
22
|
+
]
|
|
23
|
+
if missing:
|
|
24
|
+
raise FileNotFoundError(
|
|
25
|
+
f"Missing project files: {', '.join(missing)}"
|
|
26
|
+
)
|
|
27
|
+
return True
|
|
28
|
+
|
|
29
|
+
def build(self, clean=False):
|
|
30
|
+
self.val()
|
|
31
|
+
if clean and self.dist_dir.exists():
|
|
32
|
+
for file in self.dist_dir.iterdir():
|
|
33
|
+
if file.is_file(): file.unlink()
|
|
34
|
+
self._run("-m", "build")
|
|
35
|
+
return list(self.dist_dir.glob("*"))
|
|
36
|
+
|
|
37
|
+
def inspect(self):
|
|
38
|
+
if not self.dist_dir.exists(): raise FileNotFoundError("Distribution directory not found")
|
|
39
|
+
files = list(self.dist_dir.glob("*"))
|
|
40
|
+
if not files: raise FileNotFoundError("No distributions found")
|
|
41
|
+
return [
|
|
42
|
+
{
|
|
43
|
+
"name": file.name,
|
|
44
|
+
"size": file.stat().st_size,
|
|
45
|
+
"type": file.suffix
|
|
46
|
+
}
|
|
47
|
+
for file in files
|
|
48
|
+
if file.is_file()
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
def check_twine(self):
|
|
52
|
+
try:
|
|
53
|
+
self._run("-m", "twine", "--version")
|
|
54
|
+
return True
|
|
55
|
+
except sp.CalledProcessError: return False
|
|
56
|
+
|
|
57
|
+
def check(self):
|
|
58
|
+
if not self.check_twine(): raise RuntimeError("Twine is not installed")
|
|
59
|
+
self._run(
|
|
60
|
+
"-m", "twine",
|
|
61
|
+
"check",
|
|
62
|
+
"dist/*"
|
|
63
|
+
)
|
|
64
|
+
return True
|
|
65
|
+
|
|
66
|
+
def upload(self, token, repository="pypi"):
|
|
67
|
+
if not token: raise ValueError("PyPI API token cannot be empty")
|
|
68
|
+
if not self.dist_dir.exists(): raise FileNotFoundError("Build the project first")
|
|
69
|
+
distributions = [
|
|
70
|
+
str(file)
|
|
71
|
+
for file in self.dist_dir.glob("*")
|
|
72
|
+
if file.is_file()
|
|
73
|
+
]
|
|
74
|
+
if not distributions: raise FileNotFoundError("No distributions to upload")
|
|
75
|
+
self._run(
|
|
76
|
+
"-m", "twine",
|
|
77
|
+
"upload",
|
|
78
|
+
"--repository", repository,
|
|
79
|
+
"--username", "__token__",
|
|
80
|
+
"--password", token,
|
|
81
|
+
*distributions
|
|
82
|
+
)
|
|
83
|
+
return True
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: Sadr
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Python package publishing framework
|
|
5
|
+
Keywords: pypi python publishing package
|
|
6
|
+
Classifier: Programming Language :: Python :: 3
|
|
7
|
+
Classifier: Operating System :: OS Independent
|
|
8
|
+
Classifier: Topic :: Software Development :: Build Tools
|
|
9
|
+
Requires-Python: >=3.8
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
Requires-Dist: requests>=2.31.0
|
|
12
|
+
Dynamic: classifier
|
|
13
|
+
Dynamic: description
|
|
14
|
+
Dynamic: description-content-type
|
|
15
|
+
Dynamic: keywords
|
|
16
|
+
Dynamic: requires-dist
|
|
17
|
+
Dynamic: requires-python
|
|
18
|
+
Dynamic: summary
|
|
19
|
+
|
|
20
|
+
# Sadr
|
|
21
|
+
|
|
22
|
+
A Python package publishing framework.
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
pip install Sadr
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from Sadr.pypi import PyPI
|
|
32
|
+
|
|
33
|
+
sadr = PyPI(".")
|
|
34
|
+
sadr.build()
|
|
35
|
+
```
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
sadr/__init__.py,sha256=OYVmVwIfIDax3N8g1oWdlW6GzIXALuVssC58PkbCmYY,121
|
|
2
|
+
sadr/pypi.py,sha256=ooY4yLRqiTlyJ_uUGnsPVrw2vaDqJFPWU9IgAcE-GCY,2578
|
|
3
|
+
sadr-0.1.0.dist-info/METADATA,sha256=1R3Cw2CvCmeRpbxZrEfbKoMZW7TXOVL1ScqrhhKptsY,742
|
|
4
|
+
sadr-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
5
|
+
sadr-0.1.0.dist-info/top_level.txt,sha256=b0RjO8xluUPr_bJd4yzGbfzosA06mDmbJ0gtjJmV1qA,5
|
|
6
|
+
sadr-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
sadr
|