From 8bbd7faf09351c129dcedd5aeddb310cc9454c15 Mon Sep 17 00:00:00 2001 From: Ruidy Date: Mon, 5 Jul 2021 18:46:05 +0200 Subject: [PATCH] feat: refactor app --- Makefile | 17 +++++++++++------ Pipfile | 1 + Pipfile.lock | 29 +++++++++++++++++++++++------ app/main.py | 14 ++++++++++++++ app/main_test.py | 4 ++-- 5 files changed, 51 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 32c1f55..a522fcd 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,16 @@ .PHONY: lint lint: - black -l 99 . - flake8 . - mypy . - vulture . - bandit . + pipenv run black -l 99 . + pipenv run flake8 . + pipenv run mypy . + pipenv run vulture . + pipenv run bandit . .PHONY: test test: - pytest -v app/ \ No newline at end of file + pytest -v + +.PHONY: cli +cli: + pipenv run python app/main.py + diff --git a/Pipfile b/Pipfile index 90c7b43..885d646 100644 --- a/Pipfile +++ b/Pipfile @@ -4,6 +4,7 @@ verify_ssl = true name = "pypi" [packages] +typer = "*" [dev-packages] bandit = "*" diff --git a/Pipfile.lock b/Pipfile.lock index aa932f1..5dd7a69 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "59d461042336fd4cdcc06bf22ef4f96e37a2192ea2a45f76767151f8db5502d0" + "sha256": "1a3b805c8e7a09b28dbba4cf1ca47933dbbec3fb63377f92acec697ac9ebb920" }, "pipfile-spec": 6, "requires": { @@ -15,7 +15,24 @@ } ] }, - "default": {}, + "default": { + "click": { + "hashes": [ + "sha256:d2b5255c7c6349bc1bd1e59e08cd12acbbd63ce649f2588755783aa94dfb6b1a", + "sha256:dacca89f4bfadd5de3d7489b7c8a566eee0d3676333fbb50030263894c38c0dc" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'", + "version": "==7.1.2" + }, + "typer": { + "hashes": [ + "sha256:5455d750122cff96745b0dec87368f56d023725a7ebc9d2e54dd23dc86816303", + "sha256:ba58b920ce851b12a2d790143009fa00ac1d05b3ff3257061ff69dbdfc3d161b" + ], + "index": "pypi", + "version": "==0.3.2" + } + }, "develop": { "appdirs": { "hashes": [ @@ -50,11 +67,11 @@ }, "click": { "hashes": [ - "sha256:8c04c11192119b1ef78ea049e0a6f0463e4c48ef00a30160c704337586f3ad7a", - "sha256:fba402a4a47334742d782209a7c79bc448911afe1149d07bdabdf480b3e2f4b6" + "sha256:d2b5255c7c6349bc1bd1e59e08cd12acbbd63ce649f2588755783aa94dfb6b1a", + "sha256:dacca89f4bfadd5de3d7489b7c8a566eee0d3676333fbb50030263894c38c0dc" ], - "markers": "python_version >= '3.6'", - "version": "==8.0.1" + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'", + "version": "==7.1.2" }, "flake8": { "hashes": [ diff --git a/app/main.py b/app/main.py index 4cdd921..8b89802 100644 --- a/app/main.py +++ b/app/main.py @@ -1,6 +1,8 @@ import random import string +import typer + def generate_password(seed: int) -> str: lowercase = string.ascii_lowercase @@ -12,3 +14,15 @@ def generate_password(seed: int) -> str: random_generator = random.Random(seed) return "".join(random_generator.sample(letters, 8)) + + +app = typer.Typer() + + +@app.command() +def main() -> None: + typer.echo(generate_password(0)) + + +if __name__ == "__main__": + app() diff --git a/app/main_test.py b/app/main_test.py index 456f952..27696c1 100644 --- a/app/main_test.py +++ b/app/main_test.py @@ -1,6 +1,7 @@ -from app.main import generate_password import pytest +from app.main import generate_password + @pytest.mark.parametrize( ("seed", "expected"), @@ -11,4 +12,3 @@ import pytest ) def test_can_generate_random_password(seed: int, expected: str) -> None: assert generate_password(seed) == expected - \ No newline at end of file