winipedia-utils 0.4.46__py3-none-any.whl → 0.6.12__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.
@@ -0,0 +1 @@
1
+ """__init__ module."""
@@ -0,0 +1,78 @@
1
+ """Build utilities for creating and managing project builds.
2
+
3
+ This module provides functions for building and managing project artifacts,
4
+ including creating build scripts, configuring build environments, and
5
+ handling build dependencies. These utilities help with the packaging and
6
+ distribution of project code.
7
+ """
8
+
9
+ import platform
10
+ from abc import abstractmethod
11
+ from pathlib import Path
12
+
13
+ from winipedia_utils.git.github.workflows.base.base import Workflow
14
+ from winipedia_utils.oop.mixins.mixin import ABCLoggingMixin
15
+
16
+
17
+ class Build(ABCLoggingMixin):
18
+ """Base class for build scripts.
19
+
20
+ Subclass this class and implement the get_artifacts method to create
21
+ a build script for your project. The build method will be called
22
+ automatically when the class is initialized. At the end of the file add
23
+ if __name__ == "__main__":
24
+ YourBuildClass()
25
+ """
26
+
27
+ ARTIFACTS_PATH = Workflow.ARTIFACTS_PATH
28
+
29
+ @classmethod
30
+ @abstractmethod
31
+ def get_artifacts(cls) -> list[Path]:
32
+ """Build the project.
33
+
34
+ Returns:
35
+ list[Path]: List of paths to the built artifacts
36
+ """
37
+
38
+ @classmethod
39
+ def __init__(cls) -> None:
40
+ """Initialize the build script."""
41
+ cls.build()
42
+
43
+ @classmethod
44
+ def build(cls) -> None:
45
+ """Build the project.
46
+
47
+ This method is called by the __init__ method.
48
+ It takes all the files and renames them with -platform.system()
49
+ and puts them in the artifacts folder.
50
+ """
51
+ cls.ARTIFACTS_PATH.mkdir(parents=True, exist_ok=True)
52
+ artifacts = cls.get_artifacts()
53
+ for artifact in artifacts:
54
+ parent = artifact.parent
55
+ if parent != cls.ARTIFACTS_PATH:
56
+ msg = f"You must create {artifact} in {cls.ARTIFACTS_PATH}"
57
+ raise FileNotFoundError(msg)
58
+
59
+ # rename the files with -platform.system()
60
+ new_name = f"{artifact.stem}-{platform.system()}{artifact.suffix}"
61
+ new_path = cls.ARTIFACTS_PATH / new_name
62
+ artifact.rename(new_path)
63
+
64
+
65
+ class WinipediaUtilsBuild(Build):
66
+ """Build script for winipedia_utils."""
67
+
68
+ @classmethod
69
+ def get_artifacts(cls) -> list[Path]:
70
+ """Build the project."""
71
+ paths = [cls.ARTIFACTS_PATH / "build.txt"]
72
+ for path in paths:
73
+ path.write_text("Hello World!")
74
+ return paths
75
+
76
+
77
+ if __name__ == "__main__":
78
+ WinipediaUtilsBuild()