effectual 0.5.6__tar.gz → 0.6.0__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: effectual
3
- Version: 0.5.6
3
+ Version: 0.6.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>
@@ -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
@@ -30,7 +30,7 @@ sourceDirectory = "./src/"
30
30
  outputDirectory = "./dist/"
31
31
  outputFileName = "bundle.pyz"
32
32
  minification = true
33
- compressionLevel=5
33
+ compressionLevel = 5
34
34
  ```
35
35
 
36
36
  Note you must have a \_\_main\_\_.py entrypoint for this to work
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "effectual"
3
- version = "0.5.6"
3
+ version = "0.6.0"
4
4
  description = "A python package/script bundler"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -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",
@@ -50,8 +47,19 @@ def bundleFiles(
50
47
  if cachedFile.is_dir() and not any(cachedFile.iterdir()):
51
48
  continue
52
49
  totalSize += cachedFile.stat().st_size
53
- arcName = cachedFile.relative_to(cachePath)
54
- bundler.write(cachedFile, arcname=arcName)
50
+ stringCachedFile = str(cachedFile)
51
+ if (
52
+ cachedFile.suffix in (".pyc", ".pyd", ".exe", ".typed")
53
+ or "__pycache__" in stringCachedFile
54
+ or ".dist-info" in stringCachedFile
55
+ or ".lock" in stringCachedFile
56
+ ):
57
+ continue
58
+ else:
59
+ if cachedFile.suffix == ".py" and minification and freshHash:
60
+ minifyFile(cachedFile)
61
+ arcName: str = str(cachedFile.relative_to(cachePath))
62
+ bundler.write(cachedFile, arcname=arcName)
55
63
 
56
64
  print(
57
65
  f"{tagColor('bundling')} || uv dependencies {folderColor(totalSize)}" # noqa: E501
@@ -68,7 +76,8 @@ def bundleFiles(
68
76
  print(f"{tagColor('OUTPUT')} || {outputFileName} {fileColor(outputPath)}")
69
77
 
70
78
 
71
- def dependencies(minify: bool) -> None:
79
+ def dependencies() -> None:
80
+ """Installs relevant dependencies"""
72
81
  packages: list[str] = (
73
82
  loadToml("./pyproject.toml").get("project").get("dependencies")
74
83
  )
@@ -88,13 +97,6 @@ def dependencies(minify: bool) -> None:
88
97
  f'uv pip install "{key}" {argumentString} --target {pathToInstallTo}'
89
98
  )
90
99
 
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
100
 
99
101
  def main() -> None:
100
102
  """Entrypoint
@@ -128,16 +130,22 @@ def main() -> None:
128
130
  currentHash["hashes"]["pyproject"] = getHash("./pyproject.toml")
129
131
  currentHash["hashes"]["lock"] = getHash("./uv.lock")
130
132
 
133
+ freshHash: bool = False
134
+
131
135
  if uvHashPath.exists():
132
136
  lastHash: dict[str, Any] = loadToml(uvHashPath).get("hashes")
133
137
  if currentHash["hashes"] != lastHash:
134
138
  with open(uvHashPath, "w") as file:
135
139
  dumpHashes(currentHash, file)
136
- dependencies(minify=minification)
140
+ dependencies()
141
+ freshHash = True
142
+ else:
143
+ freshHash = False
137
144
  else:
138
145
  with open(uvHashPath, "x") as file:
139
146
  dumpHashes(currentHash, file)
140
- dependencies(minify=minification)
147
+ dependencies()
148
+ freshHash = True
141
149
 
142
150
  bundleFiles(
143
151
  sourceDirectory,
@@ -145,6 +153,7 @@ def main() -> None:
145
153
  outputFileName,
146
154
  compressionLevel,
147
155
  minification,
156
+ freshHash,
148
157
  )
149
158
  endTime = perf_counter()
150
159
 
@@ -48,7 +48,6 @@ def main() -> None:
48
48
  if currentHashSet != lastHashSet:
49
49
  runCommand.kill()
50
50
  runCommand.wait()
51
- outputFile.unlink()
52
51
  lastHashSet = currentHashSet
53
52
  print(f"{tagColor('reloaded')} || file change detected")
54
53
  bundle(sourceDirectory, outputFile)
@@ -5,7 +5,7 @@ tasks:
5
5
  dist:
6
6
  cmds:
7
7
  - uv sync
8
- - uv lock
8
+ - uv lock --upgrade
9
9
  - task: check
10
10
  - uv build
11
11
  - uv publish
@@ -24,7 +24,7 @@ wheels = [
24
24
 
25
25
  [[package]]
26
26
  name = "effectual"
27
- version = "0.5.6"
27
+ version = "0.6.0"
28
28
  source = { editable = "." }
29
29
  dependencies = [
30
30
  { name = "click" },
@@ -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)
File without changes
File without changes
File without changes