Skip to content

Commit

Permalink
feat(structure): improve code structure (fourth review)
Browse files Browse the repository at this point in the history
  • Loading branch information
fmind committed Mar 19, 2024
1 parent 18c14cd commit e4635fb
Show file tree
Hide file tree
Showing 7 changed files with 243 additions and 116 deletions.
325 changes: 216 additions & 109 deletions README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions mlops-python-package.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"ms-python.mypy-type-checker",
"ms-python.python",
"ms-python.vscode-pylance",
"redhat.vscode-yaml",
]
}
}
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ plugins = ["pandera.mypy", "pydantic.mypy"]

[tool.pytest.ini_options]
addopts = "--verbosity=2"
pythonpath = ["src"]

[tool.ruff]
fix = true
Expand Down
6 changes: 4 additions & 2 deletions src/bikes/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ def main(argv: list[str] | None = None) -> int:
schema = settings.MainSettings.model_json_schema()
json.dump(schema, sys.stdout, indent=4)
return 0
files = map(configs.parse_file, args.files)
strings = map(configs.parse_string, args.extras)
files = [configs.parse_file(file) for file in args.files]
strings = [configs.parse_string(string) for string in args.extras]
if len(files) == 0 and len(strings) == 0:
raise RuntimeError("No configs provided.")
config = configs.merge_configs([*files, *strings])
object_ = configs.to_object(config) # python object
setting = settings.MainSettings.model_validate(object_)
Expand Down
4 changes: 2 additions & 2 deletions tasks/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test(ctx: Context) -> None:


@task
def bandit(ctx: Context) -> None:
def security(ctx: Context) -> None:
"""Check the security with bandit."""
ctx.run("poetry run bandit --recursive --configfile=pyproject.toml src/")

Expand All @@ -50,6 +50,6 @@ def coverage(ctx: Context) -> None:
ctx.run("poetry run pytest --numprocesses='auto' --cov=src/ --cov-fail-under=80 tests/")


@task(pre=[poetry, format, type, code, bandit, coverage], default=True)
@task(pre=[poetry, format, type, code, security, coverage], default=True)
def all(_: Context) -> None:
"""Run all check tasks."""
12 changes: 9 additions & 3 deletions tasks/formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@


@task
def code(ctx: Context) -> None:
"""Format python code with ruff."""
def imports(ctx: Context) -> None:
"""Format python imports with ruff."""
ctx.run("poetry run ruff check --select I --fix")


@task
def sources(ctx: Context) -> None:
"""Format python sources with ruff."""
ctx.run("poetry run ruff format src/ tasks/ tests/")


@task(pre=[code], default=True)
@task(pre=[imports, sources], default=True)
def all(_: Context) -> None:
"""Run all format tasks."""
10 changes: 10 additions & 0 deletions tests/test_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,13 @@ def test_main(scenario: str, confs_path: str, extra_config: str) -> None:
status = scripts.main(argv=argv)
# then
assert status == 0, f"Job should succeed for config: {config}"


def test_main__no_configs() -> None:
# given
argv: list[str] = []
# when
with pytest.raises(RuntimeError) as error:
scripts.main(argv)
# then
assert error.match("No configs provided."), "RuntimeError should be raised!"

0 comments on commit e4635fb

Please sign in to comment.