a flexible chassis for assembling Python programs from parts
Project description
Chassis 2024
Automatically sequence infrastructure initialization and teardown.
Installation
pip install chassis2024
Brief Explanation
(This is just a teaser. Read the github project pages for more details and a full tutorial.)
The idea of chassis2024 to make it so that you quickly reuse infrastructure.
"Infrastructure" here means things like:
- writing a lock file for your program
- reading config files
- setting up a GUI system (like tkinter), and running a main loop
- populating and processing argparse
- reading a persistence file, and writing back to it when closing
I wanted to make it trivial to combine infrastructure like these, together.
The central challenge was making sure that infrastructure steps are followed in the correct order.
An Example: Hello, world!
Here's a "Hello, world!" program:
import sys
import chassis2024
import chassis2024.basicrun
CHASSIS2024_SPEC = {
"INTERFACES": {"RUN": sys.modules[__name__]}
}
# interface: RUN
def run():
print("Hello, world!")
if __name__ == "__main__":
chassis2024.run()
Execution Nodes
Chassis 2024 infrastructure positions itself within an execution graph.
By default, the execution graph is very basic:
- #1 CLEAR -- the program begins
- #2 RESET -- the program is initialized
- #3 ARGPARSE -- Command Line arguments are parsed
- #4 CONNECT -- files are loaded, resources are connected
- #5 ACTIVATE -- user interface systems are activated
- #6 UP -- the program is running, main loop operations commense
This built-in system is fixed, but there is no default implementation, and it is very flexible, because Chassis 2024 infrastructure can extend the graph via module declarations.
An example from the chassis2024.argparse
package:
CHASSIS2024_SPEC = {
EXECUTES_GRAPH_NODES: [CLEAR_ARGPARSE, RESET_ARGPARSE, ARGPARSE],
EXECUTION_GRAPH_SEQUENCES: [(CLEAR, CLEAR_ARGPARSE, RESET, RESET_ARGPARSE, ARGPARSE)],
INTERFACES: {ARGPARSE: sys.modules[__name__]}
}
Interfaces
The infrastructure pieces glue to one another through "interfaces." Any object or module can be at the end of an interface, but only one thing can implement a given interface.
Similarly, each execution node can activate only one function.
More Complex Example
import sys
import chassis2024
import chassis2024.basicrun
import chassis2024.argparse
import chassis2024.basicjsonpersistence
from chassis2024.words import *
from chassis2024.argparse.words import *
from chassis2024.basicjsonpersistence.words import *
this_module = sys.modules[__name__]
CHASSIS2024_SPEC = {
INTERFACES: {RUN: this_module,
ARGPARSE_CONFIGURE: this_module}
}
EXECUTION_SPEC = {
BASICJSONPERSISTENCE: {
SAVE_AT_EXIT: True,
CREATE_FOLDER: False,
FILEPATH: "./echo_persistence_data.json"
}
}
# interface: ARGPARSE_CONFIGURE
def argparse_configure(parser):
parser.add_argument("-e", "--echo",
help="input string to echo",
default=None)
parser.add_argument("-r", "--repeat-last",
dest="repeat",
help="repeat the last used echo string",
action="store_true")
chassis2024.basicjsonpersistence.argparse_configure(parser)
# interface: RUN
def run():
argparser = chassis2024.interface(ARGPARSE, required=True)
D = chassis2024.interface(PERSISTENCE_DATA, required=True).data()
if argparser.args.echo is not None:
print(argparser.args.echo)
D["msg"] = argparser.args.echo # saved automatically
else:
print(D.get("msg", "use -e to specify string to echo"))
if __name__ == "__main__":
chassis2024.run()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file chassis2024-1.0.0.tar.gz
.
File metadata
- Download URL: chassis2024-1.0.0.tar.gz
- Upload date:
- Size: 14.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74e746209a84011eb77abc0cbfef5885b00d758b6517096bb5e56f9391ff95cd |
|
MD5 | e44259e34bec908b4d04d038042b8fc1 |
|
BLAKE2b-256 | 75d0b3bc1a719fecaf7e1c503573c9850675956af2975f17d0a61bcb2a9eeaa6 |
File details
Details for the file chassis2024-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: chassis2024-1.0.0-py3-none-any.whl
- Upload date:
- Size: 16.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 919adb9948053abf3b01f0a29884292657bd7e84080ed60709faea5396537e57 |
|
MD5 | 215ed2ca94304b4744b5b5671d527bf8 |
|
BLAKE2b-256 | 53d49a32335eb60ce53f65228ab4bf9b23681db18b68f9f71dbf869ff4ab275e |