diff options
| author | Eugene Triguba <eugenetriguba@gmail.com> | 2020-06-20 15:30:11 -0500 |
|---|---|---|
| committer | Eugene Triguba <eugenetriguba@gmail.com> | 2020-06-20 15:30:11 -0500 |
| commit | a4d252e5dbcf8d366707ab0c4ddac8a81963a801 (patch) | |
| tree | 4cd1487bb27d96018f4763fa0d35a80e799ab2ed | |
| parent | Change path, parser, and contents to be properties (diff) | |
| download | config-file-a4d252e5dbcf8d366707ab0c4ddac8a81963a801.zip | |
Revert Python 3.5 support
| -rw-r--r-- | CHANGELOG.md | 1 | ||||
| -rw-r--r-- | CONTRIBUTING.md | 35 | ||||
| -rw-r--r-- | config_file/config_file.py | 10 | ||||
| -rw-r--r-- | config_file/parsers/ini_parser.py | 6 | ||||
| -rw-r--r-- | config_file/parsers/json_parser.py | 4 | ||||
| -rw-r--r-- | config_file/utils.py | 14 | ||||
| -rw-r--r-- | pyproject.toml | 9 | ||||
| -rw-r--r-- | tox.ini | 6 |
8 files changed, 41 insertions, 44 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c9e591..3f89271 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Added -- Support for Python 3.5 by removing use of f-strings from codebase. - A generic `ConfigFileError`. - More type hints from `typings` have been added to `ConfigFile` for better type information. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8669fd0..902c669 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -14,33 +14,34 @@ Here are some guidelines to keep in mind when submitting a pull request: paragraphs of explanation as you need. This is the place to clarify any subtleties you have in your implemeƒntation, document other approaches you tried that didn't end up working, any limitations on your implementation, etc. The most important - part here is to describe *why* you made the change you did, not simply *what* the + part here is to describe _why_ you made the change you did, not simply _what_ the change you made is. - Changelog: Please ensure to update the changelog by adding a new bullet under - an ``Added``, ``Changed``, ``Deprecated``, ``Removed``, ``Fixed``, or ``Security`` section - headers under the ``Unreleased`` version. If any of those sections are not present, + an `Added`, `Changed`, `Deprecated`, `Removed`, `Fixed`, or `Security` section + headers under the `Unreleased` version. If any of those sections are not present, feel free to add the one you need. See [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) if you need guidance on what makes a good entry since this project follows those principles. If you're not comfortable with your English, we'd be happy to write it for you. -- Ensure the tests pass: ``poetry run task test`` to run all tests. +- Ensure the tests pass: `poetry run task test` to run all tests. - New features should be accompanied with tests for them: + - Unit tests are written using [pytest](https://docs.pytest.org/en/latest/). - Pre-commit pipeline: We use a pre-commit pipeline to ensure standard code format. - - Unused imports are automatically removed using `autoflake <https://github.com/myint/autoflake>`_ - - - The remaining imports are sorted using `isort <https://github.com/timothycrosley/isort>`_. - - - All code is automatically formatted with `black <https://github.com/psf/black>`_ - - - Lastly, everything is checked by `flake8 <https://gitlab.com/pycqa/flake8>`_. - - Make sure to install pre-commit before making commits. + - Unused imports are automatically removed using `autoflake <https://github.com/myint/autoflake>`\_ + + - The remaining imports are sorted using `isort <https://github.com/timothycrosley/isort>`\_. + + - All code is automatically formatted with `black <https://github.com/psf/black>`\_ + + - Lastly, everything is checked by `flake8 <https://gitlab.com/pycqa/flake8>`\_. + + Make sure to install pre-commit before making commits. Note: if any of the items had to do any reformatting, sorting, etc., the commit will fail. You'll have to re-add the items it fixed and try again. @@ -48,11 +49,11 @@ Here are some guidelines to keep in mind when submitting a pull request: ```bash pre-commit install ``` - + - 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. -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 +To get started, make sure you have poetry installed and run `poetry install` and +`poetry shell` to enter the virtual environment. diff --git a/config_file/config_file.py b/config_file/config_file.py index d4131de..3af1083 100644 --- a/config_file/config_file.py +++ b/config_file/config_file.py @@ -55,9 +55,7 @@ class ConfigFile: file_path = ".".join(file_parts) if Path(file_path).is_dir(): - raise ValueError( - "The specified config file ({}) is a directory.".format(file_path) - ) + raise ValueError(f"The specified config file ({file_path}) is a directory.") return file_path @@ -74,7 +72,7 @@ class ConfigFile: return JsonParser(self.__contents) else: raise ValueError( - "File path contains an unrecognized file type: {}".format(file_path) + f"File path contains an unrecognized file type: {file_path}" ) def get(self, key: str, parse_types: bool = False, return_type=None, default=None): @@ -91,6 +89,8 @@ class ConfigFile: :param default: The default value to return if the value of the key is empty. :return: The value of the key. + + :raises ValueError: If the value is not able to be coerced into return_type """ if default is None: key_value = self.__parser.get(key, parse_types=parse_types) @@ -144,7 +144,7 @@ class ConfigFile: if not Path(original_file_path).exists(): raise FileNotFoundError( - "The {} file to restore to does not exist.".format(original_file_path) + f"The {original_file_path} file to restore to does not exist." ) self.__path.expanduser().unlink() diff --git a/config_file/parsers/ini_parser.py b/config_file/parsers/ini_parser.py index 31b0dcf..2db1ae8 100644 --- a/config_file/parsers/ini_parser.py +++ b/config_file/parsers/ini_parser.py @@ -1,10 +1,10 @@ import configparser from io import StringIO +from config_file.exceptions import ParsingError from config_file.parsers.base_parser import BaseParser from config_file.parsers.parse_value import parse_value from config_file.utils import split_on_dot -from config_file.exceptions import ParsingError class IniParser(BaseParser): @@ -96,7 +96,7 @@ class IniParser(BaseParser): if "." not in section_key: if not self.parsed_content.has_section(section_key): raise ValueError( - "Cannot delete {} because it is not in the config file.".format(section_key) + f"Cannot delete {section_key} because it is not in the config file." ) self.parsed_content.remove_section(section_key) @@ -105,7 +105,7 @@ class IniParser(BaseParser): section, key = split_on_dot(section_key, only_last_dot=True) if key not in self.parsed_content[section]: raise ValueError( - "Cannot delete {section}.{key} because {key} is not in {section}.".format(section = section, key = key) + f"Cannot delete {section}.{key} because {key} is not in {section}." ) self.parsed_content.remove_option(section, key) diff --git a/config_file/parsers/json_parser.py b/config_file/parsers/json_parser.py index 4d93ca3..10d5afc 100644 --- a/config_file/parsers/json_parser.py +++ b/config_file/parsers/json_parser.py @@ -7,10 +7,10 @@ from nested_lookup import ( nested_update, ) +from config_file.exceptions import ParsingError from config_file.parsers.base_parser import BaseParser from config_file.parsers.parse_value import parse_value from config_file.utils import split_on_dot -from config_file.exceptions import ParsingError class JsonParser(BaseParser): @@ -78,7 +78,7 @@ class JsonParser(BaseParser): result = result[key] except TypeError: raise ParsingError( - "Cannot get {} because {} is not subscriptable.".format(key, key_for_error) + f"Cannot get {key} because {key_for_error} is not subscriptable." ) else: result = self.parsed_content[key] diff --git a/config_file/utils.py b/config_file/utils.py index 05c3a7a..9ed09b5 100644 --- a/config_file/utils.py +++ b/config_file/utils.py @@ -1,8 +1,8 @@ -from pathlib import Path -from typing import Union +from pathlib import PurePath +from typing import Type, Union -def split_on_dot(line: Union[str, Path], only_last_dot=False): +def split_on_dot(line: Union[str, Type[PurePath]], only_last_dot=False): """ Split a string on the dot character (.). @@ -11,17 +11,15 @@ def split_on_dot(line: Union[str, Path], only_last_dot=False): :raises ValueError: if the line does not have a dot. """ - if isinstance(line, Path): + if isinstance(line, PurePath): line = str(line) if "." not in line: - raise ValueError( - "The given string does not have a dot to split on: {}".format(line) - ) + raise ValueError(f"The given string does not have a dot to split on: {line}") return line.rsplit(".", 1) if only_last_dot else line.split(".") -def read_file(path: Union[str, Path]): +def read_file(path: Union[str, Type[PurePath]]): with open(path, "r") as file: return file.read() diff --git a/pyproject.toml b/pyproject.toml index 97c98c7..0f3bf5f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,7 +11,6 @@ classifiers = [ "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", - "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", @@ -23,7 +22,7 @@ classifiers = [ test = "poetry run pytest -v --cov=config_file/ --cov-report term-missing tests/" [tool.poetry.dependencies] -python = "^3.5" +python = "^3.6" nested-lookup = "^0.2.21" toml = { version = "^0.10.0", optional = true } pyyaml = { version = "^5.3.1", optional = true } @@ -42,14 +41,14 @@ pytest-cov = "^2.8.1" pytest-sugar = "^0.9.3" sphinx = "^2.4.4" sphinx_rtd_theme = "^0.4.3" -taskipy = { version = "^1.2.1", python = "^3.6" } +taskipy = "^1.2.1" bump2version = "^1.0.0" flake8 = "^3.7.9" -black = { version = "^19.10b0", python = "^3.6" } +black = "^19.10b0" [tool.black] line-length = 88 -target_version = ['py35'] +target_version = ['py36'] include = '\.pyi?$' [tool.isort] @@ -1,6 +1,6 @@ [tox] isolated_build = true -envlist = py{35, 36, 37, 38} +envlist = py{36, 37, 38} recreate = True [testenv] @@ -9,6 +9,6 @@ deps = codecov>=1.4.0 whitelist_externals = poetry commands = poetry install -v --no-dev -E toml -E yaml - pip install pytest pytest-cov requests - poetry run pytest -v --cov=config_file/ --cov-report term-missing tests/ + pip install pytest pytest-cov requests taskipy + poetry run task test codecov -e TOXENV |