Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.9.0 #11

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
]
}
}
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[tool.poetry]
name = "bikes"
version = "0.8.0"
version = "0.9.0"
description = "Predict the number of bikes available."
repository = "https://github.com/fmind/mlops-python-package"
documentation = "https://fmind.github.io/mlops-python-package/"
Expand Down 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!"