Generate configuration files for classes.
Project description
pyfigure
Generate configuration files for classes.
Installation
pip install pyfigure
Usage
To generate a configuration file for a class, you must extend the class with Configurable, from the pyfigure module.
Then, to add options to the configuration, create a new Config class, and add variables of the Option class.
class YourClass(Configurable):
class Config:
option_name: type = Option(
default,
parse,
description,
)
Where the arguments are as follows:
| argument | description |
|---|---|
default |
The default value of the option |
description |
A comment to explain what the option is for |
parse |
A function that parses the given value, returns a new value or throws an exception |
file.py
from pyfigure import Configurable, Option
from typing import Literal, List
class ExampleClass(Configurable):
#config_file = 'other_file.toml'
class Config:
string_option: str = Option("default", "Any string works here.")
integer_option: int = Option(24, "Any integer here.")
float_option: float = Option(15.55, "Any float.")
bool_option: bool = Option(True, "Any boolean.")
list_option: list = Option(['e', 'a', 'o'], "A list of things.")
int_list_option: List[int] = Option([1, 2, 3], 'A list of integers.')
choice_option: Literal['spam', 'eggs'] = Option('spam', "A list of random things")
def __init__(self):
Configurable.__init__(self)
print(self.config)
ExampleClass()
This class, when initialized, will print:
{
'string_option': 'default',
'integer_option': 24,
'float_option': 15.55,
'bool_option': True,
'list_option': ['e', 'a', 'o'],
'int_list_option': [1, 2, 3],
'choice_option': 'spam'
}
And create a new file:
file.toml
[config]
string_option = "default" # Any string works here.
integer_option = 24 # Any integer here.
float_option = 15.55 # Any float.
bool_option = true # Any boolean.
list_option = ["e", "a", "o"] # A list of things.
int_list_option = [1, 2, 3] # A list of integers.
choice_option = "spam" # A list of random things
To-Do
Rework the type checking system to utilize theDone, the project now depends on typeguard.typinglibrary (Somehow).- Support nested dictionaries.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyfigure-1.1.tar.gz.
File metadata
- Download URL: pyfigure-1.1.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4dc99e26c38a84560f4be18d6810892d74b29b9fd38ecf480aa30e3bde5fa8fb
|
|
| MD5 |
d5c16375958bc4aa656c25a8f066fc14
|
|
| BLAKE2b-256 |
2d0159cb0852419bb515811587bb2ff35ec165697ebe9a799ca07a6e4d1bf48b
|
File details
Details for the file pyfigure-1.1-py3-none-any.whl.
File metadata
- Download URL: pyfigure-1.1-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c82e0f7cc69e18a3f0e16cf4472199288eda91be383a7848c1097ea8180c397f
|
|
| MD5 |
45177d5e2d3014752b63f514926d195a
|
|
| BLAKE2b-256 |
f4901b4661f4f23350d2940ba830bdbbb91bca8418ac3a070b3e4a8b6b06474f
|