From fe1a257f62f665ec52b41c27f85b29f4522a719f Mon Sep 17 00:00:00 2001 From: Julian Vanden Broeck Date: Fri, 3 May 2024 13:38:51 +0200 Subject: [PATCH] Add python packaging --- Dockerfile | 8 ++-- pyproject.toml | 43 +++++++++++++++++++ src/ansible_collection_helper/__init__.py | 0 .../ansible_collection_helper/helper.py | 10 ++++- .../templates}/readme.jinja2 | 0 5 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 pyproject.toml create mode 100644 src/ansible_collection_helper/__init__.py rename ansible_collection_helper.py => src/ansible_collection_helper/helper.py (96%) rename {templates => src/ansible_collection_helper/templates}/readme.jinja2 (100%) diff --git a/Dockerfile b/Dockerfile index 9538342..4d7f302 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,8 +6,6 @@ RUN apk add --no-cache python3 python3-dev py3-pip gcc jq \ RUN python3 -m venv --upgrade-deps /opt/venv -COPY requirements.txt /opt -COPY ansible_collection_helper.py /opt/ -COPY templates /opt/templates/ - -RUN /opt/venv/bin/pip install -r /opt/requirements.txt +COPY . /usr/local/src/ansible_collection_helper +RUN /opt/venv/bin/pip install --no-cache-dir /usr/local/src/ansible_collection_helper &&\ + rm -rf /usr/local/src/ansible_collection_helper diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..6097cae --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,43 @@ +# SPDX-FileCopyrightText: 2024 Dalibo +# +# SPDX-License-Identifier: GPL-3.0-or-later +[build-system] +requires = ["setuptools >= 61.0", "setuptools-scm>=8"] +build-backend = "setuptools.build_meta" + +[project] +name = "ansible_collection_helper" +description = "Helper to manage Ansible collection" +readme = "README.md" +requires-python = ">=3.11, <4" +license = { text = "GPLv3" } +authors = [{ name = "Dalibo SCOP", email = "contact@dalibo.com" }] +keywords = [ + "ansible", + "command-line", +] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Environment :: Console", + "Intended Audience :: Developers", + "Intended Audience :: System Administrators", + "Topic :: System :: Systems Administration", + "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3 :: Only", +] +dynamic = ["version", "dependencies"] + +[tool.setuptools.dynamic] +dependencies = {file = ["requirements.txt"]} + +[project.urls] +Source = "https://github.com/dalibo/docker-dind-molecule/" +Tracker = "https://github.com/dalibo/docker-dind-molecule/" + + +[project.scripts] +ansible_collection_helper = "ansible_collection_helper:helper.main" + +[tool.setuptools_scm] diff --git a/src/ansible_collection_helper/__init__.py b/src/ansible_collection_helper/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/ansible_collection_helper.py b/src/ansible_collection_helper/helper.py similarity index 96% rename from ansible_collection_helper.py rename to src/ansible_collection_helper/helper.py index 783e352..63e219d 100644 --- a/ansible_collection_helper.py +++ b/src/ansible_collection_helper/helper.py @@ -9,9 +9,15 @@ import yaml from ansible.cli.doc import DocCLI -from jinja2 import Environment, FileSystemLoader +from jinja2 import Environment, PackageLoader -env = Environment(loader=FileSystemLoader((Path(__file__).parent / "templates"))) +from . import __name__ as pkgname + +env = Environment( + loader=PackageLoader(package_name=pkgname, package_path="templates"), + trim_blocks=True, + lstrip_blocks=True, +) template = env.get_template("readme.jinja2") diff --git a/templates/readme.jinja2 b/src/ansible_collection_helper/templates/readme.jinja2 similarity index 100% rename from templates/readme.jinja2 rename to src/ansible_collection_helper/templates/readme.jinja2