myopy
Run blind python files.
This single class package, provides python objects to a python file at run time. This is ideal for configuration files where the user does not need to know where an object comes from or how to initialize it. It allows the python file to be blind to the origin of it's objects, removing the need for imports, object initializations or convoluted subclassing.
This is pretty much a standalone clone of the way the amazing qutebrowser handles it's config files.
Feel free to copy paste the PyFile class if you don't want the added dependency.
Installation
pip install myopy
Usage
Say you want to allow the user to change a dict containing some settings for an application in a configuration file called config.py:
In the application you would have something along the lines of:
from myopy import PyFile
user_dict = {'something': 2}
config = PyFile('path/to/config.py')
# we provide the config file the user_dict in the 'settings' variable
config.provide(settings=user_dict)
module = config.run() # returns a module object
print('after running config: ', user_dict)
print('module: ', module)
And in the user facing config.py, the user_dict object would be provided in the settings variable, and the user can change its values at will:
print('in config: ', settings)
settings['something_else'] = 4
settings['something'] = 3
The output would be:
in config: {'something': 2}
after running config: {'something': 3, 'something_else': 4}
module: <module 'config' from 'path/to/config.py'>
the user_dict is modified in place.
Metadata
Release files for myopy 1.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| myopy-1.1.2.tar.gz | 4.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| myopy-1.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.5 kB
Release files / myopy-1.1.2.tar.gz
| Download URL | myopy-1.1.2.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c65e4a4edaabec03568e6a9b0e73e67fce2bf23ffa42f40455bd8d1fc2bf780c
|
|
BLAKE2b-256 checksum How to use checksums |
0dabc35d0c9ef5d07aeeba6750b082f3e258e1741a2a1628bb0c8c406f200e2a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.8 CPython/3.8.5 Linux/5.8.1-arch1-1
|
Release files / myopy-1.1.2-py3-none-any.whl
| Download URL | myopy-1.1.2-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f820beba1870cd5a0bface9611e728df66f1c87a73264080366125cbd38e9dcf
|
|
BLAKE2b-256 checksum How to use checksums |
1ad3c4c8bdc87de5ef4570782591e976073e679f4e3cc9cff020e9cb4486857a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.8 CPython/3.8.5 Linux/5.8.1-arch1-1
|