effectual 0.5.7__py3-none-any.whl → 0.7.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.
- effectual/build.py +29 -19
- effectual/developer.py +7 -18
- {effectual-0.5.7.dist-info → effectual-0.7.0.dist-info}/METADATA +3 -3
- effectual-0.7.0.dist-info/RECORD +11 -0
- effectual/treeshake.py +0 -19
- effectual-0.5.7.dist-info/RECORD +0 -12
- {effectual-0.5.7.dist-info → effectual-0.7.0.dist-info}/WHEEL +0 -0
- {effectual-0.5.7.dist-info → effectual-0.7.0.dist-info}/entry_points.txt +0 -0
- {effectual-0.5.7.dist-info → effectual-0.7.0.dist-info}/licenses/LICENSE +0 -0
effectual/build.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
import importlib
|
2
1
|
import os
|
3
2
|
import shutil
|
4
3
|
import zipfile
|
@@ -10,8 +9,7 @@ from watch_lite import getHash
|
|
10
9
|
|
11
10
|
from .colors import completeColor, fileColor, folderColor, tagColor
|
12
11
|
from .config import dumpHashes, loadConfig, loadToml
|
13
|
-
from .transformations import minifyToString
|
14
|
-
from .treeshake import cleanPackages
|
12
|
+
from .transformations import minifyFile, minifyToString
|
15
13
|
|
16
14
|
|
17
15
|
def bundleFiles(
|
@@ -20,6 +18,7 @@ def bundleFiles(
|
|
20
18
|
outputFileName: str = "bundle.pyz",
|
21
19
|
compressionLevel: int = 5,
|
22
20
|
minification: bool = True,
|
21
|
+
freshHash: bool = False,
|
23
22
|
) -> None:
|
24
23
|
"""Bundles dependencies and scripts into a single .pyz archive
|
25
24
|
|
@@ -29,13 +28,11 @@ def bundleFiles(
|
|
29
28
|
outputFileName (str): Name of the output bundle
|
30
29
|
compressionLevel (int): Compression level for the bundle from 0-9
|
31
30
|
minification (bool): If the scripts should be minified
|
31
|
+
freshHash (bool): Is the pyproject hash different then previously?
|
32
32
|
"""
|
33
33
|
outputDirectory.mkdir(parents=True, exist_ok=True)
|
34
34
|
outputPath: Path = outputDirectory / outputFileName
|
35
35
|
|
36
|
-
if outputPath.exists():
|
37
|
-
outputPath.unlink()
|
38
|
-
|
39
36
|
with zipfile.ZipFile(
|
40
37
|
outputPath,
|
41
38
|
"w",
|
@@ -44,14 +41,26 @@ def bundleFiles(
|
|
44
41
|
) as bundler:
|
45
42
|
cachePath: Path = Path("./.effectual_cache/cachedPackages")
|
46
43
|
if cachePath.exists():
|
47
|
-
if
|
44
|
+
if Path.iterdir(cachePath):
|
48
45
|
totalSize: int = int(0)
|
49
46
|
for cachedFile in cachePath.rglob("*"):
|
50
47
|
if cachedFile.is_dir() and not any(cachedFile.iterdir()):
|
51
48
|
continue
|
52
49
|
totalSize += cachedFile.stat().st_size
|
53
|
-
|
54
|
-
|
50
|
+
stringCachedFile = str(cachedFile)
|
51
|
+
if (
|
52
|
+
cachedFile.suffix
|
53
|
+
in (".pyc", ".pyd", "pyi", ".exe", ".typed", ".so")
|
54
|
+
or "__pycache__" in stringCachedFile
|
55
|
+
or ".dist-info" in stringCachedFile
|
56
|
+
or ".lock" in stringCachedFile
|
57
|
+
):
|
58
|
+
continue
|
59
|
+
else:
|
60
|
+
if cachedFile.suffix == ".py" and minification and freshHash:
|
61
|
+
minifyFile(cachedFile)
|
62
|
+
arcName: str = str(cachedFile.relative_to(cachePath))
|
63
|
+
bundler.write(cachedFile, arcname=arcName)
|
55
64
|
|
56
65
|
print(
|
57
66
|
f"{tagColor('bundling')} || uv dependencies {folderColor(totalSize)}" # noqa: E501
|
@@ -68,7 +77,8 @@ def bundleFiles(
|
|
68
77
|
print(f"{tagColor('OUTPUT')} || {outputFileName} {fileColor(outputPath)}")
|
69
78
|
|
70
79
|
|
71
|
-
def dependencies(
|
80
|
+
def dependencies() -> None:
|
81
|
+
"""Installs relevant dependencies"""
|
72
82
|
packages: list[str] = (
|
73
83
|
loadToml("./pyproject.toml").get("project").get("dependencies")
|
74
84
|
)
|
@@ -88,13 +98,6 @@ def dependencies(minify: bool) -> None:
|
|
88
98
|
f'uv pip install "{key}" {argumentString} --target {pathToInstallTo}'
|
89
99
|
)
|
90
100
|
|
91
|
-
print(f"{tagColor('optimizing')} || {', '.join(packages)}")
|
92
|
-
|
93
|
-
multiprocessing = importlib.import_module("multiprocessing")
|
94
|
-
|
95
|
-
with multiprocessing.Pool(processes=multiprocessing.cpu_count()) as pool:
|
96
|
-
pool.map(cleanPackages, Path(pathToInstallTo).rglob("*"))
|
97
|
-
|
98
101
|
|
99
102
|
def main() -> None:
|
100
103
|
"""Entrypoint
|
@@ -128,16 +131,22 @@ def main() -> None:
|
|
128
131
|
currentHash["hashes"]["pyproject"] = getHash("./pyproject.toml")
|
129
132
|
currentHash["hashes"]["lock"] = getHash("./uv.lock")
|
130
133
|
|
134
|
+
freshHash: bool = False
|
135
|
+
|
131
136
|
if uvHashPath.exists():
|
132
137
|
lastHash: dict[str, Any] = loadToml(uvHashPath).get("hashes")
|
133
138
|
if currentHash["hashes"] != lastHash:
|
134
139
|
with open(uvHashPath, "w") as file:
|
135
140
|
dumpHashes(currentHash, file)
|
136
|
-
dependencies(
|
141
|
+
dependencies()
|
142
|
+
freshHash = True
|
143
|
+
else:
|
144
|
+
freshHash = False
|
137
145
|
else:
|
138
146
|
with open(uvHashPath, "x") as file:
|
139
147
|
dumpHashes(currentHash, file)
|
140
|
-
dependencies(
|
148
|
+
dependencies()
|
149
|
+
freshHash = True
|
141
150
|
|
142
151
|
bundleFiles(
|
143
152
|
sourceDirectory,
|
@@ -145,6 +154,7 @@ def main() -> None:
|
|
145
154
|
outputFileName,
|
146
155
|
compressionLevel,
|
147
156
|
minification,
|
157
|
+
freshHash,
|
148
158
|
)
|
149
159
|
endTime = perf_counter()
|
150
160
|
|
effectual/developer.py
CHANGED
@@ -4,7 +4,7 @@ import zipfile
|
|
4
4
|
from pathlib import Path
|
5
5
|
from typing import Any
|
6
6
|
|
7
|
-
from
|
7
|
+
from watchfiles import run_process
|
8
8
|
|
9
9
|
from .colors import completeColor, fileColor, tagColor
|
10
10
|
from .config import loadConfig
|
@@ -22,6 +22,7 @@ def bundle(sourceDirectory: Path, outputFile: Path) -> None:
|
|
22
22
|
for pyFile in sourceDirectory.rglob("*.py"):
|
23
23
|
print(f"{tagColor('bundling')} || {pyFile.name} {fileColor(pyFile)}")
|
24
24
|
bundler.write(pyFile, arcname=pyFile.name)
|
25
|
+
|
25
26
|
endTime = time.perf_counter()
|
26
27
|
|
27
28
|
print(completeColor(f"Completed in {endTime - startTime:.4f}s"))
|
@@ -37,24 +38,12 @@ def main() -> None:
|
|
37
38
|
|
38
39
|
outputFile: Path = devBundlePath / outputFileName
|
39
40
|
|
40
|
-
|
41
|
+
run_process(sourceDirectory, target=runCommand, args=(sourceDirectory, outputFile))
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
while True:
|
47
|
-
currentHashSet: set[str] = getAllHashes(str(sourceDirectory))
|
48
|
-
if currentHashSet != lastHashSet:
|
49
|
-
runCommand.kill()
|
50
|
-
runCommand.wait()
|
51
|
-
outputFile.unlink()
|
52
|
-
lastHashSet = currentHashSet
|
53
|
-
print(f"{tagColor('reloaded')} || file change detected")
|
54
|
-
bundle(sourceDirectory, outputFile)
|
55
|
-
runCommand = subprocess.Popen(["uv", "run", outputFile], shell=True)
|
56
|
-
else:
|
57
|
-
time.sleep(0.1)
|
43
|
+
|
44
|
+
def runCommand(sourceDirectory: Path, outputFile: Path) -> None:
|
45
|
+
bundle(sourceDirectory, outputFile)
|
46
|
+
subprocess.Popen(["uv", "run", outputFile], shell=True)
|
58
47
|
|
59
48
|
|
60
49
|
if __name__ == "__main__":
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: effectual
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.7.0
|
4
4
|
Summary: A python package/script bundler
|
5
5
|
Project-URL: Homepage, https://github.com/effectualpy/effectual
|
6
6
|
Author-email: jake <jakewdr@proton.me>
|
@@ -18,7 +18,7 @@ Requires-Dist: python-minifier>=2.11.3
|
|
18
18
|
Requires-Dist: rtoml>=0.11.0
|
19
19
|
Requires-Dist: ruff>=0.8.0
|
20
20
|
Requires-Dist: termcolor>=2.4.0
|
21
|
-
Requires-Dist:
|
21
|
+
Requires-Dist: watchfiles>=0.24.0
|
22
22
|
Description-Content-Type: text/markdown
|
23
23
|
|
24
24
|
# effectual
|
@@ -53,7 +53,7 @@ sourceDirectory = "./src/"
|
|
53
53
|
outputDirectory = "./dist/"
|
54
54
|
outputFileName = "bundle.pyz"
|
55
55
|
minification = true
|
56
|
-
compressionLevel=5
|
56
|
+
compressionLevel = 5
|
57
57
|
```
|
58
58
|
|
59
59
|
Note you must have a \_\_main\_\_.py entrypoint for this to work
|
@@ -0,0 +1,11 @@
|
|
1
|
+
effectual/__init__.py,sha256=Hg_RSVgpLZvaeBUqt5uL_r5YIDsVdKPcFE2L5WJVYbM,482
|
2
|
+
effectual/build.py,sha256=P5XqH4OxbKAxa46HSFC1T3KE6xQiB_NBl8yry-MW9uc,5936
|
3
|
+
effectual/colors.py,sha256=na7SEUSXM7aHvEKeIAn5shrZJtrBYq_ZUp121GRO_PQ,1411
|
4
|
+
effectual/config.py,sha256=Z99V7AnJpSWuo-aEz10TDj5BAaT7tboGJUjggj-HQh4,1798
|
5
|
+
effectual/developer.py,sha256=bFE-jQM7TtegRknXEmz1gd_P3ga--anOvmruxRJpprE,1614
|
6
|
+
effectual/transformations.py,sha256=7GHgQWzin2J1W62yMReHXaYIChXc3f0rNJA-yY4LDEI,1313
|
7
|
+
effectual-0.7.0.dist-info/METADATA,sha256=GvekOJlxB_-7dE2lOdR4sweyhLDActVIqAx9COJnWZI,2590
|
8
|
+
effectual-0.7.0.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
|
9
|
+
effectual-0.7.0.dist-info/entry_points.txt,sha256=1W7EjlLZkw_Wz8V1SgdzzDis-CRE5IINyg74upsB0zU,40
|
10
|
+
effectual-0.7.0.dist-info/licenses/LICENSE,sha256=RrVXS_K_FctToNx9BLuZm9vbcpTi3PHNzWMaz7QyVeg,1082
|
11
|
+
effectual-0.7.0.dist-info/RECORD,,
|
effectual/treeshake.py
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
from pathlib import Path
|
2
|
-
|
3
|
-
from .transformations import minifyFile
|
4
|
-
|
5
|
-
|
6
|
-
def cleanPackages(file: Path) -> None:
|
7
|
-
stringFile: str = str(file)
|
8
|
-
if (
|
9
|
-
file.suffix in (".pyc", ".pyd", ".exe", ".typed")
|
10
|
-
or "__pycache__" in stringFile
|
11
|
-
or ".dist-info" in stringFile
|
12
|
-
or ".lock" in stringFile
|
13
|
-
):
|
14
|
-
try:
|
15
|
-
file.unlink()
|
16
|
-
except PermissionError:
|
17
|
-
pass
|
18
|
-
elif file.suffix == ".py":
|
19
|
-
minifyFile(file)
|
effectual-0.5.7.dist-info/RECORD
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
effectual/__init__.py,sha256=Hg_RSVgpLZvaeBUqt5uL_r5YIDsVdKPcFE2L5WJVYbM,482
|
2
|
-
effectual/build.py,sha256=c1GyLhIqybBhED8eou8B7GOXwpmeSWvxpv4PBkYgLtQ,5463
|
3
|
-
effectual/colors.py,sha256=na7SEUSXM7aHvEKeIAn5shrZJtrBYq_ZUp121GRO_PQ,1411
|
4
|
-
effectual/config.py,sha256=Z99V7AnJpSWuo-aEz10TDj5BAaT7tboGJUjggj-HQh4,1798
|
5
|
-
effectual/developer.py,sha256=D_KX6YYWgHF5b6ri-48ai1RqxqiIqZ0Rw-dVHG9NLHE,2052
|
6
|
-
effectual/transformations.py,sha256=7GHgQWzin2J1W62yMReHXaYIChXc3f0rNJA-yY4LDEI,1313
|
7
|
-
effectual/treeshake.py,sha256=_6poBa-Z1w8FiWzY3-KJabPCbdA8K7XaZs5xSGrdGjI,486
|
8
|
-
effectual-0.5.7.dist-info/METADATA,sha256=BK1f6aSsUeosQ2IA9mZQkGn9teibuMghZD36s2ja7tU,2587
|
9
|
-
effectual-0.5.7.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
|
10
|
-
effectual-0.5.7.dist-info/entry_points.txt,sha256=1W7EjlLZkw_Wz8V1SgdzzDis-CRE5IINyg74upsB0zU,40
|
11
|
-
effectual-0.5.7.dist-info/licenses/LICENSE,sha256=RrVXS_K_FctToNx9BLuZm9vbcpTi3PHNzWMaz7QyVeg,1082
|
12
|
-
effectual-0.5.7.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|