Skip to content

Commit

Permalink
Merge pull request #9 from carstencodes/carstencodes/features/enhance…
Browse files Browse the repository at this point in the history
…-debugging

Added more debugging capabilities
  • Loading branch information
carstencodes authored Feb 21, 2022
2 parents b542dde + 20ba3ce commit 1437f6d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "flake518"
version = "1.2.0"
version = "1.2.1"
description = "A small wrapper around flake8 to support PEP518 pyproject.toml as configuration file."
authors = [
{name = "Carsten Igel", email = "cig@bite-that-bit.de"},
Expand Down
35 changes: 29 additions & 6 deletions src/flake518/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,25 @@
TOOL = "tool"
FLAKE_SECTIONS = ("flake8", "flake518")

def _get_os_var_value(var_name: str) -> bool:
"""
Gets a boolean value describing whether a
OS environment variable is set to a value
equals to 'True' or not.
Args:
var_name (str): The name of the environment variable.
Returns:
bool: True, if the variable is set and equals True; False otherwise.
"""
var_value: Optional[str] = os.getenv(var_name)

if var_value is not None:
return bool(flake518_dbg_env)

return False


def _get_log_level() -> int:
"""Get the log level (INFO or DEBUG).
Expand All @@ -64,11 +83,7 @@ def _get_log_level() -> int:
"""
result: int = logging.INFO

flake518_dbg: bool = False
flake518_dbg_env: Optional[str] = os.getenv("FLAKE518_DEBUG")

if flake518_dbg_env is not None:
flake518_dbg = bool(flake518_dbg_env)
flake518_dbg: bool = _get_os_var_value("FLAKE518_DEBUG")

if flake518_dbg:
result = logging.DEBUG
Expand Down Expand Up @@ -216,14 +231,22 @@ def run(argv: Optional[_List[str]] = None) -> None:
if py_project is not None:
config = read_pyproject_toml(py_project)

keep_file = _get_os_var_value("FLAKE518_KEEPFILE")

if _get_os_var_value("FLAKE518_BLATHER"):
args.append("-vv")
elif _get_os_var_value("FLAKE518_VERBOSE"):
args.append("-v")

if (len(config)) > 0:
logger.debug(
"Found entries in %s. Adding additional configuration...",
py_project,
)
update_configuration(config)
delete_file = not keep_file
with NamedTemporaryFile(
"x+t", prefix=".flake518_", suffix=".cfg", delete=True, dir=py_project.parent
"x+t", prefix=".flake518_", suffix=".cfg", delete=delete_file, dir=py_project.parent
) as handle:
write_config_to_ini(config, handle)
logger.debug(
Expand Down

0 comments on commit 1437f6d

Please sign in to comment.