sbuilder 1.1a0__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.
@@ -0,0 +1,89 @@
1
+ Metadata-Version: 2.4
2
+ Name: sbuilder
3
+ Version: 1.1a0
4
+ Summary: A simple Python library to build and run tasks.
5
+ Author: zboxjpg
6
+ License: MIT
7
+ Requires-Python: >=3.10
8
+ Description-Content-Type: text/markdown
9
+
10
+ # SimpleBuilder
11
+ Simple builder is simple python library which I made for myself to provide simple building operations *(and not use .sh/.bat files)*.
12
+
13
+ # Examples
14
+ ## Running an OS specific command
15
+ ```py
16
+ from simple_builder import *
17
+
18
+ platform = GetPlatform()
19
+ cmd = ""
20
+
21
+ if platform == Platform.WIN32:
22
+ cmd = "python"
23
+ else:
24
+ cmd = "python3"
25
+
26
+ b = Builder()
27
+ t = Task(cmd)
28
+ t.AddFlag("-v")
29
+ t.AddArg("main.py")
30
+ b.AddTask(t)
31
+ b.CMDRun()
32
+ ```
33
+
34
+ ## Working with `Status`
35
+ ```py
36
+ from simple_builder import *
37
+
38
+ t_compile = Task("gcc")
39
+ t_compile.AddArg("main", "-o")
40
+ t_compile.AddArg("src/main.c")
41
+
42
+ t_run = Task("./main")
43
+
44
+ b = Builder()
45
+ b.AddTask(t_compile)
46
+
47
+ if b.CMDRun() == Status.OK:
48
+ b.ClearTasks()
49
+ b.AddTask(t_run)
50
+ b.CMDRun()
51
+ ```
52
+
53
+ # Documentation
54
+
55
+ ## Functions
56
+ func `GetPlatform()` - get system platform
57
+
58
+ | System | Value |
59
+ |--------------------------------|-------------------|
60
+ | Linux | Platform.LINUX |
61
+ | Windows | Platform.WIN32 |
62
+ | Windows/Cygwin | Platform.CYGWIN |
63
+ | Windows/MSYS2<br>Windows/MinGW | Platform.MSYS |
64
+ | Mac OS X | Platform.MACOSX |
65
+ | OS/2 | Platform.OS2 |
66
+ | OS/2 EMX | Platform.OS2EMX |
67
+ | RiscOS | Platform.RISCOS |
68
+ | AtheOS | Platform.ATHEOS |
69
+ | FreeBSD 6 | Platform.FREEBSD6 |
70
+ | FreeBSD 7 | Platform.FREEBSD7 |
71
+ | FreeBSD 8 | Platform.FREEBSD8 |
72
+ | FreeBSD N | Platform.FREEBSDN |
73
+
74
+ ## class `Task(cmd, com)`
75
+ - param `cmd` - command to run (e.g. "python", "gcc", etc.)
76
+ - param `com` - print comment instead of standard log
77
+
78
+ func `AddFlag(flag)` - add flag to task (e.g. `.AddFlag("-v")`). This is a fluent method that returns the instance itself for chaining.
79
+
80
+ func `AddArg(arg, flag)` - add arg to task (e.g. `.AddArg("main.c")`, `.AddArg`). This is a fluent method that returns the instance itself for chaining.
81
+
82
+ func `GetFullTask()` - return task as list (e.g. `.GetFullTask()` will return `['gcc', 'main.c', '-o', './app']`)
83
+
84
+ ## class `Builder()`
85
+ func `AddTask(task)` - add task to builder. This is a fluent method that returns the instance itself for chaining.
86
+
87
+ func `ClearTasks()` - remove all tasks. This is a fluent method that returns the instance itself for chaining.
88
+
89
+ func `CMDRun()` - run tasks synchronously. This is a fluent method that returns the instance itself for chaining.
@@ -0,0 +1,80 @@
1
+ # SimpleBuilder
2
+ Simple builder is simple python library which I made for myself to provide simple building operations *(and not use .sh/.bat files)*.
3
+
4
+ # Examples
5
+ ## Running an OS specific command
6
+ ```py
7
+ from simple_builder import *
8
+
9
+ platform = GetPlatform()
10
+ cmd = ""
11
+
12
+ if platform == Platform.WIN32:
13
+ cmd = "python"
14
+ else:
15
+ cmd = "python3"
16
+
17
+ b = Builder()
18
+ t = Task(cmd)
19
+ t.AddFlag("-v")
20
+ t.AddArg("main.py")
21
+ b.AddTask(t)
22
+ b.CMDRun()
23
+ ```
24
+
25
+ ## Working with `Status`
26
+ ```py
27
+ from simple_builder import *
28
+
29
+ t_compile = Task("gcc")
30
+ t_compile.AddArg("main", "-o")
31
+ t_compile.AddArg("src/main.c")
32
+
33
+ t_run = Task("./main")
34
+
35
+ b = Builder()
36
+ b.AddTask(t_compile)
37
+
38
+ if b.CMDRun() == Status.OK:
39
+ b.ClearTasks()
40
+ b.AddTask(t_run)
41
+ b.CMDRun()
42
+ ```
43
+
44
+ # Documentation
45
+
46
+ ## Functions
47
+ func `GetPlatform()` - get system platform
48
+
49
+ | System | Value |
50
+ |--------------------------------|-------------------|
51
+ | Linux | Platform.LINUX |
52
+ | Windows | Platform.WIN32 |
53
+ | Windows/Cygwin | Platform.CYGWIN |
54
+ | Windows/MSYS2<br>Windows/MinGW | Platform.MSYS |
55
+ | Mac OS X | Platform.MACOSX |
56
+ | OS/2 | Platform.OS2 |
57
+ | OS/2 EMX | Platform.OS2EMX |
58
+ | RiscOS | Platform.RISCOS |
59
+ | AtheOS | Platform.ATHEOS |
60
+ | FreeBSD 6 | Platform.FREEBSD6 |
61
+ | FreeBSD 7 | Platform.FREEBSD7 |
62
+ | FreeBSD 8 | Platform.FREEBSD8 |
63
+ | FreeBSD N | Platform.FREEBSDN |
64
+
65
+ ## class `Task(cmd, com)`
66
+ - param `cmd` - command to run (e.g. "python", "gcc", etc.)
67
+ - param `com` - print comment instead of standard log
68
+
69
+ func `AddFlag(flag)` - add flag to task (e.g. `.AddFlag("-v")`). This is a fluent method that returns the instance itself for chaining.
70
+
71
+ func `AddArg(arg, flag)` - add arg to task (e.g. `.AddArg("main.c")`, `.AddArg`). This is a fluent method that returns the instance itself for chaining.
72
+
73
+ func `GetFullTask()` - return task as list (e.g. `.GetFullTask()` will return `['gcc', 'main.c', '-o', './app']`)
74
+
75
+ ## class `Builder()`
76
+ func `AddTask(task)` - add task to builder. This is a fluent method that returns the instance itself for chaining.
77
+
78
+ func `ClearTasks()` - remove all tasks. This is a fluent method that returns the instance itself for chaining.
79
+
80
+ func `CMDRun()` - run tasks synchronously. This is a fluent method that returns the instance itself for chaining.
@@ -0,0 +1,13 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "sbuilder"
7
+ version = "1.1a"
8
+ description = "A simple Python library to build and run tasks."
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ authors = [{name = "zboxjpg"}]
12
+ license = {text = "MIT"}
13
+ dependencies = []
@@ -0,0 +1 @@
1
+ from .sbuilder import *
@@ -0,0 +1,121 @@
1
+ # Simple library to build stuff
2
+ # (c) zboxjpg
3
+
4
+ from datetime import datetime
5
+ from enum import Enum, auto
6
+ import sys
7
+ import time
8
+
9
+ class Platform(Enum):
10
+ LINUX = auto()
11
+ WIN32 = auto()
12
+ CYGWIN = auto()
13
+ MSYS = auto()
14
+ MACOSX = auto()
15
+ OS2 = auto()
16
+ OS2EMX = auto()
17
+ RISCOS = auto()
18
+ ATHEOS = auto()
19
+ FREEBSD6 = auto()
20
+ FREEBSD7 = auto()
21
+ FREEBSD8 = auto()
22
+ FREEBSDN = auto()
23
+
24
+ def GetPlatform():
25
+ match sys.platform:
26
+ case "linux" | "linux2": return Platform.LINUX
27
+ case "win32": return Platform.WIN32
28
+ case "cygwin": return Platform.CYGWIN
29
+ case "msys": return Platform.MSYS
30
+ case "darwin": return Platform.MACOSX
31
+ case "os2": return Platform.OS2
32
+ case "os2emx": return Platform.OS2EMX
33
+ case "riscos": return Platform.RISCOS
34
+ case "atheos": return Platform.ATHEOS
35
+ case "freebsd6": return Platform.FREEBSD6
36
+ case "freebsd7": return Platform.FREEBSD7
37
+ case "freebsd8": return Platform.FREEBSD8
38
+ case "freebsdN": return Platform.FREEBSDN
39
+ case _: raise Exception("Undefined platform `%s`(???)" % (sys.platform))
40
+
41
+ class Status(Enum):
42
+ OK = auto()
43
+ ERROR = auto()
44
+
45
+ class Task():
46
+ """Task class, that contains task itself and args
47
+
48
+ cmd -> command
49
+
50
+ com -> comment (def. None)"""
51
+ def __init__(self, cmd, com = None):
52
+ self.args = []
53
+ self.cmd = cmd
54
+ self.com = com
55
+
56
+ def AddFlag(self, flag = ""):
57
+ """
58
+ Add flag to task
59
+
60
+ e.g. .AddArg("-v")
61
+ """
62
+ self.args.append(flag)
63
+
64
+ return self
65
+
66
+ def AddArg(self, arg = "", flag = ""):
67
+ """
68
+ Add argument to task
69
+
70
+ e.g. .AddArg("main.cpp") OR .AddArg("app", "-o")
71
+ """
72
+ if flag: self.args.extend([flag, arg])
73
+ else: self.args.append(arg)
74
+
75
+ return self
76
+
77
+ def GetFullTask(self):
78
+ """
79
+ Return task as list
80
+
81
+ e.g. ['g++', 'main.cpp', '-o', 'app']
82
+ """
83
+ full_task = [self.cmd]
84
+ full_task.extend(self.args)
85
+ return full_task
86
+
87
+ class Builder():
88
+ "Builder class that contains tasks and used to run tasks sync & async"
89
+ def __init__(self):
90
+ self.tasks : list[Task] = []
91
+
92
+ def ClearTasks(self):
93
+ self.tasks = []
94
+ return self
95
+
96
+ def AddTask(self, task : Task):
97
+ """
98
+ Add task to builder
99
+
100
+ e.g. .AddTask(Task("g++").AddArg("main.cpp").AddArg("app", "-o"))
101
+ """
102
+ self.tasks.append(task)
103
+ return self
104
+
105
+ def CMDRun(self):
106
+ "Run tasks"
107
+ start_time = time.time()
108
+ import subprocess as sp
109
+ for task in self.tasks:
110
+ ft = task.GetFullTask()
111
+ if task.com: print(task.com)
112
+ else:
113
+ print("[SB-CMD]", datetime.now().strftime("%H.%M.%S"), "RUNNING > ", " ".join(ft))
114
+ proc = sp.run(ft)
115
+ res_time = time.time() - start_time
116
+ if proc.returncode:
117
+ print("\n[SB-CMD]", datetime.now().strftime("%H.%M.%S"), "EXITCODE > ", proc.returncode)
118
+ print(f"[SB-CMD] Build finished in just {res_time:.3f}s")
119
+ return Status.ERROR
120
+ print(f"[SB-CMD] Build finished in just {res_time:.3f}s")
121
+ return Status.OK
@@ -0,0 +1,89 @@
1
+ Metadata-Version: 2.4
2
+ Name: sbuilder
3
+ Version: 1.1a0
4
+ Summary: A simple Python library to build and run tasks.
5
+ Author: zboxjpg
6
+ License: MIT
7
+ Requires-Python: >=3.10
8
+ Description-Content-Type: text/markdown
9
+
10
+ # SimpleBuilder
11
+ Simple builder is simple python library which I made for myself to provide simple building operations *(and not use .sh/.bat files)*.
12
+
13
+ # Examples
14
+ ## Running an OS specific command
15
+ ```py
16
+ from simple_builder import *
17
+
18
+ platform = GetPlatform()
19
+ cmd = ""
20
+
21
+ if platform == Platform.WIN32:
22
+ cmd = "python"
23
+ else:
24
+ cmd = "python3"
25
+
26
+ b = Builder()
27
+ t = Task(cmd)
28
+ t.AddFlag("-v")
29
+ t.AddArg("main.py")
30
+ b.AddTask(t)
31
+ b.CMDRun()
32
+ ```
33
+
34
+ ## Working with `Status`
35
+ ```py
36
+ from simple_builder import *
37
+
38
+ t_compile = Task("gcc")
39
+ t_compile.AddArg("main", "-o")
40
+ t_compile.AddArg("src/main.c")
41
+
42
+ t_run = Task("./main")
43
+
44
+ b = Builder()
45
+ b.AddTask(t_compile)
46
+
47
+ if b.CMDRun() == Status.OK:
48
+ b.ClearTasks()
49
+ b.AddTask(t_run)
50
+ b.CMDRun()
51
+ ```
52
+
53
+ # Documentation
54
+
55
+ ## Functions
56
+ func `GetPlatform()` - get system platform
57
+
58
+ | System | Value |
59
+ |--------------------------------|-------------------|
60
+ | Linux | Platform.LINUX |
61
+ | Windows | Platform.WIN32 |
62
+ | Windows/Cygwin | Platform.CYGWIN |
63
+ | Windows/MSYS2<br>Windows/MinGW | Platform.MSYS |
64
+ | Mac OS X | Platform.MACOSX |
65
+ | OS/2 | Platform.OS2 |
66
+ | OS/2 EMX | Platform.OS2EMX |
67
+ | RiscOS | Platform.RISCOS |
68
+ | AtheOS | Platform.ATHEOS |
69
+ | FreeBSD 6 | Platform.FREEBSD6 |
70
+ | FreeBSD 7 | Platform.FREEBSD7 |
71
+ | FreeBSD 8 | Platform.FREEBSD8 |
72
+ | FreeBSD N | Platform.FREEBSDN |
73
+
74
+ ## class `Task(cmd, com)`
75
+ - param `cmd` - command to run (e.g. "python", "gcc", etc.)
76
+ - param `com` - print comment instead of standard log
77
+
78
+ func `AddFlag(flag)` - add flag to task (e.g. `.AddFlag("-v")`). This is a fluent method that returns the instance itself for chaining.
79
+
80
+ func `AddArg(arg, flag)` - add arg to task (e.g. `.AddArg("main.c")`, `.AddArg`). This is a fluent method that returns the instance itself for chaining.
81
+
82
+ func `GetFullTask()` - return task as list (e.g. `.GetFullTask()` will return `['gcc', 'main.c', '-o', './app']`)
83
+
84
+ ## class `Builder()`
85
+ func `AddTask(task)` - add task to builder. This is a fluent method that returns the instance itself for chaining.
86
+
87
+ func `ClearTasks()` - remove all tasks. This is a fluent method that returns the instance itself for chaining.
88
+
89
+ func `CMDRun()` - run tasks synchronously. This is a fluent method that returns the instance itself for chaining.
@@ -0,0 +1,8 @@
1
+ README.md
2
+ pyproject.toml
3
+ sbuilder/__init__.py
4
+ sbuilder/sbuilder.py
5
+ sbuilder.egg-info/PKG-INFO
6
+ sbuilder.egg-info/SOURCES.txt
7
+ sbuilder.egg-info/dependency_links.txt
8
+ sbuilder.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ sbuilder
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+