Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial concept #1

Merged
merged 10 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---

name: Pytest tests

on:
- pull_request
- push

# permission can be added at job level or workflow level
permissions:
id-token: write # This is required for requesting the JWT
contents: write # This is required for actions/checkout
pull-requests: write

env:
VERBOSITY: 4

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
pytest:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./
steps:
- uses: actions/checkout@master

- uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: make
version: 1.0

- uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: pip

- name: Restore cached virtualenv
uses: actions/cache/restore@v4
with:
key: venv-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ hashFiles('requirements.txt') }}
path: venv

- name: Install dependencies
run: |
make init
echo "$VIRTUAL_ENV/bin" >> $GITHUB_PATH
echo "VIRTUAL_ENV=$VIRTUAL_ENV" >> $GITHUB_ENV

- name: Run tests
run: |
DEBUG=1 make test

- name: Saved cached virtualenv
if: always()
uses: actions/cache/save@v4
with:
key: venv-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ hashFiles('requirements.txt') }}
path: venv

# https://adamj.eu/tech/2023/11/02/github-actions-faster-python-virtual-environments/
67 changes: 67 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/make -f console

MAKEFILE := $(realpath $(lastword $(MAKEFILE_LIST)))
MAKE := make
MAKEFLAGS += --no-print-directory
MAKEFLAGS += --warn-undefined-variables

.ONESHELL:
SHELL := /bin/bash
.SHELLFLAGS := -o errexit -o nounset -o pipefail -u -ec

PATH := $(PWD)/bin:$(PWD)/venv/bin:$(HOME)/go/bin:$(PATH)
PYTHONPATH := $(PWD)/venv

APT_INSTALL := sudo apt install -yyq --no-install-recommends --no-install-suggests

SYSTEM_PIP := pip3
PYTHON := $(PWD)/venv/bin/python3
PYTEST := $(PWD)/venv/bin/pytest
COVERAGE := $(PWD)/venv/bin/coverage
FLAKE8 := $(PWD)/venv/bin/flake8
BLACK := $(PWD)/venv/bin/flake8
PIP3 := $(PWD)/venv/bin/pip3
YQ := $(PWD)/venv/bin/yq -y
PIPREQS := $(PWD)/venv/bin/pipreqs
BLACK := $(PWD)/venv/bin/black

num_cpus = $(shell lscpu | awk '/^CPU.s/{ print $$2 }')

DEBUG ?= 0
ifeq ($(DEBUG), 1)
PYTESTFLAGS =-rA --log-cli-level=DEBUG
VERBOSITY=5
else
PYTESTFLAGS =--log-cli-level=CRITICAL
VERBOSITY=0
endif

.PHONY: init test requirements venv

init: venv dev requirements
source venv/bin/activate
poetry env info

lint:
poetry run black -q --check --exclude venv/ --color --diff .

test:
VERBOSE=$(VERBOSITY) $(PYTEST) -n $(num_cpus) $(PYTESTFLAGS) -vvvv tests/
# VERBOSE=$(VERBOSITY) $(PYTEST) -n $(num_cpus) $(PYTESTFLAGS) -rA -vvvv tests/ \
# --log-format="%(asctime)s %(levelname)s %(message)s" \
# --log-date-format="%Y-%m-%d %H:%M:%S" \
# --show-capture=all

venv:
pip3 install -U pip --break-system-packages
# --show-capture=all
python3 -mvenv venv/

requirements:
source venv/bin/activate
poetry install

dev:
source venv/bin/activate
$(PIP3) install poetry setuptools wheel pip
poetry check
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# Terrapyne

Python wrapper around terraform and similar

```python
import terrapyne
tf = terrapyne.Terraform()
tf.apply()
outputs = tf.output()
```
1,525 changes: 1,525 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

89 changes: 89 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
[tool.poetry]
name = "terrapyne"
version = "0.0.1"
description = "Wrapper around terraform"
authors = []
license = "Apache License Version 2.0"
readme = "README.md"
homepage = "https://github.com/shalomb/terrapyne"
keywords = ["terraform", "wrapper"]

# For reference, see https://pypi.org/pypi?%3Aaction=list_classifiers
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Intended Audience :: Information Technology",
"Intended Audience :: System Administrators",
"License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: System :: Systems Administration",
"Topic :: Utilities",
]

[tool.poetry.dependencies]
python = ">=3.11.1,<4.0"
colorlog = ">=5.0.1,<7.0.0"
jinja2 = "^3.0.1"
pretty_traceback = "*"
python-decouple = "^3.8"
python-benedict = {extras = ["all"], version = "^0.33.2"}

[tool.poetry.group.test.dependencies]
black = "*"
coverage = "*"
flake8 = ">=6.0.0"
flake8-docstrings = "*"
flake8-pyproject = "*"
md-toc = "*"
mock = "*"
pook = ">=1.0.2"
pre-commit = "*"
pytest = "*"
pytest-mock = "*"
requests-mock = "*"
toml = "*"
tox = ">=4"


[tool.poetry.group.dev.dependencies]
pytest-xdist = "^3.6.1"

[tool.poetry.scripts]
tfwrapper = 'terrapyne:main'

[build-system]
requires = ["poetry-core>=1.1.0"]
build-backend = "poetry.core.masonry.api"

[tool.pytest.ini_options]
log_cli = true
log_cli_level = "INFO"
log_cli_format = "%(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s)"
log_cli_date_format = "%Y-%m-%d %H:%M:%S"

[tool.black]
# Make sure to match flake8's max-line-length.
line-length = 130 # black's default
target-version = ['py38', 'py39', 'py310', 'py311', 'py312']
exclude = '''
/(
\.git
| \.pytest_cache
| \.tox
| \.venv
)/
'''

[tool.flake8]
verbose = 3
max-line-length = 130
per-file-ignores = ['tests/*.py:D103']
exclude = ['.git', '.tox', '.venv', '.virtualenv', '__pycache__']
# See https://black.readthedocs.io/en/stable/faq.html#why-are-flake8-s-e203-and-w503-violated
ignore = ['E203', 'W503']
enable-extensions = ['W504']
Empty file removed requirements.txt
Empty file.
2 changes: 2 additions & 0 deletions src/terrapyne/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .terrapyne import Terraform
from . import logging
23 changes: 23 additions & 0 deletions src/terrapyne/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env python3

# -*- coding: utf-8 -*-

""" """


class TerraformException(Exception):
pass


class TerraformVersionException(TerraformException):
pass


class TerraformApplyException(TerraformException):
def __init__(self, message, exit_code, expect_exit_code, stdout, stderr, pwd):
self.message = message
self.exit_code = exit_code
self.expect_exit_code = expect_exit_code
self.stdout = stdout
self.stderr = stderr
self.pwd = pwd
Loading
Loading