effectual 0.5.2__tar.gz → 0.5.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: effectual
3
- Version: 0.5.2
3
+ Version: 0.5.3
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>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "effectual"
3
- version = "0.5.2"
3
+ version = "0.5.3"
4
4
  description = "A python package/script bundler"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -5,12 +5,11 @@ import zipfile
5
5
  from pathlib import Path
6
6
  from time import perf_counter
7
7
  from typing import Any
8
- from watch_lite import getHash
9
8
 
10
- import rtoml
9
+ from watch_lite import getHash
11
10
 
12
11
  from .colors import completeColor, fileColor, folderColor, tagColor
13
- from .config import loadConfig
12
+ from .config import dumpHashes, loadConfig, loadToml
14
13
  from .minifier import minifyFile, minifyToString
15
14
 
16
15
 
@@ -67,7 +66,7 @@ def bundleFiles(
67
66
 
68
67
  def dependencies(minify: bool) -> None:
69
68
  with open("./pyproject.toml", "r", encoding="utf-8") as file:
70
- packages: list[str] = dict(rtoml.load(file)).get("project").get("dependencies") # type: ignore
69
+ packages: list[str] = loadToml(file).get("project").get("dependencies") # type: ignore
71
70
 
72
71
  arguments: list[str] = ["--no-compile", "--quiet", "--no-binary=none", "--no-cache"]
73
72
 
@@ -140,14 +139,14 @@ def main() -> None:
140
139
 
141
140
  if uvHashPath.exists():
142
141
  with open(uvHashPath, "r") as file:
143
- lastHash: dict[Any, Any] = dict(rtoml.load(file)).get("hashes")
142
+ lastHash: dict[Any, Any] = loadToml(file).get("hashes")
144
143
  if currentHash["hashes"] != lastHash:
145
144
  with open(uvHashPath, "w") as file:
146
- rtoml.dump(currentHash, file)
145
+ dumpHashes(currentHash, file)
147
146
  dependencies(minify=minification)
148
147
  else:
149
148
  with open(uvHashPath, "x") as file:
150
- rtoml.dump(currentHash, file)
149
+ dumpHashes(currentHash, file)
151
150
  dependencies(minify=minification)
152
151
 
153
152
  bundleFiles(
@@ -0,0 +1,60 @@
1
+ import io
2
+ from typing import Any
3
+
4
+ import rtoml
5
+
6
+
7
+ def loadToml(tomlFile: str | io.TextIOWrapper) -> dict[str, Any]:
8
+ """Loads a toml file from a specific path to a dictionary
9
+
10
+ Args:
11
+ pathToToml (str | io.TextIOWrapper): Path or object of a toml file
12
+
13
+ Raises:
14
+ RuntimeError: Toml file is incorrectly configured
15
+ RuntimeError: Toml file is can't be located
16
+
17
+ Returns:
18
+ dict[Any, Any]: Dictionary of toml file contents
19
+ """
20
+ try:
21
+ with open(tomlFile, "r", encoding="utf-8") as file:
22
+ return dict(rtoml.load(file)) # type: ignore
23
+ except ValueError as e:
24
+ raise RuntimeError(f"Invalid TOML in {tomlFile}: {e}")
25
+ except FileNotFoundError:
26
+ raise RuntimeError(f"TOML file {tomlFile} not found.")
27
+
28
+
29
+ def loadConfig(configPath: str) -> dict[Any, Any]:
30
+ """Loads effectual config from a file
31
+
32
+ Args:
33
+ configPath (str): Path to the config file
34
+
35
+ Returns:
36
+ dict: Dictionary containing effectual config
37
+ """
38
+ configData: dict[str, Any] = loadToml(configPath)
39
+ if configData is None:
40
+ configData = {
41
+ "sourceDirectory": "./src/",
42
+ "outputDirectory": "./dist/",
43
+ "outputFileName": "bundle.pyz",
44
+ "minification": True,
45
+ "compressionLevel": 5,
46
+ }
47
+ else:
48
+ configData = configData.get("tool").get("effectual")
49
+
50
+ return configData
51
+
52
+
53
+ def dumpHashes(hashesToDump: dict[str, dict[str, str]], file: io.TextIOWrapper) -> None:
54
+ """Dumps hashes in a specific format to a toml file
55
+
56
+ Args:
57
+ hashesToDump (dict[str, dict[str, str]]): Dictionary of hashes to dump as toml
58
+ file (_type_): File object
59
+ """
60
+ return rtoml.dump(hashesToDump, file, pretty=False)
@@ -3,6 +3,7 @@ import time
3
3
  import zipfile
4
4
  from pathlib import Path
5
5
  from typing import Any
6
+
6
7
  from watch_lite import getAllHashes
7
8
 
8
9
  from .colors import completeColor, fileColor, tagColor
@@ -24,7 +24,7 @@ wheels = [
24
24
 
25
25
  [[package]]
26
26
  name = "effectual"
27
- version = "0.4.0"
27
+ version = "0.5.2"
28
28
  source = { editable = "." }
29
29
  dependencies = [
30
30
  { name = "click" },
@@ -1,38 +0,0 @@
1
- from typing import Any
2
-
3
- import rtoml
4
-
5
-
6
- def loadConfig(configPath: str) -> dict[Any, Any]:
7
- """Loads effectual config from a file
8
-
9
- Args:
10
- configPath (str): Path to the config file
11
-
12
- Raises:
13
- RuntimeError: Invalid TOML format
14
- RuntimeError: No configuration file found
15
-
16
- Returns:
17
- dict: _description_
18
- """
19
- try:
20
- with open(configPath, "r", encoding="utf-8") as file:
21
- configData: dict[Any, Any] = dict(rtoml.load(file))
22
- if configData is None:
23
- configData = {
24
- "sourceDirectory": "./src/",
25
- "outputDirectory": "./dist/",
26
- "outputFileName": "bundle.pyz",
27
- "minification": True,
28
- "compressionLevel": 5,
29
- }
30
- else:
31
- configData = configData.get("tool").get("effectual") # type: ignore
32
-
33
- except ValueError as e:
34
- raise RuntimeError(f"Invalid TOML in {configPath}: {e}")
35
- except FileNotFoundError:
36
- raise RuntimeError(f"Configuration file {configPath} not found.")
37
-
38
- return configData
@@ -1,34 +0,0 @@
1
- import hashlib
2
- from multiprocessing import Pool
3
- from pathlib import Path
4
-
5
-
6
- def getFilehash(filePath: Path) -> str:
7
- """Gets the file hash of a single python script
8
-
9
- Args:
10
- filePath (Path): Path to a file
11
-
12
- Returns:
13
- str: Hash of the file
14
- """
15
- with open(filePath, "rb") as file:
16
- fileHash = hashlib.sha1(file.read()).hexdigest()
17
- return fileHash
18
-
19
-
20
- def getAllHashes(sourceDirectory: Path, fileExtension: str) -> set[str]:
21
- """Gets all hashes in directory
22
-
23
- Args:
24
- sourceDirectory (Path): Path to a folder containing files
25
-
26
- Returns:
27
- set[str]: Set containing paths and hashes
28
- """
29
-
30
- with Pool() as pool:
31
- hashList: set[str] = set(
32
- pool.map(getFilehash, sourceDirectory.glob(f"*.{fileExtension}"))
33
- )
34
- return hashList
File without changes
File without changes
File without changes
File without changes
File without changes