From 4a6e468e1ff56899876a87e44d9acac2b4e3a069 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Sun, 3 Jan 2021 15:36:04 +0100 Subject: [PATCH] refactor: rename modules to reflect pep8 recommendations (#19) --- dockertidy/{Autostop.py => autostop.py} | 6 ++--- dockertidy/{Cli.py => cli.py} | 14 +++++------ dockertidy/{Config.py => config.py} | 16 ++++++------- dockertidy/{Exception.py => exception.py} | 0 ...rbageCollector.py => garbage_collector.py} | 6 ++--- dockertidy/{Logger.py => logger.py} | 4 ++-- dockertidy/{Parser.py => parser.py} | 0 dockertidy/test/unit/test_autostop.py | 24 +++++++++---------- dockertidy/test/unit/test_garbagecollector.py | 6 ++--- dockertidy/{Utils.py => utils.py} | 0 poetry.lock | 6 ++--- pyproject.toml | 4 ++-- 12 files changed, 43 insertions(+), 43 deletions(-) rename dockertidy/{Autostop.py => autostop.py} (96%) rename dockertidy/{Cli.py => cli.py} (93%) rename dockertidy/{Config.py => config.py} (95%) rename dockertidy/{Exception.py => exception.py} (100%) rename dockertidy/{GarbageCollector.py => garbage_collector.py} (98%) rename dockertidy/{Logger.py => logger.py} (98%) rename dockertidy/{Parser.py => parser.py} (100%) rename dockertidy/{Utils.py => utils.py} (100%) diff --git a/dockertidy/Autostop.py b/dockertidy/autostop.py similarity index 96% rename from dockertidy/Autostop.py rename to dockertidy/autostop.py index 2bbcbc7..9eec3d6 100644 --- a/dockertidy/Autostop.py +++ b/dockertidy/autostop.py @@ -6,9 +6,9 @@ import docker.errors import requests.exceptions import docker -from dockertidy.Config import SingleConfig -from dockertidy.Logger import SingleLog -from dockertidy.Parser import timedelta +from dockertidy.config import SingleConfig +from dockertidy.logger import SingleLog +from dockertidy.parser import timedelta class AutoStop: diff --git a/dockertidy/Cli.py b/dockertidy/cli.py similarity index 93% rename from dockertidy/Cli.py rename to dockertidy/cli.py index 95823c2..126c02f 100644 --- a/dockertidy/Cli.py +++ b/dockertidy/cli.py @@ -3,13 +3,13 @@ import argparse -import dockertidy.Exception +import dockertidy.exception from dockertidy import __version__ -from dockertidy.Autostop import AutoStop -from dockertidy.Config import SingleConfig -from dockertidy.GarbageCollector import GarbageCollector -from dockertidy.Logger import SingleLog -from dockertidy.Parser import timedelta_validator +from dockertidy.autostop import AutoStop +from dockertidy.config import SingleConfig +from dockertidy.garbage_collector import GarbageCollector +from dockertidy.logger import SingleLog +from dockertidy.parser import timedelta_validator class DockerTidy: @@ -124,7 +124,7 @@ class DockerTidy: def _get_config(self): try: config = SingleConfig(args=self.args) - except dockertidy.Exception.ConfigError as e: + except dockertidy.exception.ConfigError as e: self.log.sysexit_with_message(e) try: diff --git a/dockertidy/Config.py b/dockertidy/config.py similarity index 95% rename from dockertidy/Config.py rename to dockertidy/config.py index c14dc28..d3f45a8 100644 --- a/dockertidy/Config.py +++ b/dockertidy/config.py @@ -10,11 +10,11 @@ import ruamel.yaml from appdirs import AppDirs from jsonschema._utils import format_as_index -import dockertidy.Exception -import dockertidy.Parser -from dockertidy.Parser import env -from dockertidy.Utils import Singleton -from dockertidy.Utils import dict_intersect +import dockertidy.exception +import dockertidy.parser +from dockertidy.parser import env +from dockertidy.utils import Singleton +from dockertidy.utils import dict_intersect config_dir = AppDirs("docker-tidy").user_config_dir default_config_file = os.path.join(config_dir, "config.yml") @@ -162,7 +162,7 @@ class Config(): if '"{}" not set'.format(envname) in str(e): pass else: - raise dockertidy.Exception.ConfigError( + raise dockertidy.exception.ConfigError( "Unable to read environment variable", str(e) ) @@ -194,7 +194,7 @@ class Config(): normalized = ruamel.yaml.safe_load(s) except (ruamel.yaml.composer.ComposerError, ruamel.yaml.scanner.ScannerError) as e: message = "{} {}".format(e.context, e.problem) - raise dockertidy.Exception.ConfigError( + raise dockertidy.exception.ConfigError( "Unable to read config file {}".format(config), message ) @@ -236,7 +236,7 @@ class Config(): schema=format_as_index(list(e.relative_schema_path)[:-1]), message=e.message ) - raise dockertidy.Exception.ConfigError("Configuration error", schema_error) + raise dockertidy.exception.ConfigError("Configuration error", schema_error) return True diff --git a/dockertidy/Exception.py b/dockertidy/exception.py similarity index 100% rename from dockertidy/Exception.py rename to dockertidy/exception.py diff --git a/dockertidy/GarbageCollector.py b/dockertidy/garbage_collector.py similarity index 98% rename from dockertidy/GarbageCollector.py rename to dockertidy/garbage_collector.py index 115a973..3b73981 100644 --- a/dockertidy/GarbageCollector.py +++ b/dockertidy/garbage_collector.py @@ -9,9 +9,9 @@ import docker.errors import requests.exceptions import docker -from dockertidy.Config import SingleConfig -from dockertidy.Logger import SingleLog -from dockertidy.Parser import timedelta +from dockertidy.config import SingleConfig +from dockertidy.logger import SingleLog +from dockertidy.parser import timedelta class GarbageCollector: diff --git a/dockertidy/Logger.py b/dockertidy/logger.py similarity index 98% rename from dockertidy/Logger.py rename to dockertidy/logger.py index 3f019e8..389a9a7 100644 --- a/dockertidy/Logger.py +++ b/dockertidy/logger.py @@ -8,8 +8,8 @@ import sys import colorama from pythonjsonlogger import jsonlogger -from dockertidy.Utils import Singleton -from dockertidy.Utils import to_bool +from dockertidy.utils import Singleton +from dockertidy.utils import to_bool CONSOLE_FORMAT = "{}[%(levelname)s]{} %(message)s" JSON_FORMAT = "(asctime) (levelname) (message)" diff --git a/dockertidy/Parser.py b/dockertidy/parser.py similarity index 100% rename from dockertidy/Parser.py rename to dockertidy/parser.py diff --git a/dockertidy/test/unit/test_autostop.py b/dockertidy/test/unit/test_autostop.py index 244b3c6..12a0d5b 100644 --- a/dockertidy/test/unit/test_autostop.py +++ b/dockertidy/test/unit/test_autostop.py @@ -3,7 +3,7 @@ import pytest import docker -from dockertidy import Autostop +from dockertidy import autostop pytest_plugins = [ "dockertidy.test.fixtures.fixtures", @@ -11,28 +11,28 @@ pytest_plugins = [ @pytest.fixture -def autostop(mocker): +def autostop_fixture(mocker): mocker.patch.object( - Autostop.AutoStop, + autostop.AutoStop, "_get_docker_client", return_value=mocker.create_autospec(docker.APIClient) ) - stop = Autostop.AutoStop() + stop = autostop.AutoStop() return stop -def test_stop_container(autostop, mocker): +def test_stop_container(autostop_fixture, mocker): client = mocker.create_autospec(docker.APIClient) cid = "asdb" - autostop._stop_container(client, cid) + autostop_fixture._stop_container(client, cid) client.stop.assert_called_once_with(cid) -def test_build_container_matcher(autostop, mocker): +def test_build_container_matcher(autostop_fixture, mocker): prefixes = ["one_", "two_"] - matcher = autostop._build_container_matcher(prefixes) + matcher = autostop_fixture._build_container_matcher(prefixes) assert matcher("one_container") assert matcher("two_container") @@ -40,9 +40,9 @@ def test_build_container_matcher(autostop, mocker): assert not matcher("one") -def test_has_been_running_since_true(autostop, container, later_time): - assert autostop._has_been_running_since(container, later_time) +def test_has_been_running_since_true(autostop_fixture, container, later_time): + assert autostop_fixture._has_been_running_since(container, later_time) -def test_has_been_running_since_false(autostop, container, earlier_time): - assert not autostop._has_been_running_since(container, earlier_time) +def test_has_been_running_since_false(autostop_fixture, container, earlier_time): + assert not autostop_fixture._has_been_running_since(container, earlier_time) diff --git a/dockertidy/test/unit/test_garbagecollector.py b/dockertidy/test/unit/test_garbagecollector.py index 6b9c922..6efa0b9 100644 --- a/dockertidy/test/unit/test_garbagecollector.py +++ b/dockertidy/test/unit/test_garbagecollector.py @@ -4,7 +4,7 @@ import pytest import requests import docker -from dockertidy import GarbageCollector +from dockertidy import garbage_collector pytest_plugins = [ "dockertidy.test.fixtures.fixtures", @@ -14,12 +14,12 @@ pytest_plugins = [ @pytest.fixture def gc(mocker): mocker.patch.object( - GarbageCollector.GarbageCollector, + garbage_collector.GarbageCollector, "_get_docker_client", return_value=mocker.create_autospec(docker.APIClient) ) - gc = GarbageCollector.GarbageCollector() + gc = garbage_collector.GarbageCollector() return gc diff --git a/dockertidy/Utils.py b/dockertidy/utils.py similarity index 100% rename from dockertidy/Utils.py rename to dockertidy/utils.py diff --git a/poetry.lock b/poetry.lock index e8a6536..f1f8271 100644 --- a/poetry.lock +++ b/poetry.lock @@ -362,7 +362,7 @@ python-versions = "*" [[package]] name = "isort" -version = "5.6.4" +version = "5.7.0" description = "A Python utility / library to sort Python imports." category = "dev" optional = false @@ -976,8 +976,8 @@ ipaddress = [ {file = "ipaddress-1.0.23.tar.gz", hash = "sha256:b7f8e0369580bb4a24d5ba1d7cc29660a4a6987763faf1d8a8046830e020e7e2"}, ] isort = [ - {file = "isort-5.6.4-py3-none-any.whl", hash = "sha256:dcab1d98b469a12a1a624ead220584391648790275560e1a43e54c5dceae65e7"}, - {file = "isort-5.6.4.tar.gz", hash = "sha256:dcaeec1b5f0eca77faea2a35ab790b4f3680ff75590bfcb7145986905aab2f58"}, + {file = "isort-5.7.0-py3-none-any.whl", hash = "sha256:fff4f0c04e1825522ce6949973e83110a6e907750cd92d128b0d14aaaadbffdc"}, + {file = "isort-5.7.0.tar.gz", hash = "sha256:c729845434366216d320e936b8ad6f9d681aab72dc7cbc2d51bedc3582f3ad1e"}, ] jsonschema = [ {file = "jsonschema-3.2.0-py2.py3-none-any.whl", hash = "sha256:4e5b3cf8216f577bee9ce139cbe72eca3ea4f292ec60928ff24758ce626cd163"}, diff --git a/pyproject.toml b/pyproject.toml index 0ef00a7..f25fdcc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -77,7 +77,7 @@ pytest-mock = "^3.3.1" yapf = "^0.30.0" [tool.poetry.scripts] -docker-tidy = "dockertidy.Cli:main" +docker-tidy = "dockertidy.cli:main" [tool.poetry-dynamic-versioning] enable = true @@ -92,7 +92,7 @@ sections = ["FUTURE", "STDLIB", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"] skip_glob = ["**/.env*", "**/env/*", "**/docs/*"] [tool.pytest.ini_options] -addopts = "--cov=dockertidy --cov-report xml:coverage.xml --cov-append --no-cov-on-fail" +addopts = "dockertidy --cov=dockertidy --cov-report=xml:coverage.xml --cov-report=term --cov-append --no-cov-on-fail" filterwarnings = [ "ignore::FutureWarning", "ignore:.*collections.*:DeprecationWarning",