From 28db07d765669e3656baa780731a30d6ab006804 Mon Sep 17 00:00:00 2001 From: Colin Goutte Date: Wed, 23 Aug 2023 16:10:04 +0200 Subject: [PATCH] Implement venv requirement --- .gitignore | 3 +++ Makefile | 6 ++++++ MakefileVenv | 29 +++++++++++++++++++++++++++++ requirements.txt | 1 + requirements_dev.txt | 5 +++++ test_guidelines.py | 38 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 82 insertions(+) create mode 100644 MakefileVenv create mode 100644 requirements.txt create mode 100644 requirements_dev.txt create mode 100644 test_guidelines.py diff --git a/.gitignore b/.gitignore index 8f4dc5c..ea4e3f2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ Pipfile.lock +__pycache__/ +.venv* +*.py[o|c] diff --git a/Makefile b/Makefile index 437ebd5..73fd373 100644 --- a/Makefile +++ b/Makefile @@ -4,3 +4,9 @@ tdd: test: pipenv run pytest $(opt) + +requirements: + pipenv requirements > requirements.txt + pipenv requirements --dev-only > requirements_dev.txt + + diff --git a/MakefileVenv b/MakefileVenv new file mode 100644 index 0000000..47017b8 --- /dev/null +++ b/MakefileVenv @@ -0,0 +1,29 @@ +PY_MINOR=11 +VENV_NAME=.venv_$(PY_MINOR) +VENV=$(CURDIR)/$(VENV_NAME) +python=$(VENV)/bin/python +pip=$(python) -m pip + + +_delete_venv: + ( [ -d $(VENV_NAME) ] && rm -fr $(VENV_NAME) ) || echo "no venv to drop" + + +_create_venv: + python3.$(PY_MINOR) -m venv $(VENV_NAME) + +clean: _delete_venv _create_venv + + +install: + $(python) -m pip install -r requirements.txt + +test: + $(python) -m unittest --discover . + + +run: + $(python) dev.py + + + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e4f81fa --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +-i https://pypi.org/simple diff --git a/requirements_dev.txt b/requirements_dev.txt new file mode 100644 index 0000000..f9e31e3 --- /dev/null +++ b/requirements_dev.txt @@ -0,0 +1,5 @@ +-i https://pypi.org/simple +iniconfig==2.0.0 ; python_version >= '3.7' +packaging==23.1 ; python_version >= '3.7' +pluggy==1.2.0 ; python_version >= '3.7' +pytest==7.4.0 diff --git a/test_guidelines.py b/test_guidelines.py new file mode 100644 index 0000000..aef608a --- /dev/null +++ b/test_guidelines.py @@ -0,0 +1,38 @@ +""" +Testing guidelines and install +""" + +import unittest +from subprocess import run +import pathlib + + +class TestGuidelines(unittest.TestCase): + def test_git(self): + "The poj" + + assert run(["git", "status"], check=True) + + def test_has_requirement(self): + root_dir = run( + ["git", "rev-parse", "--show-toplevel"], capture_output=True, text=True + ).stdout.strip() + target = pathlib.Path(root_dir) / "requirements.txt" + assert target.exists() + + assert target.isFile() + + def test_environment(self): + """We want to make sure that the project is virtualenv compatible. + we may provie and extra makefile for that (and automate build phase) + """ + + venv = "-f", "MakefileVenv" + + for step in ["clean", "install", "test"]: + with self.subTest(setp=step): + try: + run(["make", *venv, step], check=True) + except Exception as E: + print(E.output) + raise