From 008fbfd264d1ab7869f759a1b1aebb95e3095e9d Mon Sep 17 00:00:00 2001 From: Stefan Eiermann Date: Fri, 15 Nov 2024 19:05:16 +0100 Subject: [PATCH 1/8] chore: fix documentation build process; and package build process --- .github/release.bash | 2 +- .github/workflows/docs.yml | 6 ++--- .github/workflows/validate.yml | 16 +++++++++++++ docs/source/_static/.gitkeep | 0 docs/source/conf.py | 3 ++- pyproject.toml | 43 +++++++++++++++++++++++++++++++--- requirements-dev.txt | 14 ----------- requirements.txt | 2 -- setup.cfg | 3 --- setup.py | 22 ----------------- 10 files changed, 62 insertions(+), 49 deletions(-) create mode 100644 docs/source/_static/.gitkeep delete mode 100644 requirements-dev.txt delete mode 100644 requirements.txt delete mode 100644 setup.cfg delete mode 100644 setup.py diff --git a/.github/release.bash b/.github/release.bash index 2d0500d..9d3307c 100755 --- a/.github/release.bash +++ b/.github/release.bash @@ -4,7 +4,7 @@ echo $1 echo $2 echo "Replace Version inside tfutility" -echo "__version__=\"$2\"" > src/tfutility/__init__.py +echo "__version__= \"$2\"" > src/tfutility/__init__.py echo "Replace Docker image Reference inside README.md" sed -i "s/tfutility:$1/tfutility:$1/" README.md diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 1f8fbe0..3af106f 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -21,12 +21,12 @@ jobs: - uses: actions/setup-python@v5 - name: Install dependencies run: | - pip install -r requirements-dev.txt - pip install . + pip3 install -r requirements-dev.txt + pip3 install . - name: Sphinx build run: | cd docs - make html + make html SPHINXOPTS="-W" - name: Deploy to GitHub Pages uses: peaceiris/actions-gh-pages@v3 with: diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 32bdfc4..950ecb4 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -4,6 +4,22 @@ on: [push] jobs: + + docs: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + - name: Install dependencies + run: | + pip3 install -r requirements-dev.txt + pip3 install . + - name: Sphinx build + run: | + cd docs + make html SPHINXOPTS="-W" + + pre-commit: runs-on: ubuntu-latest steps: diff --git a/docs/source/_static/.gitkeep b/docs/source/_static/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/docs/source/conf.py b/docs/source/conf.py index 9b2bc7a..ffba85d 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -6,7 +6,7 @@ # -- Project information ----------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information -project = 'TF-Utils' +project = 'TfUtility' copyright = '2024, Stefan Eiermann' author = 'Stefan Eiermann' @@ -16,6 +16,7 @@ extensions = [ 'sphinxarg.ext', 'sphinx.ext.autodoc', + 'sphinx_toolbox.pre_commit' ] diff --git a/pyproject.toml b/pyproject.toml index c7c34b5..f2b9196 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,19 +9,48 @@ dynamic = ["version"] readme = { file = 'README.md', content-type = 'text/markdown' } license = { file = 'LICENSE' } authors = [{ name = "Stefan Eiermann", email = "stefan.eiermann@eneka.de" }] -dependencies = ["python-hcl2"] +dependencies = [ + "python-hcl2==4.3.5" +] +classifiers = [ + "Development Status :: 4 - Beta", + # Indicate who your project is intended for + "Intended Audience :: Developers", + "Intended Audience :: System Administrators", + "Topic :: Software Development :: Build Tools", + # Pick your license as you wish (see also "license" above) + "License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)", + + # Specify the Python versions you support here + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", +] [tool.setuptools] packages = ["tfutility"] +package-dir = {"" = "src"} [tool.setuptools.dynamic] version = {attr = "tfutility.__version__"} [project.optional-dependencies] -dev = ["pre-commit", "sphinx-autobuild", "coverage", "pytest", "pytest-mock", "pre-commit", "sphinx-argparse"] -docs = ["sphinx", "sphinx-rtd-theme"] +dev = [ + "pytest==8.3.3", + "pytest-mock==3.14.0", + "pytest-cov==6.0.0", + "coverage==7.6.6", + "pre_commit==4.0.1", + "Sphinx==8.1.3", + "sphinx-argparse==0.5.2", + "sphinx-autobuild==2024.10.3", + "sphinx-toolbox==3.8.1", + "sphinx-rtd-theme==3.0.2", + "setuptools>=70.0.0" + ] [tool.black] line-length = 88 @@ -62,3 +91,11 @@ source = ["."] [project.scripts] tfutility = "tfutility.main:main" + + + +[project.urls] +Homepage = "https://github.com/eieste/tfutility/" +Documentation = "https://eieste.github.io/tfutility/" +Repo = "https://github.com/eieste/tfutility" +Issues = "https://github.com/eieste/tfutility/issues" diff --git a/requirements-dev.txt b/requirements-dev.txt deleted file mode 100644 index 609c4f0..0000000 --- a/requirements-dev.txt +++ /dev/null @@ -1,14 +0,0 @@ --r requirements.txt - -pytest -pytest-cov -pytest-mock -coverage -setuptools>=38.6.0 - -sphinx -sphinx-autobuild -pre-commit - -sphinx-argparse -sphinx-rtd-theme diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 43aa492..0000000 --- a/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -python-hcl2==4.3.5 -setuptools==70.0.0 diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 471db9e..0000000 --- a/setup.cfg +++ /dev/null @@ -1,3 +0,0 @@ -[metadata] -name = "tfutility" -version = attr: tfutility.__version__ diff --git a/setup.py b/setup.py deleted file mode 100644 index 2e56fd9..0000000 --- a/setup.py +++ /dev/null @@ -1,22 +0,0 @@ -# -*- coding: utf-8 -*- -from setuptools import find_packages, setup - -f = open("README.md", "r") -LONG_DESCRIPTION = f.read() -f.close() - -setup( - name="tfutility", - description="TfUtility provides different tools for Terraform Developers", - long_description=LONG_DESCRIPTION, - long_description_content_type="text/markdown", - author="Stefan Eiermann", - author_email="foss@ultraapp.de", - url="https://github.com/eieste/tfutility.git", - license="AGPLv3", - packages=find_packages(), - package_dir={"": "src"}, - package_data={"tfutility": ["templates/*"]}, - include_package_data=True, - entry_points={"console_scripts": ["tfutility = tfutility.main:main"]}, -) From 2da5653059ed4064b9209688c887ef2566dae26d Mon Sep 17 00:00:00 2001 From: Stefan Eiermann Date: Fri, 15 Nov 2024 19:19:51 +0100 Subject: [PATCH 2/8] feat: add version command --- src/tfutility/main.py | 7 +++++++ tests/test_cli.py | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 tests/test_cli.py diff --git a/src/tfutility/main.py b/src/tfutility/main.py index e6b0294..b133f46 100644 --- a/src/tfutility/main.py +++ b/src/tfutility/main.py @@ -4,8 +4,10 @@ import argparse import logging +import sys from collections import namedtuple +import tfutility from tfutility.controllers.blockdate import ImportDateHandler, MovedDateHandler from tfutility.controllers.forcedremotesource import ForcedRemoteSourceHandler from tfutility.controllers.sourceswap import SourceSwapHandler @@ -64,6 +66,7 @@ def add_arguments(self, parser: argparse.ArgumentParser) -> argparse.ArgumentPar :return: the main argparser with attached global arguments """ parser.add_argument("--verbose", "-v", action="count", default=1) + parser.add_argument("-V", "--version", action="store_true") return parser def _handle(self, options: argparse.Namespace): @@ -82,6 +85,10 @@ def _handle(self, options: argparse.Namespace): datefmt="%Y-%m-%d %H:%M:%S", ) + if options.version: + print(tfutility.__version__) + sys.exit(0) + # find command which is used by user for name, handler in self.commands.items(): if handler.handler_obj.itsme(options): diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 0000000..b321399 --- /dev/null +++ b/tests/test_cli.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +import re + +from tfutility.main import main + +VESION_REGEX = re.compile(r"^(\d+\.)?(\d+\.)?(\*|\d+)$") + + +def test_empty(capsys, mocker): + mocker.patch("sys.argv", ["tfutility"]) + tfdo = mocker.patch("tfutility.main.TfUtility.do") + main() + captured = capsys.readouterr() + assert captured.out == "" + assert tfdo.call_count == 1 + + +def test_version(capsys, mocker): + mocker.patch("sys.argv", ["tfutility", "-V"]) + sysexit = mocker.patch("sys.exit") + main() + captured = capsys.readouterr() + assert VESION_REGEX.match(captured.out) is not None + assert sysexit.call_count == 1 From 1cf08d020e5bdf0e43e2dde9f84ccc5976c95f79 Mon Sep 17 00:00:00 2001 From: Stefan Eiermann Date: Fri, 15 Nov 2024 19:24:35 +0100 Subject: [PATCH 3/8] fix: Buildprocess --- .github/workflows/docs.yml | 2 +- .github/workflows/validate.yml | 10 ++++++---- Dockerfile | 3 +-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 3af106f..f98db38 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -21,7 +21,7 @@ jobs: - uses: actions/setup-python@v5 - name: Install dependencies run: | - pip3 install -r requirements-dev.txt + pip3 install .[dev] pip3 install . - name: Sphinx build run: | diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 950ecb4..88819d9 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -12,8 +12,9 @@ jobs: - uses: actions/setup-python@v5 - name: Install dependencies run: | - pip3 install -r requirements-dev.txt + pip3 install .[dev] pip3 install . + - name: Sphinx build run: | cd docs @@ -56,8 +57,8 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install -r requirements-dev.txt - pip install -e . + pip3 install .[dev] + pip3 install . - name: Test with pytest run: | pip install pytest pytest-cov @@ -82,5 +83,6 @@ jobs: # You can test your matrix by printing the current Python version - name: Test Install run: | - pip3 install .; + pip3 install .[dev] + pip3 install . tfutility --help \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index f600f2c..4c6f954 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,6 @@ ENV PS1="\[\e[0;33m\]|> tfutility <| \[\e[1;35m\]\W\[\e[0m\] \[\e[0m\]# " WORKDIR /src COPY . /src -RUN pip install --no-cache-dir -r requirements.txt \ - && python setup.py install +RUN pip install --no-cache-dir . WORKDIR / ENTRYPOINT ["tfutility"] From befba5e80cf202936e49fe697356cdcf322a53a1 Mon Sep 17 00:00:00 2001 From: Stefan Eiermann Date: Fri, 15 Nov 2024 19:26:59 +0100 Subject: [PATCH 4/8] fix: requirements --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index f2b9196..1e5c420 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,7 +44,7 @@ dev = [ "pytest-cov==6.0.0", "coverage==7.6.6", "pre_commit==4.0.1", - "Sphinx==8.1.3", + "sphinx==8.1.3", "sphinx-argparse==0.5.2", "sphinx-autobuild==2024.10.3", "sphinx-toolbox==3.8.1", From d90abecc80ab0b5a6b02b8a631f6e368648e88b4 Mon Sep 17 00:00:00 2001 From: Stefan Eiermann Date: Fri, 15 Nov 2024 19:48:20 +0100 Subject: [PATCH 5/8] fix: requirements --- .github/workflows/validate.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 88819d9..a5dec5f 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -14,7 +14,6 @@ jobs: run: | pip3 install .[dev] pip3 install . - - name: Sphinx build run: | cd docs From 45bc00e138eda21dda3a1acf0bc18c32c583b8d5 Mon Sep 17 00:00:00 2001 From: Stefan Eiermann Date: Fri, 15 Nov 2024 19:55:05 +0100 Subject: [PATCH 6/8] fix: requirements --- .github/workflows/validate.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index a5dec5f..5d6c4be 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -17,6 +17,7 @@ jobs: - name: Sphinx build run: | cd docs + sphinx-build --version make html SPHINXOPTS="-W" From fa6d70aeaa063bb6a0c2fe6cde8f15b8cfc87fba Mon Sep 17 00:00:00 2001 From: Stefan Eiermann Date: Fri, 15 Nov 2024 21:03:24 +0100 Subject: [PATCH 7/8] fix: installation of packages in workflows --- .github/workflows/docs.yml | 2 +- .github/workflows/validate.yml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index f98db38..9d563fd 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -21,7 +21,7 @@ jobs: - uses: actions/setup-python@v5 - name: Install dependencies run: | - pip3 install .[dev] + pip3 install '.[dev]' pip3 install . - name: Sphinx build run: | diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 5d6c4be..4d1b840 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -12,7 +12,7 @@ jobs: - uses: actions/setup-python@v5 - name: Install dependencies run: | - pip3 install .[dev] + pip3 install '.[dev]' pip3 install . - name: Sphinx build run: | @@ -57,7 +57,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip3 install .[dev] + pip3 install '.[dev]' pip3 install . - name: Test with pytest run: | @@ -83,6 +83,6 @@ jobs: # You can test your matrix by printing the current Python version - name: Test Install run: | - pip3 install .[dev] + pip3 install '.[dev]' pip3 install . tfutility --help \ No newline at end of file From c853f5e4e871c8fa51d4409b6e5e18df29a97325 Mon Sep 17 00:00:00 2001 From: Stefan Eiermann Date: Fri, 15 Nov 2024 22:05:10 +0100 Subject: [PATCH 8/8] cicd: Upgrade pip before installing --- .github/workflows/validate.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 4d1b840..f3ca5d6 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -12,6 +12,7 @@ jobs: - uses: actions/setup-python@v5 - name: Install dependencies run: | + python -m pip install --upgrade pip pip3 install '.[dev]' pip3 install . - name: Sphinx build