From 4c54f474c879501c15e966f137188ad7c6630f9d Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sat, 18 Jan 2020 07:50:56 -0600 Subject: Add travis ci badge --- README.md | 1 + 1 file changed, 1 insertion(+) (limited to 'README.md') diff --git a/README.md b/README.md index 83a5e76..d47292a 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ [![Python 3.8.0|](https://img.shields.io/badge/python-3.8.0-blue.svg)](https://www.python.org/downloads/release/python-380/) [![Version](https://img.shields.io/pypi/v/config-file)](https://pypi.org/project/config-file/) [![Style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://pypi.org/project/black/) +[![Build Status](https://travis-ci.com/eugenetriguba/config_file.svg?branch=master)](https://travis-ci.com/eugenetriguba/config_file) > This python package is currently a work in progress and is in a pre-alpha phase. The API is liable to break until v1. -- cgit v1.2.3 From df7a92116ed5b939593f29ef5097342ddbb5e1e3 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sun, 19 Jan 2020 13:21:59 -0600 Subject: Update README and CHANGELOG with changes --- README.md | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 83a5e76..2d3ae16 100644 --- a/README.md +++ b/README.md @@ -11,14 +11,6 @@ Config File allows you to use the same simple API for manipulating INI, JSON, YAML, and TOML configuration files. For the time being, it only supports INI. -## Motivation - -With applications I was building, I found myself frequently having to use some sort of configuration folder with an object that modeled the configuration file. I did this to help more easily manipulate my configuration. However, I found myself needing this sort of thing for several different applications and would end up rewriting something similar. So ended up deciding to create a package out of it so I could focus more on the application I was building instead. - -## Why not just use configparser, ConfigObj, etc. - -I wanted something a bit cleaner to use than configparser. The ini parser uses configparser under the hood, but it provides some niceties such as automatically parsing configuration values into their native types when you retrieve them. However, I also wanted something more flexible, and ini files aren't the only common configuration format. That is why Config File uses an adapter pattern to swap in and out the right parser for various file types you give it. This allows you to use the same API for all of your configuration needs. - ## Installation ```bash $ pip install config_file @@ -92,4 +84,19 @@ config.has('week') >>> False config.has('calendar.start_week_on_sunday') >>> True + +# The file is only written back out when you call save() +config.save() +>>> True + +# You can also reset the file back to its original state. The current configuration file +# would be deleted and replaced by a copy of the original. By default, since our passed in +# config file was at path `~/.config/test/config.ini`, `reset()` will look for +# `~/.config/test/config.original.ini` +config.reset() +>>> True + +# Or you can specify the file path explicitly +config.reset(original_file_path="~/some_other_directory/this_is_actually_the_original.ini") +>>> True ``` -- cgit v1.2.3 From bbacf0d592bdbcca79b6e1ffd38f7de18f5a4535 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sun, 19 Jan 2020 13:54:06 -0600 Subject: Update dependencies and add codecov badge to master --- README.md | 1 + 1 file changed, 1 insertion(+) (limited to 'README.md') diff --git a/README.md b/README.md index d52fe1d..82ed0a0 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ [![Version](https://img.shields.io/pypi/v/config-file)](https://pypi.org/project/config-file/) [![Style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://pypi.org/project/black/) [![Build Status](https://travis-ci.com/eugenetriguba/config_file.svg?branch=master)](https://travis-ci.com/eugenetriguba/config_file) +[![Codecov](https://codecov.io/gh/eugenetriguba/config_file/branch/master/graph/badge.svg)](https://codecov.io/gh/eugenetriguba/config_file) > This python package is currently a work in progress and is in a pre-alpha phase. The API is liable to break until v1. -- cgit v1.2.3 From 301cc8afc938c5dcd8b52492f113f8f1d893d918 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sun, 19 Jan 2020 14:10:16 -0600 Subject: Clean up examples and fix codecov badge --- README.md | 56 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 19 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 82ed0a0..ff81630 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![Version](https://img.shields.io/pypi/v/config-file)](https://pypi.org/project/config-file/) [![Style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://pypi.org/project/black/) [![Build Status](https://travis-ci.com/eugenetriguba/config_file.svg?branch=master)](https://travis-ci.com/eugenetriguba/config_file) -[![Codecov](https://codecov.io/gh/eugenetriguba/config_file/branch/master/graph/badge.svg)](https://codecov.io/gh/eugenetriguba/config_file) +[![Codecov](https://codecov.io/gh/eugenetriguba/config_file/graph/badge.svg)](https://codecov.io/gh/eugenetriguba/config_file) > This python package is currently a work in progress and is in a pre-alpha phase. The API is liable to break until v1. @@ -18,7 +18,9 @@ YAML, and TOML configuration files. For the time being, it only supports INI. $ pip install config_file ``` -## Examples +## Example + +### Sample Configuration File `config.ini` ```ini @@ -29,17 +31,22 @@ today_index = 0 quarter_hours_passed = 0.25 ``` -`example.py` +### Create a ConfigFile ```python from config_file import ConfigFile config = ConfigFile("~/.config/test/config.ini") +``` -# Output your config file as a string +### Output your config file as a string +```python config.stringify() >>> '[calendar]\ntoday = monday\nstart_week_on_sunday = false\ntoday_index = 0\nquarter_hours_passed = 0.25\n\n' +``` -# Retrieve values with a section.key format +### Retrieve values +A section.key format is used for retrieving and setting values. +```python config.get("calendar.today") >>> 'monday' @@ -47,15 +54,13 @@ config.get("calendar.today") config.get("calendar.start_week_on_sunday") >>> False -# Values from the config file are automatically parsed -config.get("calendar.start_week_on_sunday") ->>> False - # Unless you don't want them to be parsed config.get("calendar.today_index", parse_type=False) >>> '0' +``` -# The dot syntax is also used to set values. True is returned on success. +### Set values +```python config.set("calendar.today_index", 20) >>> True config.stringify() @@ -66,39 +71,52 @@ config.set("week.tuesday_index", 2) >>> True config.stringify() >>> '[calendar]\ntoday = monday\nstart_week_on_sunday = false\ntoday_index = 20\nquarter_hours_passed = 0.25\n\n[week]\ntuesday_index = 2\n\n' +``` -# Delete can delete an entire section or just a key/value pair. +# Delete sections or key/value pairs. +```python config.delete('week') >>> True config.stringify() >>> '[calendar]\ntoday = monday\nstart_week_on_sunday = false\ntoday_index = 20\nquarter_hours_passed = 0.25\n\n' -# Delete can delete an entire section or just a key/value pair. config.delete('calendar.today') >>> True config.stringify() >>> '[calendar]\nstart_week_on_sunday = false\ntoday_index = 20\nquarter_hours_passed = 0.25\n\n' +``` + -# You can also just check if the file has a particular section or key. +### Check whether you have a particular section or key +```python config.has('calendar') >>> True + config.has('week') >>> False + config.has('calendar.start_week_on_sunday') >>> True +``` -# The file is only written back out when you call save() +### Save when you're done +The contents are only written back out when you call `save()`. +```python config.save() >>> True +``` -# You can also reset the file back to its original state. The current configuration file -# would be deleted and replaced by a copy of the original. By default, since our passed in -# config file was at path `~/.config/test/config.ini`, `reset()` will look for -# `~/.config/test/config.original.ini` +### Reset the file back to its original + +The current configuration file would be deleted and replaced by a copy of the original. +By default, since our passed in config file was at path `~/.config/test/config.ini`, `reset()` +will look for `~/.config/test/config.original.ini`. + +```python config.reset() >>> True -# Or you can specify the file path explicitly +# But you can also specify the original config file explicitly. config.reset(original_file_path="~/some_other_directory/this_is_actually_the_original.ini") >>> True ``` -- cgit v1.2.3 From e51ec35bd4a52323a20a728e25613643bc79d4be Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sun, 19 Jan 2020 14:11:22 -0600 Subject: Fix example heading that is too large --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'README.md') diff --git a/README.md b/README.md index ff81630..de1fa99 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ config.stringify() >>> '[calendar]\ntoday = monday\nstart_week_on_sunday = false\ntoday_index = 20\nquarter_hours_passed = 0.25\n\n[week]\ntuesday_index = 2\n\n' ``` -# Delete sections or key/value pairs. +### Delete sections or key/value pairs. ```python config.delete('week') >>> True -- cgit v1.2.3 From d91a146198ea2f5e2ca0cfa45948913e878ff315 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sun, 19 Jan 2020 14:21:30 -0600 Subject: Add section on using your own parser Also, a sentence is added on what is exposed to the public API. --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'README.md') diff --git a/README.md b/README.md index de1fa99..bb76e0f 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,8 @@ $ pip install config_file ## Example +The `config_file` package exposes `ConfigFile`, `ParsingError`, and `BaseParser` to the public API. + ### Sample Configuration File `config.ini` @@ -120,3 +122,9 @@ config.reset() config.reset(original_file_path="~/some_other_directory/this_is_actually_the_original.ini") >>> True ``` + +## Using your own parser + +> This feature is a work in-progress and has not been tested yet. + +You can still use config file, even if you don't use one of our supported configuration formats. The `ConfigFile` object swaps in the parser it needs based on the file format. However, the constructor takes in an optional `parser` argument that you can use to supply your own custom parser. The only requirement is that the parser must be a concrete implementation of `BaseParser`. -- cgit v1.2.3 From 9c8c6c1fc2ccf31bc8c709ab052c34a45e207b36 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sun, 19 Jan 2020 14:40:13 -0600 Subject: Add support for retrieving entire sections with get() --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index bb76e0f..708ad83 100644 --- a/README.md +++ b/README.md @@ -46,19 +46,19 @@ config.stringify() >>> '[calendar]\ntoday = monday\nstart_week_on_sunday = false\ntoday_index = 0\nquarter_hours_passed = 0.25\n\n' ``` -### Retrieve values +### Retrieve values or sections A section.key format is used for retrieving and setting values. ```python -config.get("calendar.today") ->>> 'monday' - # Values from the config file are automatically parsed config.get("calendar.start_week_on_sunday") >>> False # Unless you don't want them to be parsed -config.get("calendar.today_index", parse_type=False) ->>> '0' +config.get("calendar.start_week_on_sunday", parse_type=False) +>>> 'false' + +config.get("calendar") +>>> {'today': 'monday', 'start_week_on_sunday': False, 'today_index': 0, 'quarter_hours_passed': 0.25} ``` ### Set values -- cgit v1.2.3