wolfsoftware.profiles-config
A basic package for managing profile based configuration files.
https://github.com/developerstoolbox/profiles-config-package
Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (10.5%) to scientific vocabulary
Keywords
Repository
A basic package for managing profile based configuration files.
Basic Info
Statistics
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 3
- Releases: 3
Topics
Metadata Files
README.md
Overview
Profiles Config is a Python package designed to handle configuration files with profiles, key-value pairs, and comments. This package provides functionalities to load and preprocess configuration files, manage comments and whitespace, retrieve profiles and key-value pairs, display the current configuration, and convert the configuration to a dictionary format.
Like many of our packages this was developed as part of another project, but we felt others might be able to make use of it.
Features
- Load and preprocess configuration files: Reads the configuration file, removes comments and extra spaces.
- Handle comments and whitespace: Processes configuration files to ensure clean and accurate data.
- Retrieve profiles and key-value pairs: Access specific profiles and their associated key-value pairs.
- Display the current configuration: Provides a formatted string representation of the current configuration.
- Convert the configuration to a dictionary format: Allows for easy manipulation and access of the configuration data.
Installation
To install the profiles-config package, use pip:
bash
pip install wolfsoftware.profiles-config
Usage
Here is an example of how to use the ConfigHandler class from the profiles-config package:
```python from wolfsoftware.profiles_config import ConfigHandler
Example usage
if name == "main": confighandler = ConfigHandler("config.ini") print("All Profiles:", confighandler.listprofiles()) print("Profile 'profile name 1':", confighandler.getprofile("profile name 1")) print("Value of 'some key' in 'profile name 1':", confighandler.getvalue("profile name 1", "some key")) print("Current Config:\n" + confighandler.displayconfig()) print("Config as dict:\n", confighandler.get_config()) ```
Example Config File
``` [ profile name 1 ]
This is a comment for some key
some key = some value
This is a random comment
This is a random comment also
[profile name 2] # Comment 1 keys1 = value keys2 = another value # comment 2
[profile name 3] # Comment 1 keys1 = value keys2 = another value # comment 2
more comments
comments to end the file
more comments
```
Note the spaces prefixing and suffixing the 'profile name 1' entry. These are stripped as part of the load and cleanse phase.
Once the config file has been loaded, parsed and cleansed the internal representation is a Python dictionary, which would look like this:
{
'profile name 1': {
'some key': 'some value'
},
'profile name 2': {
'keys1': 'value',
'keys2': 'another value'
},
'profile name 3': {
'keys1': 'value',
'keys2': 'another value'
}
}
If you use display_config() then the output would look like this:
``` [profile name 1] some key = some value
[profile name 2] keys1 = value keys2 = another value
[profile name 3] keys1 = value keys2 = another value ```
Class Documentation
ConfigHandler
A class to manage and manipulate configuration files.
Attributes
- filepath: str - Path to the configuration file.
Methods
__init__(self, filepath: str, preserve_case: Optional[bool] = False): Initializes the ConfigHandler with the path to the configuration file.preprocess_file(self) -> str: Reads and preprocesses the configuration file to remove comments and extra spaces.load_config(self) -> None: Loads and processes the configuration file, checking for formatting errors and duplicates.get_config(self) -> Dict: Returns the entire configuration as a dictionary.get_profile(self, profile_name: str) -> Dict[str, str]: Returns a dictionary of key-value pairs for a given profile.get_value(self, profile_name: str, key_name: str) -> str: Returns the value for a specific key in a given profile.list_profiles(self) -> List[str]: Returns a list of all profile names in the configuration file.display_config(self) -> str: Returns the current configuration as a formatted string.
If you set preserve_case=True it will preserve the case for both sections and keys, otherwise is will lowercase BOTH.
Method Details
__init__(self, filepath: str, preserve_case: Optional[bool] = False):- Initializes the ConfigHandler with the path to the configuration file.
- Arguments:
filepath(str): Path to the configuration file.preserve_caseOptional[bool]: Override the default and preserve case sensitivity for names.
preprocess_file(self) -> str:- Reads and preprocesses the configuration file to remove comments and extra spaces.
- Returns:
- str: A string of the preprocessed configuration file.
load_config(self) -> None:- Loads and processes the configuration file, checking for formatting errors and duplicates.
- Raises:
FileNotFoundError: If the configuration file does not exist.ValueError: If there are duplicate keys in a section or parsing errors.
get_config(self) -> Dict:- Returns the entire configuration as a dictionary.
- Returns:
- Dict: A dictionary representation of the entire configuration.
get_profile(self, profile_name: str) -> Dict[str, str]:- Returns a dictionary of key-value pairs for a given profile.
- Arguments:
profile_name(str): The name of the profile.- Returns:
- Dict[str, str]: A dictionary of key-value pairs for the given profile.
- Raises:
KeyError: If the profile is not found in the configuration.
get_value(self, profile_name: str, key_name: str) -> str:- Returns the value for a specific key in a given profile.
- Arguments:
profile_name(str): The name of the profile.key_name(str): The name of the key.- Returns:
- str: The value associated with the key in the given profile.
- Raises:
KeyError: If the profile or key is not found in the configuration.
list_profiles(self) -> List[str]:- Returns a list of all profile names in the configuration file.
- Returns:
- List[str]: A list of all profile names.
display_config(self) -> str:- Returns the current configuration as a formatted string.
- Returns:
- str: The formatted string representation of the configuration.
Owner
- Name: Developers Toolbox
- Login: DevelopersToolbox
- Kind: organization
- Email: github@wolfsoftware.com
- Location: United Kingdom
- Website: https://wolfsoftware.com
- Twitter: wolfsoftware
- Repositories: 24
- Profile: https://github.com/DevelopersToolbox
A selection of tools to help developers. Created by Wolf Software.
Citation (CITATION.cff)
cff-version: 1.2.0
message: If you use this software, please cite it using these metadata.
title: Profile Configuration
abstract: A simple tool to handle profile based configuration files.
type: software
version: 0.1.1
date-released: 2024-06-26
repository-code: https://github.com/DevelopersToolbox/profiles-config-package
keywords:
- "Wolf Software"
- "Software"
license: MIT
authors:
- family-names: "Wolf"
orcid: "https://orcid.org/0009-0007-0983-2072"
GitHub Events
Total
- Delete event: 79
- Issue comment event: 173
- Push event: 139
- Pull request review event: 122
- Pull request event: 161
- Create event: 85
Last Year
- Delete event: 79
- Issue comment event: 173
- Push event: 139
- Pull request review event: 122
- Pull request event: 161
- Create event: 85
Issues and Pull Requests
Last synced: 4 months ago
All Time
- Total issues: 0
- Total pull requests: 122
- Average time to close issues: N/A
- Average time to close pull requests: 3 days
- Total issue authors: 0
- Total pull request authors: 2
- Average comments per issue: 0
- Average comments per pull request: 1.77
- Merged pull requests: 94
- Bot issues: 0
- Bot pull requests: 121
Past Year
- Issues: 0
- Pull requests: 89
- Average time to close issues: N/A
- Average time to close pull requests: 4 days
- Issue authors: 0
- Pull request authors: 1
- Average comments per issue: 0
- Average comments per pull request: 1.78
- Merged pull requests: 65
- Bot issues: 0
- Bot pull requests: 89
Top Authors
Issue Authors
- dependabot[bot] (3)
Pull Request Authors
- dependabot[bot] (185)
- TGWolf (2)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 14 last-month
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 2
- Total maintainers: 1
pypi.org: wolfsoftware.profiles-config
A basic package for managing profile based configuration files.
- Homepage: https://github.com/DevelopersToolbox/profiles-config-package
- Documentation: https://github.com/DevelopersToolbox/profiles-config-package
- License: MIT
-
Latest release: 0.1.1
published over 1 year ago
Rankings
Maintainers (1)
Dependencies
- ActionsToolbox/get-language-versions-action 446919617fd774095b5dd3ed71c39dd3fd0d8f4f composite
- actions/checkout a5ac7e51b41094c92402da3b24376905380afc29 composite
- actions/setup-python 82c7e631bb3cdc910f68e0081d67478d79c6982d composite
- ActionsToolbox/get-language-versions-action 446919617fd774095b5dd3ed71c39dd3fd0d8f4f composite
- actions/checkout a5ac7e51b41094c92402da3b24376905380afc29 composite
- citation-file-format/cffconvert-github-action 4cf11baa70a673bfdf9dad0acc7ee33b3f4b6084 composite
- ruby/setup-ruby 943103cae7d3f1bb1e4951d5fcc7928b40e4b742 composite
- Gamesight/slack-workflow-status 68bf00d0dbdbcb206c278399aa1ef6c14f74347a composite
- actions/checkout a5ac7e51b41094c92402da3b24376905380afc29 composite
- github/codeql-action/analyze a57c67b89589d2d13d5ac85a9fc4679c7539f94c composite
- github/codeql-action/autobuild a57c67b89589d2d13d5ac85a9fc4679c7539f94c composite
- github/codeql-action/init a57c67b89589d2d13d5ac85a9fc4679c7539f94c composite
- Gamesight/slack-workflow-status 68bf00d0dbdbcb206c278399aa1ef6c14f74347a composite
- Mattraks/delete-workflow-runs 39f0bbed25d76b34de5594dceab824811479e5de composite
- dependabot/fetch-metadata 5e5f99653a5b510e8555840e80cbf1514ad4af38 composite
- ActionsToolbox/get-language-versions-action 446919617fd774095b5dd3ed71c39dd3fd0d8f4f composite
- actions/checkout a5ac7e51b41094c92402da3b24376905380afc29 composite
- actions/setup-node 60edb5dd545a775178f52524783378180af0d1f8 composite
- ruby/setup-ruby 943103cae7d3f1bb1e4951d5fcc7928b40e4b742 composite
- ActionsToolbox/get-language-versions-action 446919617fd774095b5dd3ed71c39dd3fd0d8f4f composite
- Bullrich/generate-release-changelog 6b60f004b4bf12ff271603dc32dbd261965ad2f2 composite
- actions/checkout a5ac7e51b41094c92402da3b24376905380afc29 composite
- actions/setup-python 82c7e631bb3cdc910f68e0081d67478d79c6982d composite
- softprops/action-gh-release 69320dbe05506a9a39fc8ae11030b214ec2d1f87 composite
- ActionsToolbox/get-language-versions-action 446919617fd774095b5dd3ed71c39dd3fd0d8f4f composite
- Bullrich/generate-release-changelog 6b60f004b4bf12ff271603dc32dbd261965ad2f2 composite
- actions/checkout a5ac7e51b41094c92402da3b24376905380afc29 composite
- actions/setup-python 82c7e631bb3cdc910f68e0081d67478d79c6982d composite
- softprops/action-gh-release 69320dbe05506a9a39fc8ae11030b214ec2d1f87 composite
- actions/first-interaction 34f15e814fe48ac9312ccf29db4e74fa767cbab7 composite
- Gamesight/slack-workflow-status 68bf00d0dbdbcb206c278399aa1ef6c14f74347a composite
- otto-de/purge-deprecated-workflow-runs 31a4e821d43e9a354cbd65845922c76e4b4b3633 composite
- ActionsToolbox/get-language-versions-action 446919617fd774095b5dd3ed71c39dd3fd0d8f4f composite
- actions/checkout a5ac7e51b41094c92402da3b24376905380afc29 composite
- actions/setup-go cdcb36043654635271a94b9a6d1392de5bb323a7 composite
- actions/setup-python 82c7e631bb3cdc910f68e0081d67478d79c6982d composite
- actions/checkout a5ac7e51b41094c92402da3b24376905380afc29 composite
- zgosalvez/github-actions-ensure-sha-pinned-actions 40e45e738b3cad2729f599d8afc6ed02184e1dbd composite
- Gamesight/slack-workflow-status 68bf00d0dbdbcb206c278399aa1ef6c14f74347a composite
- actions/stale 28ca1036281a5e5922ead5184a1bbf96e5fc984e composite
- pytest ==8.2.1
- setuptools ==70.0.0