From e8f2142eddc4e7013171e3e6dad17f61df2e37bc Mon Sep 17 00:00:00 2001 From: Jan Snasel Date: Mon, 16 Oct 2023 10:45:21 +0200 Subject: [PATCH] Remove 3rd party dependencies from invoke (#26) --- .github/workflows/check-pr-qa.yaml | 3 +- development/default.env | 47 ------------------------------ poetry.lock | 27 +---------------- pyproject.toml | 2 -- tasks.py | 19 ++++-------- 5 files changed, 8 insertions(+), 90 deletions(-) delete mode 100644 development/default.env diff --git a/.github/workflows/check-pr-qa.yaml b/.github/workflows/check-pr-qa.yaml index 721a7b0..13a225f 100644 --- a/.github/workflows/check-pr-qa.yaml +++ b/.github/workflows/check-pr-qa.yaml @@ -13,6 +13,8 @@ jobs: qa: runs-on: "ubuntu-22.04" env: + COMPOSE_FILE: "development/compose.yaml" + FROM_IMAGE: "python:3.11-slim" IMAGE_PREFIX: "ghcr.io/${{ github.repository }}" IMAGE_TAG: "${{ github.sha }}" TARGET_WORKDIR: "/${{ github.repository }}" @@ -22,7 +24,6 @@ jobs: - name: "QA" run: | docker compose \ - --env-file=development/default.env \ up \ --exit-code-from=qa \ --no-color \ diff --git a/development/default.env b/development/default.env deleted file mode 100644 index c10c41c..0000000 --- a/development/default.env +++ /dev/null @@ -1,47 +0,0 @@ -# Default environment variables for the development -# -# WARNING: Do not change this file, to customize variables. Instead create `.env` file in the project root, and define -# necessary variables there. -# -# Environment variables order of precedence: -# -# 1. Environment variables from shell -# 2. `.creds.env` file -# 3. `.env` file -# 4. `development/default.env` (this) file -# 5. `tasks.py` -# -# Credentials: -# -# - DO NOT ADD credentials to this OR `.env` file. -# - To specify credentials for the development, it's always better to use temporary environment variables directly -# defined in the shell. -# -# If necessary, create `.creds.env` file in the project root, and define credentials there, `tasks.py` loads this file -# automatically. -# -# BEWARE: -# -# - Use `.creds.env` only for the local development, do not commit it to git. -# - Do not expose `.creds.env` to the editors whispering tools or other ways. -# - Remove `.creds.env` file after finishing the development. - -# Default values: -COMPOSE_FILE="development/compose.yaml" -FROM_IMAGE="python:3.11-slim" -IMAGE_TAG="latest" - -# Other variables, mostly set up by invoke `tasks.py`: -# COMPOSE_PROJECT_NAME="" -# IMAGE_PREFIX="" -# INVOKE_DEFAULT_EXEC=False -# INVOKE_DEFAULT_SERVICE="dev" -# INVOKE_DRY=False -# INVOKE_ECHO=True -# INVOKE_LOCAL=False -# PACKAGE_NAME="" -# PACKAGE_SLUG="" -# PACKAGE_VERSION="" -# TARGET_WORKDIR="" -# USER_NAME="" -# USER_UID= diff --git a/poetry.lock b/poetry.lock index e8d59bb..c92890c 100644 --- a/poetry.lock +++ b/poetry.lock @@ -712,20 +712,6 @@ files = [ [package.dependencies] six = ">=1.5" -[[package]] -name = "python-dotenv" -version = "1.0.0" -description = "Read key-value pairs from a .env file and set them as environment variables" -optional = false -python-versions = ">=3.8" -files = [ - {file = "python-dotenv-1.0.0.tar.gz", hash = "sha256:a8df96034aae6d2d50a4ebe8216326c61c3eb64836776504fcca410e5937a3ba"}, - {file = "python_dotenv-1.0.0-py3-none-any.whl", hash = "sha256:f5971a9226b701070a4bf2c38c89e5a3f0d64de8debda981d1db98583009122a"}, -] - -[package.extras] -cli = ["click (>=5.0)"] - [[package]] name = "python-slugify" version = "8.0.1" @@ -905,17 +891,6 @@ files = [ {file = "text_unidecode-1.3-py2.py3-none-any.whl", hash = "sha256:1311f10e8b895935241623731c2ba64f4c455287888b18189350b67134a822e8"}, ] -[[package]] -name = "toml" -version = "0.10.2" -description = "Python Library for Tom's Obvious, Minimal Language" -optional = false -python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*" -files = [ - {file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"}, - {file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"}, -] - [[package]] name = "tomli" version = "2.0.1" @@ -1071,4 +1046,4 @@ dev = ["doc8", "flake8", "flake8-import-order", "rstcheck[sphinx]", "sphinx"] [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "c36eb72d57e917143cce4dcf55bb7b0b4bfd24eccb0fdc4548061f7f3ab3fdde" +content-hash = "061386bb7b2c34c852255c1d22e19551e14f5100066927a6d66c2585ba45f3e4" diff --git a/pyproject.toml b/pyproject.toml index c26cb39..6d1313a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,9 +23,7 @@ isort = "*" pylint = "*" pytest = "*" pytest-cookies = "*" -python-dotenv = "*" ruff = "*" -toml = "*" yamllint = "*" [tool.black] diff --git a/tasks.py b/tasks.py index 744ec76..2e3dbc8 100644 --- a/tasks.py +++ b/tasks.py @@ -21,8 +21,6 @@ from pwd import getpwuid from typing import Generator -import toml -from dotenv import load_dotenv from invoke.collection import Collection from invoke.tasks import task @@ -34,28 +32,21 @@ def _jsontobool(value: str) -> bool: def _setup_env(): - load_dotenv(_PATH / ".creds.env", verbose=True) - load_dotenv(_PATH / ".env", verbose=True) - load_dotenv(_PATH / "development/default.env", verbose=True) - def setenv(key, value): if key not in environ: environ[key] = str(value) - setenv("REPOSITORY_DIR", _PATH.absolute()) setenv("TARGET_WORKDIR", _PATH) uid = getuid() setenv("USER_UID", uid) setenv("USER_NAME", getpwuid(uid).pw_name) - pyproject = toml.load(_PATH / "pyproject.toml") - setenv("PACKAGE_SLUG", pyproject["tool"]["poetry"]["name"]) - setenv("PACKAGE_NAME", pyproject["tool"]["poetry"]["name"].replace("-", "_")) - setenv("PACKAGE_VERSION", pyproject["tool"]["poetry"]["version"]) - - setenv("COMPOSE_PROJECT_NAME", environ["PACKAGE_SLUG"]) + setenv("COMPOSE_FILE", "development/compose.yaml") + setenv("COMPOSE_PROJECT_NAME", "cookiecutter-nautobot-app") + setenv("FROM_IMAGE", "python:3.11-slim") setenv("IMAGE_PREFIX", f"localhost/{environ['COMPOSE_PROJECT_NAME']}") + setenv("IMAGE_TAG", "latest") _setup_env() @@ -137,7 +128,7 @@ def build_task(context, service="", cache=True, force_rm=False, pull=False): "template": "Name of the cookiecutter template to test", } ) -def test_template(context, template): +def test_template(context, template=""): """Test a specific cookiecutter template.""" test_dir = _PATH / template / "tests" if not test_dir.exists():