From 7254f3053dc9a4e11988629159d39b832c3c92de Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sat, 18 Jan 2020 07:35:29 -0600 Subject: Add travis CI + tox --- .travis.yml | 25 +++++++++++++++++++++++++ tox.ini | 9 +++++++++ 2 files changed, 34 insertions(+) create mode 100644 .travis.yml create mode 100644 tox.ini diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..8c6609b --- /dev/null +++ b/.travis.yml @@ -0,0 +1,25 @@ +language: python +matrix: + include: + - python: 3.3 + env: + TOXENV: py33 + - python: 3.4 + env: + TOXENV: py34 + - python: 3.5 + env: + TOXENV: py35 + - python: 3.6 + env: + TOXENV: py36 + - python: 3.7 + env: + TOXENV: py37 + - python: 3.8 + env: + TOXENV: py38 + +install: pip install --upgrade pip tox + +script: tox \ No newline at end of file diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..abf7fb4 --- /dev/null +++ b/tox.ini @@ -0,0 +1,9 @@ +[tox] +isolated_build = true +envlist = py33, py34, py35, py36, py37, py38 + +[testenv] +whitelist_externals = poetry +commands = + poetry install -v + poetry run pytest --cov=config_file/ tests/ \ No newline at end of file -- cgit v1.2.3 From fbb0bc401c54086944057e2fca181646e78ca63d Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sat, 18 Jan 2020 07:43:14 -0600 Subject: Remove other py version tests on ci, add lint + test stages --- .travis.yml | 31 +++++++++++++++---------------- tox.ini | 2 +- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8c6609b..b96bf9d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,25 +1,24 @@ language: python + +stages: + - lint + - test + +jobs: + include: + - stage: lint + install: + - pip install pre-commit + - pre-commit install-hooks + script: + - pre-commit run --all-files + matrix: include: - - python: 3.3 - env: - TOXENV: py33 - - python: 3.4 - env: - TOXENV: py34 - - python: 3.5 - env: - TOXENV: py35 - - python: 3.6 - env: - TOXENV: py36 - - python: 3.7 - env: - TOXENV: py37 - python: 3.8 env: TOXENV: py38 -install: pip install --upgrade pip tox +install: pip install --upgrade pip tox poetry script: tox \ No newline at end of file diff --git a/tox.ini b/tox.ini index abf7fb4..d86b26b 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] isolated_build = true -envlist = py33, py34, py35, py36, py37, py38 +envlist = py38 [testenv] whitelist_externals = poetry -- cgit v1.2.3 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(+) 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 7122db9a63bc4954ad6ccc63b3b9af7b98e984b8 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sun, 19 Jan 2020 10:22:50 -0600 Subject: Only use matrix and change to include lint + test stages --- .travis.yml | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index b96bf9d..a1e0cad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ stages: - lint - test -jobs: +matrix: include: - stage: lint install: @@ -12,13 +12,9 @@ jobs: - pre-commit install-hooks script: - pre-commit run --all-files - -matrix: - include: - - python: 3.8 + - stage: test + python: 3.8 + install: pip install --upgrade pip tox poetry + script: tox env: - TOXENV: py38 - -install: pip install --upgrade pip tox poetry - -script: tox \ No newline at end of file + TOXENV: py38 \ No newline at end of file -- cgit v1.2.3 From 869f6ffd0614337d688e5aafa3ebc2220dacb1c1 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sun, 19 Jan 2020 13:04:43 -0600 Subject: Add CI pipeline details to contributing guidelines --- CONTRIBUTING.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9a0dcc0..e5c2b0c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -49,9 +49,12 @@ Here are some guidelines to keep in mind when submitting a pull request: ```bash pre-commit install ``` - - If the pipeline is acting oddly, you can skip it with the ``--no-verify`` option - to ``git push``. + +- CI Pipeline: There is a CI pipeline that is run by Travis CI on commits to master and + on pull requests. + + - All it does is ensure that all the tests pass and that all the files adhere to the + standard format (`pre-commit run --all-files`). To get started, make sure you have poetry installed and run ``poetry install`` and ``poetry shell`` to enter the virtual environment. \ No newline at end of file -- cgit v1.2.3 From 699c0e66d138fb70ac50e03a012522480ed8d1f0 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sun, 19 Jan 2020 13:05:52 -0600 Subject: Add TODO to ini_parser to be able to retrieve sections --- config_file/parsers/ini_parser.py | 1 + 1 file changed, 1 insertion(+) diff --git a/config_file/parsers/ini_parser.py b/config_file/parsers/ini_parser.py index 3c8f12f..3e93e4c 100644 --- a/config_file/parsers/ini_parser.py +++ b/config_file/parsers/ini_parser.py @@ -33,6 +33,7 @@ class IniParser(BaseParser): :raises ParsingError: if the specified `section.key` is not found, in an invalid format, or if we are unable to coerce the return value to value_type. """ + # TODO: Support for retrieving entire sections instead of just key/values section, key = split_on_dot(section_key, only_last_dot=True) try: -- cgit v1.2.3 From 2117c36ab0953f69945275e9bc5bfece4c14a26b Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sun, 19 Jan 2020 13:20:57 -0600 Subject: Add save() and reset() methods to ConfigFile Test coverage on other files has also been increased --- config_file/config_file.py | 90 ++++++++++++++++++++++++++++++++++++++++------ config_file/utils.py | 5 +++ tests/test_config_file.py | 63 ++++++++++++++++++++++++++++++++ tests/test_ini_parser.py | 15 ++++++-- tests/test_parse_value.py | 11 +++++- tests/test_utils.py | 19 ++++++++++ 6 files changed, 188 insertions(+), 15 deletions(-) create mode 100644 tests/test_config_file.py create mode 100644 tests/test_utils.py diff --git a/config_file/config_file.py b/config_file/config_file.py index 5a2dbb5..b090ace 100644 --- a/config_file/config_file.py +++ b/config_file/config_file.py @@ -1,5 +1,6 @@ import inspect -from pathlib import Path +from pathlib import Path, PurePath +from shutil import copyfile from config_file.parsers.base_parser import BaseParser from config_file.parsers.ini_parser import IniParser @@ -7,26 +8,49 @@ from config_file.utils import split_on_dot class ConfigFile: - def __init__(self, file_path: str, parser=None): - self.path = self.__create_config_path(file_path) + def __init__(self, file_path, parser=None): + """ + Saves the config file path and expands it if needed, reads in + the file contents, and determines what parser should be used for + the given file. - with open(self.path, "r") as file: - self.contents = file.read() + :param file_path: The path to your configuration file. + :param parser: A custom parser you'd like used for your config file. + It must be a concrete implementation of BaseParser. + :raises ValueError: If the specified file path does not have an extension + that is supported or it is a directory. + """ + self.path = self.__create_config_path(file_path) + self.contents = self.__read_config_file() self.parser = self.__determine_parser(file_path, parser) @staticmethod - def __create_config_path(file_path: str): + def __create_config_path(file_path, original=False) -> str: + if isinstance(file_path, PurePath): + file_path = str(file_path) + if len(file_path) > 1 and file_path[0] == "~": - return Path(file_path).expanduser().resolve() + return str(Path(file_path).expanduser()) + + if original: + file_parts = split_on_dot(file_path, only_last_dot=True) + file_parts.insert(-1, "original") + file_path = ".".join(file_parts) - return Path(file_path) + if Path(file_path).is_dir(): + raise ValueError(f"The specified config file ({file_path}) is a directory.") + + return file_path + + def __determine_parser(self, file_path, parser): + if isinstance(file_path, PurePath): + file_path = str(file_path) - def __determine_parser(self, file_path: str, parser): if isinstance(parser, BaseParser) and not inspect.isabstract(parser): return parser(self.contents) - file_type = split_on_dot(file_path)[-1] + file_type = split_on_dot(file_path, only_last_dot=True)[-1] if file_type == "ini": return IniParser(self.contents) else: @@ -35,6 +59,10 @@ class ConfigFile: f"unrecognized file type: {file_path}" ) + def __read_config_file(self): + with open(self.path, "r") as file: + return file.read() + def get(self, key, parse_type=True): """ Retrieve the value of a key in its native type. @@ -64,6 +92,46 @@ class ConfigFile: using a section.key format. Some formats, like JSON, do not have sections and therefore, - it would only be checking if the section + it would only be checking if the key exists. """ return self.parser.has(section_key) + + def reset(self, original_file_path=None): + """ + Resets the config file by deleting it and copying the original back + in its place. The contents of this config file are then set to the + newly reset config file. + + :param original_file_path: The path to the original config file to reset it to. + If this is not provided and, say, your configuration file is config.json, the + method would look for a config.original.json in the same folder by default. + + :return: True if the reset succeeded + :raises OSError: If the original configuration file is not present or if an + error occurred when trying to copy the file. + """ + if original_file_path is None: + original_file_path = self.__create_config_path( + str(self.path), original=True + ) + + if not Path(original_file_path).exists(): + raise OSError(f"The {original_file_path} file to reset to does not exist.") + + Path(self.path).expanduser().unlink(missing_ok=True) + copyfile(original_file_path, self.path) + + self.contents = self.__read_config_file() + self.parser.parsed_content = self.parser.parse(self.contents) + + return True + + def save(self): + """ + Save the configuration changes by writing the file out to the specified path + :return: True if the save succeeded. + """ + with open(self.path, "w") as config_file: + config_file.write(self.parser.stringify()) + + return True diff --git a/config_file/utils.py b/config_file/utils.py index 41ce2a5..61f0ae0 100644 --- a/config_file/utils.py +++ b/config_file/utils.py @@ -8,6 +8,11 @@ def split_on_dot(line: str, only_last_dot=False): :raises ValueError: if the line does not have a dot. """ if "." not in line: + # TODO: This is used in the parser for section.keys where a more specific + # error message would be nice, but it is only used more generically to, say, + # split a file path. We may just have to insert some try-catches to catch the + # ValueError and insert a more specific error message or create a custom error + # for this method? raise ValueError( "section_key must contain the section and key separated by a dot. " + "e.g. 'section.key'" diff --git a/tests/test_config_file.py b/tests/test_config_file.py new file mode 100644 index 0000000..1daba6f --- /dev/null +++ b/tests/test_config_file.py @@ -0,0 +1,63 @@ +from pathlib import Path + +import pytest + +from config_file.config_file import BaseParser, ConfigFile + + +@pytest.mark.parametrize( + "file_contents, file_name", [("[calendar]\nsunday_index = 0\n\n", "config.ini")] +) +def test_that_config_file_initializes_correctly(tmp_path, file_contents, file_name): + temp = tmp_path / file_name + temp.write_text(file_contents) + + config = ConfigFile(temp) + assert config.path == str(temp) + assert config.contents == temp.read_text() + assert isinstance(config.parser, BaseParser) + + +@pytest.mark.parametrize( + "file_contents, file_name, original_file_name", + [("[calendar]\nsunday_index = 0\n\n", "config.ini", "config.original.ini")], +) +def test_that_config_file_can_reset( + tmpdir, file_contents, file_name, original_file_name +): + config_path = tmpdir / file_name + config_path.write_text(file_contents, encoding="utf-8") + + original_config_path = tmpdir / original_file_name + original_config_path.write_text(file_contents, encoding="utf-8") + + config = ConfigFile(str(config_path)) + config.set("calendar.sunday_index", 0) + config.reset() + assert config.stringify() == ConfigFile(str(original_config_path)).stringify() + assert config_path.read_text(encoding="utf-8") == original_config_path.read_text( + encoding="utf-8" + ) + + +@pytest.mark.parametrize( + "file_contents, file_name", [("[calendar]\nsunday_index = 0\n\n", "config.ini")] +) +def test_that_config_file_can_save(tmpdir, file_contents, file_name): + config_path = tmpdir / file_name + config_path.write_text(file_contents, encoding="utf-8") + + config = ConfigFile(str(config_path)) + config.set("calendar.sunday_index", 1) + config.save() + assert config.stringify() == Path(config_path).read_text(encoding="utf-8") + + +@pytest.mark.parametrize( + "path, is_dir", [("invalid", False), ("invalid", True), ("invalid.conf", False)] +) +def test_invalid_config_paths(tmpdir, path, is_dir): + with pytest.raises(ValueError): + temp_path = tmpdir / path + temp_path.write("") + ConfigFile(str(tmpdir)) if is_dir else ConfigFile(str(temp_path)) diff --git a/tests/test_ini_parser.py b/tests/test_ini_parser.py index 5c26b23..da1b43e 100644 --- a/tests/test_ini_parser.py +++ b/tests/test_ini_parser.py @@ -34,18 +34,27 @@ floatkey = 5.3 assert parser.get(section_key, parse_type=parse_type) == expected_value +@pytest.mark.parametrize( + "test_input", ["invalid.invalid_key"], +) +def test_that_getting_unknown_sections_or_keys_throws_errors(test_input): + with pytest.raises(ParsingError): + IniParser("").get(test_input) + + @pytest.mark.parametrize( "section_key,value,expected_value", [ ("test.key1", "different value", "[test]\nkey1 = different value\n\n"), - ("test.key2", 5, "[test]\nkey1 = different value\nkey2 = 5\n\n"), - ("test2.key", False, "[test]\nkey1 = value1\n[test2]\nkey = False\n\n"), + ("test.key2", 5, "[test]\nkey1 = value1\nkey2 = 5\n\n"), + ("test2.key", False, "[test]\nkey1 = value1\n\n[test2]\nkey = False\n\n"), ], ) def test_that_ini_parser_can_set_values(section_key, value, expected_value): ini_file = """[test]\nkey1 = value1\n\n""" parser = IniParser(ini_file) - assert parser.stringify() == ini_file + parser.set(section_key, value) + assert parser.stringify() == expected_value @pytest.mark.parametrize( diff --git a/tests/test_parse_value.py b/tests/test_parse_value.py index 54e056b..2123337 100644 --- a/tests/test_parse_value.py +++ b/tests/test_parse_value.py @@ -1,6 +1,6 @@ import pytest -from config_file.parsers.parse_value import parse_value +from config_file.parsers.parse_value import can_be_parsed_as_bool, parse_value @pytest.mark.parametrize( @@ -21,3 +21,12 @@ from config_file.parsers.parse_value import parse_value ) def test_parse_value(test_input, expected): assert parse_value(test_input) == expected + + +def test_can_be_parsed_as_bool(): + """ + This is the section not being covered in the parse_value.py + file from test_parse_value, but I don't think it's reachable + from using it. + """ + assert can_be_parsed_as_bool(5) is False diff --git a/tests/test_utils.py b/tests/test_utils.py new file mode 100644 index 0000000..6779d18 --- /dev/null +++ b/tests/test_utils.py @@ -0,0 +1,19 @@ +import pytest + +from config_file.utils import split_on_dot + + +@pytest.mark.parametrize( + "test_input, only_last_dot, expected_result", + [("section.key.blah", False, ["section", "key", "blah"])], +) +def test_that_split_on_dot_splits_the_line_correctly( + test_input, only_last_dot, expected_result +): + assert split_on_dot(test_input, only_last_dot=only_last_dot) == expected_result + + +@pytest.mark.parametrize("test_input", ["this line has no dots in it"]) +def test_that_split_on_dot_raises_error_when_there_is_no_dot(test_input): + with pytest.raises(ValueError): + split_on_dot(test_input) -- 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 --- CHANGELOG.md | 13 +++++++++++++ README.md | 23 +++++++++++++++-------- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e699e5..5898f60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + + - Change Travis CI to lint all files as well as run the tests. + - Add `reset()` and `save()` methods to `ConfigFile`. This allows you to reset your + configuration file to an "original state," given the original config file path. + However, say you have a `config/config.json` file. Then it will automatically try + to look for `config/config.original.json` if no file path is specified. The `save()` + method should be called after your changes to the config file. It will write them + back out. + - Raise test coverage to 93% (`BaseParser` is abstract so it isn't tested and some + methods in `ConfigFile` simply use the same method in the parser so it doesn't make + sense to test those methods.) + ## 0.3.3 Fixed 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 fdeaa95bbfd78c7760921bde21a9bc3fcd066d61 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sun, 19 Jan 2020 13:25:54 -0600 Subject: Change ci to use `pre-commit install` instead of install-hooks --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a1e0cad..22d1d7f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ matrix: - stage: lint install: - pip install pre-commit - - pre-commit install-hooks + - pre-commit install script: - pre-commit run --all-files - stage: test -- cgit v1.2.3 From 1c25a44e87d2a6bf982f3764f026a883292a92e5 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sun, 19 Jan 2020 13:29:07 -0600 Subject: Remove lint phase from ci for now --- .travis.yml | 7 ------- CONTRIBUTING.md | 3 +-- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 22d1d7f..f535f0c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,17 +1,10 @@ language: python stages: - - lint - test matrix: include: - - stage: lint - install: - - pip install pre-commit - - pre-commit install - script: - - pre-commit run --all-files - stage: test python: 3.8 install: pip install --upgrade pip tox poetry diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e5c2b0c..6b307cc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -53,8 +53,7 @@ Here are some guidelines to keep in mind when submitting a pull request: - CI Pipeline: There is a CI pipeline that is run by Travis CI on commits to master and on pull requests. - - All it does is ensure that all the tests pass and that all the files adhere to the - standard format (`pre-commit run --all-files`). + - All it does is ensure that all the tests pass. To get started, make sure you have poetry installed and run ``poetry install`` and ``poetry shell`` to enter the virtual environment. \ No newline at end of file -- cgit v1.2.3 From 07347c74dd16a80fa206ec184c3fa8401a07cf94 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sun, 19 Jan 2020 13:38:54 -0600 Subject: Remove linting from changelog since it was removed --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5898f60..abd6826 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased - - Change Travis CI to lint all files as well as run the tests. - Add `reset()` and `save()` methods to `ConfigFile`. This allows you to reset your configuration file to an "original state," given the original config file path. However, say you have a `config/config.json` file. Then it will automatically try -- cgit v1.2.3 From c19f8f711ac99fe578c22eec47374dfbc2f734dd Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sun, 19 Jan 2020 13:39:13 -0600 Subject: =?UTF-8?q?Bump=20version:=200.3.3=20=E2=86=92=200.4.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .bumpversion.cfg | 2 +- CHANGELOG.md | 2 +- config_file/__init__.py | 2 +- pyproject.toml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 550acf7..19bb5c6 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.3.3 +current_version = 0.4.0 commit = True tag = True diff --git a/CHANGELOG.md b/CHANGELOG.md index abd6826..5306057 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## Unreleased +## 0.4.0 - 2020-01-19 - Add `reset()` and `save()` methods to `ConfigFile`. This allows you to reset your configuration file to an "original state," given the original config file path. diff --git a/config_file/__init__.py b/config_file/__init__.py index c71562f..ce02903 100644 --- a/config_file/__init__.py +++ b/config_file/__init__.py @@ -1,7 +1,7 @@ from config_file.config_file import ConfigFile from config_file.parsers.base_parser import BaseParser, ParsingError -__version__ = "0.3.3" +__version__ = "0.4.0" __all__ = [ "ConfigFile", diff --git a/pyproject.toml b/pyproject.toml index 0e5b82c..7dd90a8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "config_file" -version = "0.3.3" +version = "0.4.0" description = "Manage your configuration files." authors = ["Eugene Triguba "] readme = "README.md" -- cgit v1.2.3 From 149eb0e4d90aad1a252aff58cefc356f018e33a3 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sun, 19 Jan 2020 13:49:16 -0600 Subject: Test configuration for using codecov --- .coveragerc | 2 ++ .travis.yml | 6 ++++-- tox.ini | 5 ++++- 3 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 .coveragerc diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..e272605 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,2 @@ +[run] +source=config_file \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index f535f0c..3fb5db1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,9 @@ matrix: include: - stage: test python: 3.8 - install: pip install --upgrade pip tox poetry + install: pip install --upgrade pip tox poetry codecov script: tox env: - TOXENV: py38 \ No newline at end of file + TOXENV: py38 + after_success: + - codecov \ No newline at end of file diff --git a/tox.ini b/tox.ini index d86b26b..d94f733 100644 --- a/tox.ini +++ b/tox.ini @@ -3,7 +3,10 @@ isolated_build = true envlist = py38 [testenv] +passenv = CI TRAVIS TRAVIS_* +deps = codecov whitelist_externals = poetry commands = poetry install -v - poetry run pytest --cov=config_file/ tests/ \ No newline at end of file + poetry run pytest --cov=config_file/ tests/ + codecov \ No newline at end of file -- 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 + poetry.lock | 138 +++++++++++++++++++++++++++--------------------------------- 2 files changed, 64 insertions(+), 75 deletions(-) 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. diff --git a/poetry.lock b/poetry.lock index 12b2266..64dd310 100644 --- a/poetry.lock +++ b/poetry.lock @@ -128,7 +128,7 @@ description = "Code coverage measurement for Python" name = "coverage" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <4" -version = "5.0.1" +version = "5.0.3" [package.extras] toml = ["toml"] @@ -169,7 +169,7 @@ description = "File identification library for Python" name = "identify" optional = false python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7" -version = "1.4.9" +version = "1.4.10" [package.extras] license = ["editdistance"] @@ -202,7 +202,7 @@ description = "More routines for operating on iterables, beyond itertools" name = "more-itertools" optional = false python-versions = ">=3.5" -version = "8.0.2" +version = "8.1.0" [[package]] category = "dev" @@ -210,7 +210,7 @@ description = "Node.js virtual environment builder" name = "nodeenv" optional = false python-versions = "*" -version = "1.3.3" +version = "1.3.4" [[package]] category = "dev" @@ -293,11 +293,11 @@ six = ">=1.10.0" [[package]] category = "dev" -description = "A ``py.test`` fixture for benchmarking code. It will group the tests into rounds that are calibrated to the chosen timer. See calibration_ and FAQ_." +description = "A ``pytest`` fixture for benchmarking code. It will group the tests into rounds that are calibrated to the chosen timer. See calibration_ and FAQ_." name = "pytest-benchmark" optional = false -python-versions = "*" -version = "3.2.2" +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" +version = "3.2.3" [package.dependencies] py-cpuinfo = "*" @@ -339,21 +339,13 @@ six = "*" [package.extras] tests = ["pytest-virtualenv"] -[[package]] -category = "main" -description = "File type identification using libmagic" -name = "python-magic" -optional = false -python-versions = "*" -version = "0.4.15" - [[package]] category = "main" description = "YAML parser and emitter for Python" name = "pyyaml" optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" -version = "5.2" +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" +version = "5.3" [[package]] category = "dev" @@ -371,8 +363,8 @@ category = "dev" description = "Python 2 and 3 compatibility utilities" name = "six" optional = false -python-versions = ">=2.6, !=3.0.*, !=3.1.*" -version = "1.13.0" +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*" +version = "1.14.0" [[package]] category = "main" @@ -395,7 +387,7 @@ docs = ["sphinx (>=1.8.0,<2)", "towncrier (>=18.5.0)", "sphinx-rtd-theme (>=0.4. testing = ["pytest (>=4.0.0,<5)", "coverage (>=4.5.0,<5)", "pytest-timeout (>=1.3.0,<2)", "six (>=1.10.0,<2)", "pytest-xdist", "pytest-localserver", "pypiserver", "mock", "xonsh"] [metadata] -content-hash = "a3687fe4afb7e547c0bbc19d3ab240dd4afb6927760e63649fccfd97e0991cab" +content-hash = "ddf19a9d0619bc0bf76ebb1425acbcab5058f59f1f29f36e1f24748006db6ed3" python-versions = "^3.8" [metadata.files] @@ -447,37 +439,37 @@ colorama = [ {file = "colorama-0.4.3.tar.gz", hash = "sha256:e96da0d330793e2cb9485e9ddfd918d456036c7149416295932478192f4436a1"}, ] coverage = [ - {file = "coverage-5.0.1-cp27-cp27m-macosx_10_12_x86_64.whl", hash = "sha256:c90bda74e16bcd03861b09b1d37c0a4158feda5d5a036bb2d6e58de6ff65793e"}, - {file = "coverage-5.0.1-cp27-cp27m-macosx_10_13_intel.whl", hash = "sha256:bb3d29df5d07d5399d58a394d0ef50adf303ab4fbf66dfd25b9ef258effcb692"}, - {file = "coverage-5.0.1-cp27-cp27m-manylinux1_i686.whl", hash = "sha256:1ca43dbd739c0fc30b0a3637a003a0d2c7edc1dd618359d58cc1e211742f8bd1"}, - {file = "coverage-5.0.1-cp27-cp27m-manylinux1_x86_64.whl", hash = "sha256:591506e088901bdc25620c37aec885e82cc896528f28c57e113751e3471fc314"}, - {file = "coverage-5.0.1-cp27-cp27m-win32.whl", hash = "sha256:a50b0888d8a021a3342d36a6086501e30de7d840ab68fca44913e97d14487dc1"}, - {file = "coverage-5.0.1-cp27-cp27m-win_amd64.whl", hash = "sha256:c792d3707a86c01c02607ae74364854220fb3e82735f631cd0a345dea6b4cee5"}, - {file = "coverage-5.0.1-cp27-cp27mu-manylinux1_i686.whl", hash = "sha256:f425f50a6dd807cb9043d15a4fcfba3b5874a54d9587ccbb748899f70dc18c47"}, - {file = "coverage-5.0.1-cp27-cp27mu-manylinux1_x86_64.whl", hash = "sha256:25b8f60b5c7da71e64c18888f3067d5b6f1334b9681876b2fb41eea26de881ae"}, - {file = "coverage-5.0.1-cp35-cp35m-macosx_10_12_x86_64.whl", hash = "sha256:7362a7f829feda10c7265b553455de596b83d1623b3d436b6d3c51c688c57bf6"}, - {file = "coverage-5.0.1-cp35-cp35m-manylinux1_i686.whl", hash = "sha256:fcd4459fe35a400b8f416bc57906862693c9f88b66dc925e7f2a933e77f6b18b"}, - {file = "coverage-5.0.1-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:40fbfd6b044c9db13aeec1daf5887d322c710d811f944011757526ef6e323fd9"}, - {file = "coverage-5.0.1-cp35-cp35m-win32.whl", hash = "sha256:7f2675750c50151f806070ec11258edf4c328340916c53bac0adbc465abd6b1e"}, - {file = "coverage-5.0.1-cp35-cp35m-win_amd64.whl", hash = "sha256:24bcfa86fd9ce86b73a8368383c39d919c497a06eebb888b6f0c12f13e920b1a"}, - {file = "coverage-5.0.1-cp36-cp36m-macosx_10_13_x86_64.whl", hash = "sha256:eeafb646f374988c22c8e6da5ab9fb81367ecfe81c70c292623373d2a021b1a1"}, - {file = "coverage-5.0.1-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:2ca2cd5264e84b2cafc73f0045437f70c6378c0d7dbcddc9ee3fe192c1e29e5d"}, - {file = "coverage-5.0.1-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:2cc707fc9aad2592fc686d63ef72dc0031fc98b6fb921d2f5395d9ab84fbc3ef"}, - {file = "coverage-5.0.1-cp36-cp36m-win32.whl", hash = "sha256:04b961862334687549eb91cd5178a6fbe977ad365bddc7c60f2227f2f9880cf4"}, - {file = "coverage-5.0.1-cp36-cp36m-win_amd64.whl", hash = "sha256:232f0b52a5b978288f0bbc282a6c03fe48cd19a04202df44309919c142b3bb9c"}, - {file = "coverage-5.0.1-cp37-cp37m-macosx_10_13_x86_64.whl", hash = "sha256:cfce79ce41cc1a1dc7fc85bb41eeeb32d34a4cf39a645c717c0550287e30ff06"}, - {file = "coverage-5.0.1-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:46c9c6a1d1190c0b75ec7c0f339088309952b82ae8d67a79ff1319eb4e749b96"}, - {file = "coverage-5.0.1-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:1cbb88b34187bdb841f2599770b7e6ff8e259dc3bb64fc7893acf44998acf5f8"}, - {file = "coverage-5.0.1-cp37-cp37m-win32.whl", hash = "sha256:ff3936dd5feaefb4f91c8c1f50a06c588b5dc69fba4f7d9c79a6617ad80bb7df"}, - {file = "coverage-5.0.1-cp37-cp37m-win_amd64.whl", hash = "sha256:65bead1ac8c8930cf92a1ccaedcce19a57298547d5d1db5c9d4d068a0675c38b"}, - {file = "coverage-5.0.1-cp38-cp38-macosx_10_13_x86_64.whl", hash = "sha256:348630edea485f4228233c2f310a598abf8afa5f8c716c02a9698089687b6085"}, - {file = "coverage-5.0.1-cp38-cp38-manylinux1_i686.whl", hash = "sha256:960d7f42277391e8b1c0b0ae427a214e1b31a1278de6b73f8807b20c2e913bba"}, - {file = "coverage-5.0.1-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:0101888bd1592a20ccadae081ba10e8b204d20235d18d05c6f7d5e904a38fc10"}, - {file = "coverage-5.0.1-cp38-cp38m-win32.whl", hash = "sha256:c0fff2733f7c2950f58a4fd09b5db257b00c6fec57bf3f68c5bae004d804b407"}, - {file = "coverage-5.0.1-cp38-cp38m-win_amd64.whl", hash = "sha256:5f622f19abda4e934938e24f1d67599249abc201844933a6f01aaa8663094489"}, - {file = "coverage-5.0.1-cp39-cp39m-win32.whl", hash = "sha256:2714160a63da18aed9340c70ed514973971ee7e665e6b336917ff4cca81a25b1"}, - {file = "coverage-5.0.1-cp39-cp39m-win_amd64.whl", hash = "sha256:b7dbc5e8c39ea3ad3db22715f1b5401cd698a621218680c6daf42c2f9d36e205"}, - {file = "coverage-5.0.1.tar.gz", hash = "sha256:5ac71bba1e07eab403b082c4428f868c1c9e26a21041436b4905c4c3d4e49b08"}, + {file = "coverage-5.0.3-cp27-cp27m-macosx_10_12_x86_64.whl", hash = "sha256:cc1109f54a14d940b8512ee9f1c3975c181bbb200306c6d8b87d93376538782f"}, + {file = "coverage-5.0.3-cp27-cp27m-macosx_10_13_intel.whl", hash = "sha256:be18f4ae5a9e46edae3f329de2191747966a34a3d93046dbdf897319923923bc"}, + {file = "coverage-5.0.3-cp27-cp27m-manylinux1_i686.whl", hash = "sha256:3230d1003eec018ad4a472d254991e34241e0bbd513e97a29727c7c2f637bd2a"}, + {file = "coverage-5.0.3-cp27-cp27m-manylinux1_x86_64.whl", hash = "sha256:e69215621707119c6baf99bda014a45b999d37602cb7043d943c76a59b05bf52"}, + {file = "coverage-5.0.3-cp27-cp27m-win32.whl", hash = "sha256:1daa3eceed220f9fdb80d5ff950dd95112cd27f70d004c7918ca6dfc6c47054c"}, + {file = "coverage-5.0.3-cp27-cp27m-win_amd64.whl", hash = "sha256:51bc7710b13a2ae0c726f69756cf7ffd4362f4ac36546e243136187cfcc8aa73"}, + {file = "coverage-5.0.3-cp27-cp27mu-manylinux1_i686.whl", hash = "sha256:9bea19ac2f08672636350f203db89382121c9c2ade85d945953ef3c8cf9d2a68"}, + {file = "coverage-5.0.3-cp27-cp27mu-manylinux1_x86_64.whl", hash = "sha256:5012d3b8d5a500834783689a5d2292fe06ec75dc86ee1ccdad04b6f5bf231691"}, + {file = "coverage-5.0.3-cp35-cp35m-macosx_10_12_x86_64.whl", hash = "sha256:d513cc3db248e566e07a0da99c230aca3556d9b09ed02f420664e2da97eac301"}, + {file = "coverage-5.0.3-cp35-cp35m-manylinux1_i686.whl", hash = "sha256:3dbb72eaeea5763676a1a1efd9b427a048c97c39ed92e13336e726117d0b72bf"}, + {file = "coverage-5.0.3-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:15cf13a6896048d6d947bf7d222f36e4809ab926894beb748fc9caa14605d9c3"}, + {file = "coverage-5.0.3-cp35-cp35m-win32.whl", hash = "sha256:fca1669d464f0c9831fd10be2eef6b86f5ebd76c724d1e0706ebdff86bb4adf0"}, + {file = "coverage-5.0.3-cp35-cp35m-win_amd64.whl", hash = "sha256:1e44a022500d944d42f94df76727ba3fc0a5c0b672c358b61067abb88caee7a0"}, + {file = "coverage-5.0.3-cp36-cp36m-macosx_10_13_x86_64.whl", hash = "sha256:b26aaf69713e5674efbde4d728fb7124e429c9466aeaf5f4a7e9e699b12c9fe2"}, + {file = "coverage-5.0.3-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:722e4557c8039aad9592c6a4213db75da08c2cd9945320220634f637251c3894"}, + {file = "coverage-5.0.3-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:7afad9835e7a651d3551eab18cbc0fdb888f0a6136169fbef0662d9cdc9987cf"}, + {file = "coverage-5.0.3-cp36-cp36m-win32.whl", hash = "sha256:25dbf1110d70bab68a74b4b9d74f30e99b177cde3388e07cc7272f2168bd1477"}, + {file = "coverage-5.0.3-cp36-cp36m-win_amd64.whl", hash = "sha256:c312e57847db2526bc92b9bfa78266bfbaabac3fdcd751df4d062cd4c23e46dc"}, + {file = "coverage-5.0.3-cp37-cp37m-macosx_10_13_x86_64.whl", hash = "sha256:a8b8ac7876bc3598e43e2603f772d2353d9931709345ad6c1149009fd1bc81b8"}, + {file = "coverage-5.0.3-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:527b4f316e6bf7755082a783726da20671a0cc388b786a64417780b90565b987"}, + {file = "coverage-5.0.3-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:d649dc0bcace6fcdb446ae02b98798a856593b19b637c1b9af8edadf2b150bea"}, + {file = "coverage-5.0.3-cp37-cp37m-win32.whl", hash = "sha256:cd60f507c125ac0ad83f05803063bed27e50fa903b9c2cfee3f8a6867ca600fc"}, + {file = "coverage-5.0.3-cp37-cp37m-win_amd64.whl", hash = "sha256:c60097190fe9dc2b329a0eb03393e2e0829156a589bd732e70794c0dd804258e"}, + {file = "coverage-5.0.3-cp38-cp38-macosx_10_13_x86_64.whl", hash = "sha256:d7008a6796095a79544f4da1ee49418901961c97ca9e9d44904205ff7d6aa8cb"}, + {file = "coverage-5.0.3-cp38-cp38-manylinux1_i686.whl", hash = "sha256:ea9525e0fef2de9208250d6c5aeeee0138921057cd67fcef90fbed49c4d62d37"}, + {file = "coverage-5.0.3-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:c62a2143e1313944bf4a5ab34fd3b4be15367a02e9478b0ce800cb510e3bbb9d"}, + {file = "coverage-5.0.3-cp38-cp38m-win32.whl", hash = "sha256:b0840b45187699affd4c6588286d429cd79a99d509fe3de0f209594669bb0954"}, + {file = "coverage-5.0.3-cp38-cp38m-win_amd64.whl", hash = "sha256:76e2057e8ffba5472fd28a3a010431fd9e928885ff480cb278877c6e9943cc2e"}, + {file = "coverage-5.0.3-cp39-cp39m-win32.whl", hash = "sha256:b63dd43f455ba878e5e9f80ba4f748c0a2156dde6e0e6e690310e24d6e8caf40"}, + {file = "coverage-5.0.3-cp39-cp39m-win_amd64.whl", hash = "sha256:da93027835164b8223e8e5af2cf902a4c80ed93cb0909417234f4a9df3bcd9af"}, + {file = "coverage-5.0.3.tar.gz", hash = "sha256:77afca04240c40450c331fa796b3eab6f1e15c5ecf8bf2b8bee9706cd5452fef"}, ] entrypoints = [ {file = "entrypoints-0.3-py2.py3-none-any.whl", hash = "sha256:589f874b313739ad35be6e0cd7efde2a4e9b6fea91edcc34e58ecbb8dbe56d19"}, @@ -491,8 +483,8 @@ gprof2dot = [ {file = "gprof2dot-2019.11.30.tar.gz", hash = "sha256:b43fe04ebb3dfe181a612bbfc69e90555b8957022ad6a466f0308ed9c7f22e99"}, ] identify = [ - {file = "identify-1.4.9-py2.py3-none-any.whl", hash = "sha256:72e9c4ed3bc713c7045b762b0d2e2115c572b85abfc1f4604f5a4fd4c6642b71"}, - {file = "identify-1.4.9.tar.gz", hash = "sha256:6f44e637caa40d1b4cb37f6ed3b262ede74901d28b1cc5b1fc07360871edd65d"}, + {file = "identify-1.4.10-py2.py3-none-any.whl", hash = "sha256:418f3b2313ac0b531139311a6b426854e9cbdfcfb6175447a5039aa6291d8b30"}, + {file = "identify-1.4.10.tar.gz", hash = "sha256:8ad99ed1f3a965612dcb881435bf58abcfbeb05e230bb8c352b51e8eac103360"}, ] isort = [ {file = "isort-4.3.21-py2.py3-none-any.whl", hash = "sha256:6e811fcb295968434526407adb8796944f1988c5b65e8139058f2014cbe100fd"}, @@ -503,11 +495,11 @@ mccabe = [ {file = "mccabe-0.6.1.tar.gz", hash = "sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f"}, ] more-itertools = [ - {file = "more-itertools-8.0.2.tar.gz", hash = "sha256:b84b238cce0d9adad5ed87e745778d20a3f8487d0f0cb8b8a586816c7496458d"}, - {file = "more_itertools-8.0.2-py3-none-any.whl", hash = "sha256:c833ef592a0324bcc6a60e48440da07645063c453880c9477ceb22490aec1564"}, + {file = "more-itertools-8.1.0.tar.gz", hash = "sha256:c468adec578380b6281a114cb8a5db34eb1116277da92d7c46f904f0b52d3288"}, + {file = "more_itertools-8.1.0-py3-none-any.whl", hash = "sha256:1a2a32c72400d365000412fe08eb4a24ebee89997c18d3d147544f70f5403b39"}, ] nodeenv = [ - {file = "nodeenv-1.3.3.tar.gz", hash = "sha256:ad8259494cf1c9034539f6cced78a1da4840a4b157e23640bc4a0c0546b0cb7a"}, + {file = "nodeenv-1.3.4-py2.py3-none-any.whl", hash = "sha256:561057acd4ae3809e665a9aaaf214afff110bbb6a6d5c8a96121aea6878408b3"}, ] pluggy = [ {file = "pluggy-0.13.1-py2.py3-none-any.whl", hash = "sha256:966c145cd83c96502c3c3868f50408687b38434af77734af1e9ca461a4081d2d"}, @@ -537,8 +529,8 @@ pytest = [ {file = "pytest-3.10.1.tar.gz", hash = "sha256:e246cf173c01169b9617fc07264b7b1316e78d7a650055235d6d897bc80d9660"}, ] pytest-benchmark = [ - {file = "pytest-benchmark-3.2.2.tar.gz", hash = "sha256:4512c6805318d07926efcb3b39f7b98a10d035305a93edfd5329c86cbf9cfbf7"}, - {file = "pytest_benchmark-3.2.2-py2.py3-none-any.whl", hash = "sha256:ab851115ce022639173b9497d4a4183a1d8fe9cdcf8fab9d8a57607008aedd3d"}, + {file = "pytest-benchmark-3.2.3.tar.gz", hash = "sha256:ad4314d093a3089701b24c80a05121994c7765ce373478c8f4ba8d23c9ba9528"}, + {file = "pytest_benchmark-3.2.3-py2.py3-none-any.whl", hash = "sha256:01f79d38d506f5a3a0a9ada22ded714537bbdfc8147a881a35c1655db07289d9"}, ] pytest-cov = [ {file = "pytest-cov-2.8.1.tar.gz", hash = "sha256:cc6742d8bac45070217169f5f72ceee1e0e55b0221f54bcf24845972d3a47f2b"}, @@ -550,30 +542,26 @@ pytest-profiling = [ {file = "pytest_profiling-1.7.0-py2.py3-none-any.whl", hash = "sha256:999cc9ac94f2e528e3f5d43465da277429984a1c237ae9818f8cfd0b06acb019"}, {file = "pytest_profiling-1.7.0-py3.6.egg", hash = "sha256:6bce4e2edc04409d2f3158c16750fab8074f62d404cc38eeb075dff7fcbb996c"}, ] -python-magic = [ - {file = "python-magic-0.4.15.tar.gz", hash = "sha256:f3765c0f582d2dfc72c15f3b5a82aecfae9498bd29ca840d72f37d7bd38bfcd5"}, - {file = "python_magic-0.4.15-py2.py3-none-any.whl", hash = "sha256:f2674dcfad52ae6c49d4803fa027809540b130db1dec928cfbb9240316831375"}, -] pyyaml = [ - {file = "PyYAML-5.2-cp27-cp27m-win32.whl", hash = "sha256:35ace9b4147848cafac3db142795ee42deebe9d0dad885ce643928e88daebdcc"}, - {file = "PyYAML-5.2-cp27-cp27m-win_amd64.whl", hash = "sha256:ebc4ed52dcc93eeebeae5cf5deb2ae4347b3a81c3fa12b0b8c976544829396a4"}, - {file = "PyYAML-5.2-cp35-cp35m-win32.whl", hash = "sha256:38a4f0d114101c58c0f3a88aeaa44d63efd588845c5a2df5290b73db8f246d15"}, - {file = "PyYAML-5.2-cp35-cp35m-win_amd64.whl", hash = "sha256:483eb6a33b671408c8529106df3707270bfacb2447bf8ad856a4b4f57f6e3075"}, - {file = "PyYAML-5.2-cp36-cp36m-win32.whl", hash = "sha256:7f38e35c00e160db592091751d385cd7b3046d6d51f578b29943225178257b31"}, - {file = "PyYAML-5.2-cp36-cp36m-win_amd64.whl", hash = "sha256:0e7f69397d53155e55d10ff68fdfb2cf630a35e6daf65cf0bdeaf04f127c09dc"}, - {file = "PyYAML-5.2-cp37-cp37m-win32.whl", hash = "sha256:e4c015484ff0ff197564917b4b4246ca03f411b9bd7f16e02a2f586eb48b6d04"}, - {file = "PyYAML-5.2-cp37-cp37m-win_amd64.whl", hash = "sha256:4b6be5edb9f6bb73680f5bf4ee08ff25416d1400fbd4535fe0069b2994da07cd"}, - {file = "PyYAML-5.2-cp38-cp38-win32.whl", hash = "sha256:8100c896ecb361794d8bfdb9c11fce618c7cf83d624d73d5ab38aef3bc82d43f"}, - {file = "PyYAML-5.2-cp38-cp38-win_amd64.whl", hash = "sha256:2e9f0b7c5914367b0916c3c104a024bb68f269a486b9d04a2e8ac6f6597b7803"}, - {file = "PyYAML-5.2.tar.gz", hash = "sha256:c0ee8eca2c582d29c3c2ec6e2c4f703d1b7f1fb10bc72317355a746057e7346c"}, + {file = "PyYAML-5.3-cp27-cp27m-win32.whl", hash = "sha256:940532b111b1952befd7db542c370887a8611660d2b9becff75d39355303d82d"}, + {file = "PyYAML-5.3-cp27-cp27m-win_amd64.whl", hash = "sha256:059b2ee3194d718896c0ad077dd8c043e5e909d9180f387ce42012662a4946d6"}, + {file = "PyYAML-5.3-cp35-cp35m-win32.whl", hash = "sha256:4fee71aa5bc6ed9d5f116327c04273e25ae31a3020386916905767ec4fc5317e"}, + {file = "PyYAML-5.3-cp35-cp35m-win_amd64.whl", hash = "sha256:dbbb2379c19ed6042e8f11f2a2c66d39cceb8aeace421bfc29d085d93eda3689"}, + {file = "PyYAML-5.3-cp36-cp36m-win32.whl", hash = "sha256:e3a057b7a64f1222b56e47bcff5e4b94c4f61faac04c7c4ecb1985e18caa3994"}, + {file = "PyYAML-5.3-cp36-cp36m-win_amd64.whl", hash = "sha256:74782fbd4d4f87ff04159e986886931456a1894c61229be9eaf4de6f6e44b99e"}, + {file = "PyYAML-5.3-cp37-cp37m-win32.whl", hash = "sha256:24521fa2890642614558b492b473bee0ac1f8057a7263156b02e8b14c88ce6f5"}, + {file = "PyYAML-5.3-cp37-cp37m-win_amd64.whl", hash = "sha256:1cf708e2ac57f3aabc87405f04b86354f66799c8e62c28c5fc5f88b5521b2dbf"}, + {file = "PyYAML-5.3-cp38-cp38-win32.whl", hash = "sha256:70024e02197337533eef7b85b068212420f950319cc8c580261963aefc75f811"}, + {file = "PyYAML-5.3-cp38-cp38-win_amd64.whl", hash = "sha256:cb1f2f5e426dc9f07a7681419fe39cee823bb74f723f36f70399123f439e9b20"}, + {file = "PyYAML-5.3.tar.gz", hash = "sha256:e9f45bd5b92c7974e59bcd2dcc8631a6b6cc380a904725fce7bc08872e691615"}, ] seed-isort-config = [ {file = "seed_isort_config-1.9.4-py2.py3-none-any.whl", hash = "sha256:81f7adf8dd0bc24e03d0f5eef87561e170757fc7a36050c01e4c29d150757783"}, {file = "seed_isort_config-1.9.4.tar.gz", hash = "sha256:cecccb911b8d01ecdca16e17d083bf4cd78e928db4d7906125b0373b81f1c7ec"}, ] six = [ - {file = "six-1.13.0-py2.py3-none-any.whl", hash = "sha256:1f1b7d42e254082a9db6279deae68afb421ceba6158efa6131de7b3003ee93fd"}, - {file = "six-1.13.0.tar.gz", hash = "sha256:30f610279e8b2578cab6db20741130331735c781b56053c59c4076da27f06b66"}, + {file = "six-1.14.0-py2.py3-none-any.whl", hash = "sha256:8f3cd2e254d8f793e7f3d6d9df77b92252b52637291d0f0da013c76ea2724b6c"}, + {file = "six-1.14.0.tar.gz", hash = "sha256:236bdbdce46e6e6a3d61a337c0f8b763ca1e8717c03b369e87a7ec7ce1319c0a"}, ] toml = [ {file = "toml-0.10.0-py2.7.egg", hash = "sha256:f1db651f9657708513243e61e6cc67d101a39bad662eaa9b5546f789338e07a3"}, -- 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(-) 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(-) 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(+) 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() --- CHANGELOG.md | 4 ++++ README.md | 12 ++++++------ config_file/parsers/ini_parser.py | 16 ++++++++++++++-- tests/test_ini_parser.py | 10 ++++++++++ 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5306057..d90dc54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + + - Add support for retrieving entire sections as a `dict` with `get()`. + ## 0.4.0 - 2020-01-19 - Add `reset()` and `save()` methods to `ConfigFile`. This allows you to reset your 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 diff --git a/config_file/parsers/ini_parser.py b/config_file/parsers/ini_parser.py index 3e93e4c..549ed37 100644 --- a/config_file/parsers/ini_parser.py +++ b/config_file/parsers/ini_parser.py @@ -33,15 +33,27 @@ class IniParser(BaseParser): :raises ParsingError: if the specified `section.key` is not found, in an invalid format, or if we are unable to coerce the return value to value_type. """ - # TODO: Support for retrieving entire sections instead of just key/values - section, key = split_on_dot(section_key, only_last_dot=True) + if "." not in section_key: + return self.__retrieve_section(section_key, parse_type) try: + section, key = split_on_dot(section_key, only_last_dot=True) value = self.parsed_content.get(section, key) return parse_value(value) if parse_type else value except configparser.Error as error: raise ParsingError(error.message) + def __retrieve_section(self, section, parse_type): + items = dict(self.parsed_content.items(section)) + + if not parse_type: + return items + + for item in items: + items[item] = parse_value(items[item]) + + return items + def set(self, section_key, value): """ Sets the value of 'section.key' of the config file. If the specified section diff --git a/tests/test_ini_parser.py b/tests/test_ini_parser.py index da1b43e..7af3ea4 100644 --- a/tests/test_ini_parser.py +++ b/tests/test_ini_parser.py @@ -20,6 +20,16 @@ def test_incorrect_ini_formats(ini_file): ("test_section.strkey", "blah", False), ("test_section.boolkey", "false", False), ("test_section.floatkey", "5.3", False), + ( + "test_section", + {"intkey": "5", "strkey": "blah", "boolkey": "false", "floatkey": "5.3"}, + False, + ), + ( + "test_section", + {"intkey": 5, "strkey": "blah", "boolkey": False, "floatkey": 5.3}, + True, + ), ], ) def test_that_ini_parser_can_get_values(section_key, expected_value, parse_type): -- cgit v1.2.3 From 757f14b288979681f2a872bdbb8092f573a1fd07 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sun, 19 Jan 2020 14:40:38 -0600 Subject: =?UTF-8?q?Bump=20version:=200.4.0=20=E2=86=92=200.5.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .bumpversion.cfg | 2 +- CHANGELOG.md | 2 +- config_file/__init__.py | 2 +- pyproject.toml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 19bb5c6..cb0cd7f 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.4.0 +current_version = 0.5.0 commit = True tag = True diff --git a/CHANGELOG.md b/CHANGELOG.md index d90dc54..76e93bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## Unreleased +## 0.5.0 - 2020-01-19 - Add support for retrieving entire sections as a `dict` with `get()`. diff --git a/config_file/__init__.py b/config_file/__init__.py index ce02903..22164c1 100644 --- a/config_file/__init__.py +++ b/config_file/__init__.py @@ -1,7 +1,7 @@ from config_file.config_file import ConfigFile from config_file.parsers.base_parser import BaseParser, ParsingError -__version__ = "0.4.0" +__version__ = "0.5.0" __all__ = [ "ConfigFile", diff --git a/pyproject.toml b/pyproject.toml index 7dd90a8..2f38381 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "config_file" -version = "0.4.0" +version = "0.5.0" description = "Manage your configuration files." authors = ["Eugene Triguba "] readme = "README.md" -- cgit v1.2.3 From d9bddaa1acd7496d13eea1e1d88961c5b670c555 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sun, 19 Jan 2020 14:42:21 -0600 Subject: Fix 0.3.3 with changelog --- CHANGELOG.md | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76e93bc..c12cf1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,15 +21,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 methods in `ConfigFile` simply use the same method in the parser so it doesn't make sense to test those methods.) -## 0.3.3 - -Fixed - - - `TypeError` when setting the key/value pairs since configparser requires the option - to be a string. The parser now just converts the value to a string if it is not one - and then adds the key/value pair. It would still be parsed correctly when retrieving - it. - ## 0.3.3 - 2020-01-18 - 2020-01-17 Changed @@ -40,6 +31,11 @@ Changed Fixed - `ConfigFile` was trying to use `_split_on_dot`, but it no longer inherited from base parser. + + - `TypeError` when setting the key/value pairs since configparser requires the option + to be a string. The parser now just converts the value to a string if it is not one + and then adds the key/value pair. It would still be parsed correctly when retrieving + it. ## 0.3.1 - 2020-01-17 -- cgit v1.2.3 From 5f51ce75b21438115013a7a996a31ea5c809daf9 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sun, 19 Jan 2020 14:42:58 -0600 Subject: Fix date on 0.3.3 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c12cf1b..257f685 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,7 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 methods in `ConfigFile` simply use the same method in the parser so it doesn't make sense to test those methods.) -## 0.3.3 - 2020-01-18 - 2020-01-17 +## 0.3.3 - 2020-01-18 Changed -- cgit v1.2.3 From d273fc16f44d351645d91b74500488c2ccdc2210 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sun, 19 Jan 2020 14:46:20 -0600 Subject: Add spacing --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 257f685..7ccab9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 to look for `config/config.original.json` if no file path is specified. The `save()` method should be called after your changes to the config file. It will write them back out. + - Raise test coverage to 93% (`BaseParser` is abstract so it isn't tested and some methods in `ConfigFile` simply use the same method in the parser so it doesn't make sense to test those methods.) @@ -81,4 +82,4 @@ Added - bump2version for easily upgrading versions of config file - - pytest to dev dependencies for testing later on \ No newline at end of file + - pytest to dev dependencies for testing later on -- cgit v1.2.3