Skip to content

Commit

Permalink
Fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
rgryta committed Jul 17, 2024
1 parent d4513bc commit 5ad6f96
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 12 deletions.
4 changes: 4 additions & 0 deletions check_bump/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@


class VersionChecker(StrEnum):
"""
Available version checkers
"""

TOML = auto()
REGEX = auto()
TOUCH = auto()
Expand Down
12 changes: 8 additions & 4 deletions check_bump/methods/regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@


def argparser(subparsers: argparse._SubParsersAction) -> None: # pragma: no cover
"""Create argparse subparser for toml method"""
"""
Create argparse subparser for toml method
"""
parser = subparsers.add_parser("regex", help="Regex file parsing")
parser.add_argument("-p", "--path", type=str, default="pyproject.toml", help="Path to file that manages versions")
parser.add_argument(
Expand All @@ -33,16 +35,18 @@ def _get_version(file_content: str, args: argparse.Namespace) -> str:
"""
match = re.match(args.regex, file_content, flags=re.DOTALL)
if not match:
logger.error(f"Version not found in file")
logger.error("Version not found in file")
sys.exit(2)
return match.group(1)


def check(args):
"""Check bump with regex method"""
"""
Check bump with regex method
"""
file_path = get_file_path(args.path)

# New version
# New version # pylint:disable=R0801
with open(file_path, encoding="utf-8") as file:
current_version = _get_version(file.read(), args)

Expand Down
6 changes: 4 additions & 2 deletions check_bump/methods/toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@


def argparser(subparsers: argparse._SubParsersAction) -> None: # pragma: no cover
"""Create argparse subparser for toml method"""
"""
Create argparse subparser for toml method
"""
parser = subparsers.add_parser("toml", help="Parsing toml file")
parser.add_argument(
"-p", "--path", type=str, default="pyproject.toml", help="Path to toml file that manages versions"
Expand Down Expand Up @@ -47,7 +49,7 @@ def check(args: argparse.Namespace): # pragma: no cover
"""
file_path = get_file_path(args.path)

if not str(file_path.parts[-1]) == "pyproject.toml":
if str(file_path.parts[-1]) != "pyproject.toml":
logger.warning(f"Not a pyproject.toml file: {file_path}")

# New version
Expand Down
9 changes: 6 additions & 3 deletions check_bump/methods/touch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
This module contains the methods for the touch check bump.
"""

import re
import sys
import shlex
import logging
Expand All @@ -15,13 +14,17 @@


def argparser(subparsers: argparse._SubParsersAction) -> None: # pragma: no cover
"""Create argparse subparser for toml method"""
"""
Create argparse subparser for toml method
"""
parser = subparsers.add_parser("touch", help="Touch file check")
parser.add_argument("-p", "--path", type=str, default="pyproject.toml", help="Path to file that manages versions")


def check(args):
"""Check bump with touch method"""
"""
Check bump with touch method
"""
file_path = get_file_path(args.path)

# New version
Expand Down
14 changes: 11 additions & 3 deletions check_bump/path.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Common path methods
"""

import os
import sys
import logging
Expand All @@ -9,7 +13,9 @@


def get_file_path(path: str) -> pathlib.Path:
"""Get file path from provided path. If path is a directory, check for `pyproject.toml` file."""
"""
Get file path from provided path. If path is a directory, check for `pyproject.toml` file.
"""
curr_path = pathlib.Path(os.getcwd())

file_path = pathlib.Path(path)
Expand All @@ -29,13 +35,15 @@ def get_file_path(path: str) -> pathlib.Path:
logger.error(f"[{file_path}] is not a path to `pyproject.toml`")
sys.exit(2)

if not str(file_path.parts[-1]) == "pyproject.toml":
if str(file_path.parts[-1]) != "pyproject.toml":
logger.warning(f"Not a pyproject.toml file: {file_path}")
return file_path


def get_repo_file(file_path: pathlib.Path):
"""Set the repository path and return the relative path to the file"""
"""
Set the repository path and return the relative path to the file
"""
base_path = git_repo_path()
rel_path = os.path.relpath(file_path, start=base_path)
return rel_path

0 comments on commit 5ad6f96

Please sign in to comment.