Skip to content

Commit

Permalink
refactor: explicit naming for flake8 options
Browse files Browse the repository at this point in the history
To avoid confusion with click's env variables.
  • Loading branch information
andreoliwa committed Nov 11, 2023
1 parent 9362dec commit 38102c9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/nitpick/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from loguru import logger

from nitpick.blender import TomlDoc
from nitpick.constants import CONFIG_TOOL_KEY, CONFIG_TOOL_NITPICK_KEY, PROJECT_NAME, OptionEnum
from nitpick.constants import CONFIG_TOOL_KEY, CONFIG_TOOL_NITPICK_KEY, PROJECT_NAME, Flake8OptionEnum
from nitpick.core import Nitpick
from nitpick.exceptions import QuitComplainingError
from nitpick.generic import relative_to_current_dir
Expand All @@ -43,10 +43,10 @@
help="Path to project root",
)
@click.option(
f"--{OptionEnum.OFFLINE.name.lower()}", # pylint: disable=no-member
f"--{Flake8OptionEnum.OFFLINE.name.lower()}", # pylint: disable=no-member
is_flag=True,
default=False,
help=OptionEnum.OFFLINE.value,
help=Flake8OptionEnum.OFFLINE.value,
)
@click.version_option()
def nitpick_cli(project: Path | None = None, offline=False): # pylint: disable=unused-argument # noqa: ARG001
Expand Down
4 changes: 2 additions & 2 deletions src/nitpick/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ def get_environ(self) -> str:
return os.environ.get(self.as_envvar(), "")


class OptionEnum(_OptionMixin, Enum):
"""Options to be used with the CLI."""
class Flake8OptionEnum(_OptionMixin, Enum):
"""Options to be used with the ``flake8`` plugin/CLI."""

OFFLINE = "Offline mode: no style will be downloaded (no HTTP requests at all)"

Expand Down
6 changes: 3 additions & 3 deletions src/nitpick/flake8.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from loguru import logger

from nitpick import __version__
from nitpick.constants import FLAKE8_PREFIX, PROJECT_NAME, OptionEnum
from nitpick.constants import FLAKE8_PREFIX, PROJECT_NAME, Flake8OptionEnum
from nitpick.core import Nitpick, find_main_python_file
from nitpick.exceptions import QuitComplainingError
from nitpick.typedefs import Flake8Error
Expand Down Expand Up @@ -63,7 +63,7 @@ def collect_errors(self) -> Iterator[Fuss]:
def add_options(option_manager: OptionManager):
"""Add the offline option."""
option_manager.add_option(
OptionEnum.OFFLINE.as_flake8_flag(), action="store_true", help=OptionEnum.OFFLINE.value
Flake8OptionEnum.OFFLINE.as_flake8_flag(), action="store_true", help=Flake8OptionEnum.OFFLINE.value
)

@staticmethod
Expand All @@ -75,5 +75,5 @@ def parse_options(option_manager: OptionManager, options, args): # pylint: disa
log_mapping = {1: logging.INFO, 2: logging.DEBUG}
logging.basicConfig(level=log_mapping.get(options.verbose, logging.WARNING))

nit = Nitpick.singleton().init(offline=bool(options.nitpick_offline or OptionEnum.OFFLINE.get_environ()))
nit = Nitpick.singleton().init(offline=bool(options.nitpick_offline or Flake8OptionEnum.OFFLINE.get_environ()))
logger.info("Offline mode: {}", nit.offline)
4 changes: 2 additions & 2 deletions src/nitpick/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
TOML_EXTENSION,
WRITE_STYLE_MAX_ATTEMPTS,
CachingEnum,
OptionEnum,
Flake8OptionEnum,
)
from nitpick.exceptions import Deprecation, QuitComplainingError, pretty_exception
from nitpick.generic import glob_files, url_to_python_path
Expand Down Expand Up @@ -698,7 +698,7 @@ def fetch(self, url: furl) -> str:
click.secho(
f"The URL {url} could not be downloaded. Either your network is unreachable or the URL is broken."
f" Check the URL, fix your connection, or use "
f" {OptionEnum.OFFLINE.as_flake8_flag()} / {OptionEnum.OFFLINE.as_envvar()}=1",
f" {Flake8OptionEnum.OFFLINE.as_flake8_flag()} / {Flake8OptionEnum.OFFLINE.as_envvar()}=1",
fg="red",
err=True,
)
Expand Down

0 comments on commit 38102c9

Please sign in to comment.