A standardized configuration object for reference genome assemblies
Project description
Yacman is a YAML configuration manager. It provides some convenience tools for dealing with YAML configuration files.
Please see this Python notebook for features and usage instructions and this document for API documentation.
Upgrading guide
How to upgrade to yacman v1.0.0. Yacman v1 provides 2 feature upgrades:
- Constructors take the form of
yacman.YAMLConfigManager.from_x(...)functions, to make it clearer how to create a newymobject. - It separates locks into read locks and write locks, to allow mutliple simultaneous readers.
The v0.9.3 transition release has 3 versions of the basic yacman object, namely:
- attmap-based version (YacAttMap)
- non-attmap-but-mostly-compatible (YAMLConfigManager)
- new future object (FutureYAMLConfigManager...), which is explicitly not backwards compatible with the attmap version.
In v1.0.0, FutureYAMLConfigManager will be renamed to YAMLConfigManager and the old stuff will be removed. Here's how to transition your code:
Use the FutureYAMLConfigManager in 0.9.3
- Import the FutureYAMLConfigManager
Change from:
from yacman import YAMLConfigManager
to
from yacman import FutureYAMLConfigManager as YAMLConfigManager
Once we switch from v0.9.3 to v1.X.X, you will need to switch back.
- Update any context managers to use
write_lockorread_lock
from yacman import write_lock, read_lock
Change
with ym as locked_ym:
locked_ym.write()
to
with write_lock(ym) as locked_ym:
locked_ym.rebase()
locked_ym.write()
In the new system, you must use rebase() before write() if you want to allow for multiple processes to possibly have written the file since you read it in.
More examples:
from yacman import FutureYAMLConfigManager as YAMLConfigManager
from yacman import read_lock, write_lock
data = {"my_list": [1,2,3], "my_int": 8, "my_str": "hello world!", "my_dict": {"nested_val": 15}}
ym = YAMLConfigManager(data)
ym["my_list"]
ym["my_int"]
ym["my_dict"]
# Use in a context manager to write to the file
ym["new_var"] = 15
# Use a write-lock, and rebase before writing to ensure you capture any changes since you loaded the file
with write(ym) as locked_ym:
locked_ym.rebase()
locked_ym.write()
# use a read lock to rebase -- this will replay any in-memory updates on top of whatever is re-read from the file
with read_lock(ym) as locked_ym:
locked_ym.rebase()
# use a read lock to reset the in-memory object to whatever is on disk
with read_lock(ym) as locked_ym:
locked_ym.reset()
- Update any constructors to use the
from_{x}functions
You can no longer just create a YAMLConfigManager object directly; now you need to use the constructor helpers.
Examples:
from yacman import FutureYAMLConfigManager as YAMLConfigManager
data = {"my_list": [1,2,3], "my_int": 8, "my_str": "hello world!", "my_dict": {"nested_val": 15}}
file_path = "tests/data/full.yaml"
yaml_data = "myvar: myval"
yacman.YAMLConfigManager.from_yaml_file(file_path)
yacman.YAMLConfigManager.from_yaml_data(yaml_data)
yacman.YAMLConfigManager.from_obj(data)
In the past, you could load from a file and overwrite some attributes with a dict of variables, all from the constructor. Now it would is more explicit:
ym = yacman.YacMan.from_yaml_file(file_path)
ym.update_from_obj(data)
To exppand environment variables in values, use .exp.
ym.exp["text_expand_home_dir"]
From v0.9.3 (using future) to v1.X.X:
Switch back to:
from yacman import YAMLConfigManager
Demos
Some interactive demos
from yacman import FutureYAMLConfigManager as YAMLConfigManager
ym = yacman.YAMLConfigManager(entries=["a", "b", "c"])
ym.to_dict()
ym
print(ym.to_yaml())
ym = YAMLConfigManager(entries={"top": {"bottom": ["a", "b"], "bottom2": "a"}, "b": "c"})
ym
print(ym.to_yaml())
ym = YAMLConfigManager(filepath="tests/data/conf_schema.yaml")
print(ym.to_yaml())
ym
ym = YAMLConfigManager(filepath="tests/data/empty.yaml")
print(ym.to_yaml())
ym = YAMLConfigManager(filepath="tests/data/list.yaml")
print(ym.to_yaml())
ym = YAMLConfigManager(YAMLConfigManager(filepath="tests/data/full.yaml").exp)
print(ym.to_yaml())
ym = YAMLConfigManager(filepath="tests/data/full.yaml")
print(ym.to_yaml(expand=True))
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 yacman-0.9.4.tar.gz.
File metadata
- Download URL: yacman-0.9.4.tar.gz
- Upload date:
- Size: 23.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e10babf0faa1e77ce35d8d00e6be1aa762aef5db6666db09015ba013a65e5f45
|
|
| MD5 |
a699da685ab7ceaee20b995352ebe5c7
|
|
| BLAKE2b-256 |
34b1129c08d94d57efe63143f505b739c3ee631e915e2e83c4e93151e59464fc
|
Provenance
The following attestation bundles were made for yacman-0.9.4.tar.gz:
Publisher:
python-publish.yml on databio/yacman
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
yacman-0.9.4.tar.gz -
Subject digest:
e10babf0faa1e77ce35d8d00e6be1aa762aef5db6666db09015ba013a65e5f45 - Sigstore transparency entry: 672892373
- Sigstore integration time:
-
Permalink:
databio/yacman@a037ccc52f568f0016822833cabebbcf27430806 -
Branch / Tag:
refs/tags/v0.9.4 - Owner: https://github.com/databio
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@a037ccc52f568f0016822833cabebbcf27430806 -
Trigger Event:
release
-
Statement type:
File details
Details for the file yacman-0.9.4-py3-none-any.whl.
File metadata
- Download URL: yacman-0.9.4-py3-none-any.whl
- Upload date:
- Size: 27.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8acec597a8ede98562066611cd1d11ad1f4076fe7ae700d070afe8570c034eed
|
|
| MD5 |
9db9635e737c8eb7a9c1d077a2c0c872
|
|
| BLAKE2b-256 |
4ed0df1427ac21ef5c1ce6fe8f1bfe396e23ee8a025ae078893204a5dd7d4c7d
|
Provenance
The following attestation bundles were made for yacman-0.9.4-py3-none-any.whl:
Publisher:
python-publish.yml on databio/yacman
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
yacman-0.9.4-py3-none-any.whl -
Subject digest:
8acec597a8ede98562066611cd1d11ad1f4076fe7ae700d070afe8570c034eed - Sigstore transparency entry: 672892374
- Sigstore integration time:
-
Permalink:
databio/yacman@a037ccc52f568f0016822833cabebbcf27430806 -
Branch / Tag:
refs/tags/v0.9.4 - Owner: https://github.com/databio
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@a037ccc52f568f0016822833cabebbcf27430806 -
Trigger Event:
release
-
Statement type: