Skip to content

Commit

Permalink
Merge pull request #27 from Cielquan/#26-increase-cc-rating
Browse files Browse the repository at this point in the history
#26 increase cc rating
  • Loading branch information
Cielquan authored Feb 6, 2021
2 parents 75bfec8 + 79103ca commit cae6cc0
Show file tree
Hide file tree
Showing 16 changed files with 810 additions and 205 deletions.
34 changes: 34 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,40 @@
---
version: "2" # required to adjust maintainability checks

exclude_patterns:
- "tests/"
- "docs/source/conf.py"
- "noxfile.py"
- "prep_release.py"

checks:
argument-count:
config:
threshold: 6
complex-logic:
config:
threshold: 4
file-lines:
config:
threshold: 500
identical-code:
config:
threshold: 8
method-complexity:
config:
threshold: 10
method-count:
config:
threshold: 20
method-lines:
config:
threshold: 25
nested-control-flow:
config:
threshold: 4
return-statements:
config:
threshold: 4
similar-code:
config:
threshold: 4
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,27 @@ For a list of all available releases see the
## Unreleased
[diff v4.0.0...main](https://github.com/Cielquan/formelsammlung/compare/v4.0.0...main)

#### BREAKING CHANGES
- change min python version from `3.6.1` to `3.6.2`

#### New features
- refactored `getenv_typed()` *backend* into `EnvVarGetter` class which holds the config

#### Documentation
- improved docs for `envvar.py`
- improved docs for `flask_sphinx_docs.py`
- improved docs for `nox_session.py`

#### Miscellaneous
- updated code-climate config for maintainability checks
[#26](https://github.com/Cielquan/formelsammlung/issues/26)
- refactored `env_var_runner.py` to reduce cognitive complexity and added tests for new
code
- refactored `envvar.py` to reduce cognitive complexity and added tests for new code
- refactored `flask_sphinx_docs.py` to reduce cognitive complexity and added tests for
new code



## [4.0.0](https://github.com/Cielquan/formelsammlung/releases/v4.0.0) (2021-02-04)
[diff v3.2.0...v4.0.0](https://github.com/Cielquan/formelsammlung/compare/v3.2.0...v4.0.0)
Expand Down
2 changes: 2 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
"flask": ("https://flask.palletsprojects.com/en/1.1.x/api/", "inv_flask.inv"),
"nox": ("https://nox.thea.codes/en/stable/", "inv_nox.inv"),
}
nitpick_ignore = [("py:class", "SessionRunner")]

extensions.append("sphinx.ext.extlinks")
extlinks = {
Expand All @@ -131,6 +132,7 @@
apidoc_extra_args = []
if Path("_apidoc_templates").is_dir():
apidoc_extra_args += ["--templatedir", "apidoc_templates"]
autoclass_content = "both"


if find_spec("sphinxcontrib.apidoc") is not None:
Expand Down
Binary file modified docs/source/inv_nox.inv
Binary file not shown.
4 changes: 4 additions & 0 deletions docs/source/spelling_dict.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ arg
args
attr
bool
boolean
bugfixes
cfg
changelog
Expand All @@ -13,6 +14,7 @@ compat
conf
config
csv
deleter
dev
dir
dirs
Expand All @@ -29,6 +31,7 @@ executables
expr
fmt
func
getter
github
html
importlib
Expand Down Expand Up @@ -57,6 +60,7 @@ repo
riedel
rst
sdist
setter
st
submodule
submodules
Expand Down
12 changes: 9 additions & 3 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,12 @@ def test_code(session: Session) -> None:
extras = "testing"
session.poetry_install(
extras,
no_root=(TOX_CALLS or SKIP_INSTALL),
no_root=True,
no_dev=(TOX_CALLS or IN_CI),
pip_require_venv=poetry_require_venv(session),
)
if not (TOX_CALLS or SKIP_INSTALL):
session.install(".")
else:
session.log("Skipping install step.")
#: Remove processed posargs
Expand Down Expand Up @@ -470,10 +472,12 @@ def docs(session: Session) -> None:
if "skip_install" not in session.posargs:
session.poetry_install(
extras,
no_root=(TOX_CALLS or SKIP_INSTALL),
no_root=True,
no_dev=(TOX_CALLS or IN_CI),
pip_require_venv=poetry_require_venv(session),
)
if not (TOX_CALLS or SKIP_INSTALL):
session.install(".")
else:
session.log("Skipping install step.")

Expand All @@ -500,10 +504,12 @@ def test_docs(session: Session, builder: str) -> None:
extras = "docs"
session.poetry_install(
extras,
no_root=(TOX_CALLS or SKIP_INSTALL),
no_root=True,
no_dev=(TOX_CALLS or IN_CI),
pip_require_venv=poetry_require_venv(session),
)
if not (TOX_CALLS or SKIP_INSTALL):
session.install(".")
else:
session.log("Skipping install step.")
#: Remove processed posargs
Expand Down
2 changes: 1 addition & 1 deletion prep_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class PyprojectError(Exception):
"""Exception for lookup errors in pyproject.toml file."""


def _get_config_value(section: str, key: str) -> str:
def _get_config_value(section: str, key: str) -> str: # noqa: CCR001
"""Extract a config value from pyproject.toml file.
:return: config value
Expand Down
8 changes: 6 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"Source" = "https://github.com/Cielquan/formelsammlung"

[tool.poetry.dependencies]
python = "^3.6.1"
python = "^3.6.2" # NOTE: update min_python_version below also
importlib-metadata = {version = ">=1.6, <4.0", python = "<3.8"}
flask = {version = "^1.1.2", optional = true}
nox = {version = "^2020.12.31", optional = true}
Expand Down Expand Up @@ -228,7 +228,8 @@
format="colored"
max_line_length = 88
max_complexity = 20
max_cognitive_complexity = 20
max_cognitive_complexity = 10
min_python_version = "3.6.2"
pytest_fixture_no_parentheses = true

[tool.flakehell.plugins]
Expand Down Expand Up @@ -278,6 +279,9 @@
flake8-bandit = [
"-S101", # assert used
]
pylint = [
"-W0212", # accesss protected member
]

[tool.flakehell.exceptions."noxfile.py"]
flake8-cognitive-complexity = [
Expand Down
49 changes: 28 additions & 21 deletions src/formelsammlung/env_exe_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,27 @@
from typing import List, Optional


IS_WIN = sys.platform == "win32"
EXE = "Scripts/{tool}.exe" if IS_WIN else "bin/{tool}"


def _check_runner_envs(venv_runner: str, envs: List[str], tool: str) -> Optional[Path]:
"""Check if executable is found in any of the envs for given env runner."""
for env in envs:
path = Path(f".{venv_runner}") / env / EXE.format(tool=tool)
if path.is_file():
return path
return None


def _check_venv(venv: str, tool: str) -> Optional[Path]:
"""Check if executable is found in venv."""
path = Path(venv) / EXE.format(tool=tool)
if path.is_file():
return path
return None


def env_exe_runner(
venv_runner: List[str],
envs: List[str],
Expand All @@ -31,42 +52,28 @@ def env_exe_runner(
:param tool_args: Arguments to give to the ``tool``.
:return: Exit code 127 if no executable is found or the exit code of the called cmd.
"""
is_win = sys.platform == "win32"

exe = Path(f"Scripts/{tool}.exe") if is_win else Path(f"bin/{tool}")
cmd = None

if not tool_args:
tool_args = []

cmd_path = None
error_msgs = []

for runner in venv_runner:

if runner in ("tox", "nox"):
error_msgs.append(f"- '{runner}' envs: {envs}")

for env in envs:
path = Path(f".{runner}") / env / exe
if path.is_file():
cmd = (str(path), *tool_args)
break

cmd_path = _check_runner_envs(runner, envs, tool)
else:
error_msgs.append(f"- virtual env: ['{runner}']")
cmd_path = _check_venv(runner, tool)

path = Path(runner) / exe
if path.is_file():
cmd = (str(path), *tool_args)
break
if cmd_path is not None:
break

if cmd is None:
if cmd_path is None:
print(f"No '{tool}' executable found. Searched in:")
for msg in error_msgs:
print(msg)
return 127

return subprocess.call(cmd) # noqa: S603
return subprocess.call([str(cmd_path), *(tool_args or [])]) # noqa: S603


def cli_caller() -> int:
Expand Down
Loading

0 comments on commit cae6cc0

Please sign in to comment.