1
0
Fork 0

Modernizing PyThon Projec

This commit is contained in:
Joao Gilberto Magalhaes 2026-01-22 20:14:22 -05:00
parent b8848c8303
commit 55d0d1a105
51 changed files with 157 additions and 47 deletions

View file

@ -26,15 +26,16 @@ jobs:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Install requirements - name: Install uv
run: curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Install dependencies
run: | run: |
cd src/ export PATH="$HOME/.local/bin:$PATH"
pip install -r requirements.txt uv pip install --system -e ".[dev]"
- name: Run tests - name: Run tests
run: | run: pytest -s tests/ -vv
cd src/
pytest -s tests/ -vv
Build: Build:
runs-on: ubuntu-latest runs-on: ubuntu-latest

10
.gitignore vendored
View file

@ -6,6 +6,16 @@ __pycache__
.pytest_cache .pytest_cache
*.pyc *.pyc
.env .env
# uv
uv.lock
.venv/
# Build artifacts
dist/
build/
*.egg-info/
/examples/static/conf/config.yml /examples/static/conf/config.yml
/examples/docker/certs/haproxy/.place_holder_cert.pem /examples/docker/certs/haproxy/.place_holder_cert.pem
/examples/static/host1.local.pem /examples/static/host1.local.pem

1
.python-version Normal file
View file

@ -0,0 +1 @@
3.12

View file

@ -6,4 +6,16 @@ build:
.PHONY: test .PHONY: test
test: test:
cd src/ && pytest tests/ -vv uv run pytest tests/ -vv
.PHONY: sync
sync:
uv sync --dev
.PHONY: lint
lint:
uv run ruff check src/ tests/
.PHONY: format
format:
uv run ruff format src/ tests/

View file

@ -100,6 +100,47 @@ Detailed configuration guides for advanced setups:
- [Other Configurations](docs/other.md) - Additional configurations (ports, custom errors, etc.) - [Other Configurations](docs/other.md) - Additional configurations (ports, custom errors, etc.)
- [Limitations](docs/limitations.md) - Important limitations and considerations - [Limitations](docs/limitations.md) - Important limitations and considerations
## Development
### Requirements
- Python 3.11 or higher
- [uv](https://github.com/astral-sh/uv) package manager
### Installation for Development
```bash
# Install uv (if not already installed)
curl -LsSf https://astral.sh/uv/install.sh | sh
# Clone the repository
git clone https://github.com/byjg/docker-easy-haproxy.git
cd docker-easy-haproxy
# Install dependencies (creates virtual environment automatically)
uv sync --dev
# Run tests
make test
# or directly: uv run pytest tests/ -vv
# Run linting
make lint
# Format code
make format
```
### Installing the Package
```bash
# Install with uv
uv pip install easymapping
# Or install from source
uv pip install -e ".[dev]"
```
## See EasyHAProxy in action ## See EasyHAProxy in action
Click on the image to see the videos (use HD for better visualization) Click on the image to see the videos (use HD for better visualization)

View file

@ -5,9 +5,11 @@ ARG RELEASE_VERSION_ARG
ENV RELEASE_VERSION=$RELEASE_VERSION_ARG ENV RELEASE_VERSION=$RELEASE_VERSION_ARG
ENV TZ="Etc/UTC" ENV TZ="Etc/UTC"
RUN apk add --no-cache haproxy bash python3 py3-pip py-yaml certbot openssl \ RUN apk add --no-cache haproxy bash python3 py3-pip py-yaml certbot openssl curl \
&& apk add --no-cache --virtual .build-deps build-base python3-dev musl-dev linux-headers \ && apk add --no-cache --virtual .build-deps build-base python3-dev musl-dev linux-headers \
&& pip3 install --upgrade pip --break-system-packages && pip3 install --upgrade pip --break-system-packages \
&& curl -LsSf https://astral.sh/uv/install.sh | sh \
&& ln -s /root/.local/bin/uv /usr/local/bin/uv
RUN openssl dhparam -out /etc/haproxy/dhparam 2048 \ RUN openssl dhparam -out /etc/haproxy/dhparam 2048 \
&& openssl dhparam -out /etc/haproxy/dhparam-1024 1024 && openssl dhparam -out /etc/haproxy/dhparam-1024 1024
@ -16,12 +18,14 @@ WORKDIR /scripts
COPY build/assets / COPY build/assets /
COPY pyproject.toml LICENSE README.md /scripts/
COPY src/ /scripts/ COPY src/ /scripts/
COPY tests/ /scripts/tests/
RUN pip install -r requirements.txt --break-system-packages RUN cd /scripts && uv pip install --python /usr/bin/python3 --break-system-packages ".[dev]"
RUN apk del .build-deps RUN apk del .build-deps
RUN pytest -s -vv tests/ RUN cd /scripts && pytest -s -vv tests/
CMD ["/usr/bin/python", "-u", "/scripts/main.py" ] CMD ["/usr/bin/python", "-u", "/scripts/main.py" ]

77
pyproject.toml Normal file
View file

@ -0,0 +1,77 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = "easymapping"
version = "5.0.0"
description = "HAProxy label based routing with service discovery for Docker, Swarm, and Kubernetes"
readme = "README.md"
license = {file = "LICENSE"}
requires-python = ">=3.11"
authors = []
keywords = ["haproxy", "docker", "kubernetes", "service-discovery", "load-balancer"]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Intended Audience :: System Administrators",
"Topic :: System :: Systems Administration",
"Topic :: Internet :: Proxy Servers",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
]
dependencies = [
"pyyaml>=6.0",
"docker>=7.0.0",
"jinja2>=3.1.0",
"kubernetes>=28.0.0",
"deepdiff>=6.0.0",
"pyopenssl>=24.0.0",
"psutil>=5.9.0",
"requests>=2.31.0",
]
[dependency-groups]
dev = [
"pytest>=8.0.0",
"pytest-cov>=4.1.0",
"ruff>=0.1.0",
]
[project.scripts]
easy-haproxy = "main:main"
[tool.hatch.build.targets.wheel]
packages = ["src/easymapping", "src/functions", "src/processor", "src/plugins", "src/templates"]
[tool.hatch.build.targets.wheel.sources]
"src" = ""
[tool.pytest.ini_options]
addopts = "-v -p no:warnings"
testpaths = ["tests"]
pythonpath = ["src"]
[tool.ruff]
line-length = 120
target-version = "py311"
[tool.ruff.lint]
select = ["E", "F", "W", "I", "N", "UP"]
ignore = ["E501"]
[tool.coverage.run]
source = ["src"]
omit = ["*/tests/*", "*/test_*.py"]
[tool.coverage.report]
exclude_lines = [
"pragma: no cover",
"def __repr__",
"raise AssertionError",
"raise NotImplementedError",
"if __name__ == .__main__.:",
]

View file

@ -1,20 +0,0 @@
from setuptools import setup, find_packages
with open('README.md') as f:
readme = f.read()
with open('LICENSE') as f:
license = f.read()
setup(
name='easymapping',
version='0.1.0',
description='HAProxy label based routing',
long_description=readme,
author='',
author_email='',
url='',
license=license,
packages=find_packages(exclude=('tests', 'docs'))
)

View file

@ -1,2 +0,0 @@
[pytest]
addopts = -v -p no:warnings

View file

@ -1,9 +0,0 @@
pyyaml
docker
jinja2
pytest
docker
kubernetes
deepdiff
pyopenssl
psutil

View file

@ -1,5 +0,0 @@
import os
import sys
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))