Skip to content

Commit

Permalink
v1.0.0: separate package from python-dev-utils (refactor).
Browse files Browse the repository at this point in the history
  • Loading branch information
ALittleMoron committed Aug 5, 2024
1 parent 78b8d3f commit 52b36bc
Show file tree
Hide file tree
Showing 41 changed files with 3,602 additions and 2 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Tests And Linting

on:
pull_request:
push:

jobs:
test:
name: "Test (${{ matrix.python-version }}"
strategy:
fail-fast: true
matrix:
python-version: ["3.11"]
uses: ./.github/workflows/test.yaml
with:
coverage: true
python-version: ${{ matrix.python-version }}
41 changes: 41 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Python package

on:
workflow_call:
inputs:
python-version:
required: true
type: string
os:
required: false
type: string
default: "ubuntu-latest"
timeout:
required: false
type: number
default: 60


jobs:
lint:
timeout-minutes: ${{ inputs.timeout }}
runs-on: ${{ inputs.os }}
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ inputs.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python-version }}
- name: Set up PDM
uses: pdm-project/setup-pdm@v3
with:
python-version: ${{ inputs.python-version }}
- uses: actions/cache@v3
name: Define a cache for the virtual environment based on the dependencies lock file
with:
path: ./.venv
key: venv-${{ hashFiles('pdm.lock') }}
- name: Install the project dependencies
run: make install
- name: Run linting
run: make lint
87 changes: 87 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Python package

on:
workflow_call:
inputs:
python-version:
required: true
type: string
poetry-version:
required: false
type: string
default: "1.8"
coverage:
required: false
type: boolean
default: false
os:
required: false
type: string
default: "ubuntu-latest"
timeout:
required: false
type: number
default: 60


jobs:
test:
timeout-minutes: ${{ inputs.timeout }}
runs-on: ${{ inputs.os }}
defaults:
run:
shell: bash
services:
postgres:
image: postgres
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: test_db
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ inputs.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python-version }}
- name: Set up PDM
uses: pdm-project/setup-pdm@v3
with:
python-version: ${{ inputs.python-version }}
- uses: actions/cache@v3
name: Define a cache for the virtual environment based on the dependencies lock file
with:
path: ./.venv
key: venv-${{ hashFiles('pdm.lock') }}
- name: Install the project dependencies
run: make install
- name: Run the automated tests with coverage
if: ${{ inputs.coverage }}
run: make test
- name: Coverage Badge
uses: tj-actions/coverage-badge-py@v2
- name: Verify Changed files
uses: tj-actions/verify-changed-files@v16
id: verify-changed-files
with:
files: coverage.svg
- name: Commit files
if: steps.verify-changed-files.outputs.files_changed == 'true'
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add coverage.svg
git commit -m "Updated coverage.svg"
- name: Push changes
if: steps.verify-changed-files.outputs.files_changed == 'true'
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.github_token }}
branch: ${{ github.ref }}
167 changes: 167 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm-python
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/


# VSCode
.vscode
test.db
report.txt
58 changes: 58 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
NAME := sqlalchemy_dev_utils
PDM := $(shell command -v pdm 2> /dev/null)

.DEFAULT_GOAL := help

.PHONY: help
help:
@echo -e "Please, use \033[0;33m'make <target>'\033[0m where <target> is one the following commands:"
@echo ""
@echo -e " \033[0;33minstall\033[0m run installation for all dependencies"
@echo -e " \033[0;33mshell\033[0m run ipython shell"
@echo -e " \033[0;33mclean\033[0m run delete all not needed files"
@echo -e " \033[0;33mlint\033[0m run project code checking without formatting"
@echo -e " \033[0;33mformat\033[0m run project code formatting"
@echo -e " \033[0;33mtest\033[0m run all tests"
@echo -e " \033[0;33mtest_docker\033[0m run all tests in docker"

@echo ""
@echo -e "Check \033[0;33mMakefile\033[0m to get full context of commands."


.PHONY: install
install:
@if [ -z $(PDM) ]; then echo "PDM could not be found."; exit 2; fi
$(PDM) install -G:all --no-self


.PHONY: shell
shell:
@if [ -z $(PDM) ]; then echo "Poetry could not be found. See https://python-poetry.org/docs/"; exit 2; fi
$(ENV_VARS_PREFIX) $(PDM) run ipython --no-confirm-exit --no-banner --quick \
--InteractiveShellApp.extensions="autoreload" \
--InteractiveShellApp.exec_lines="%autoreload 2"

.PHONY: clean
clean:
find . -type d -name "__pycache__" | xargs rm -rf {};

.PHONY: lint
lint:
@if [ -z $(PDM) ]; then echo "Poetry could not be found. See https://python-poetry.org/docs/"; exit 2; fi
$(PDM) run pyright $(NAME)
$(PDM) run isort --settings-path ./pyproject.toml --check-only $(NAME)
$(PDM) run black --config ./pyproject.toml --check $(NAME) --diff
$(PDM) run ruff check $(NAME)
$(PDM) run vulture $(NAME) --min-confidence 100 --exclude "migration_numbering.py"
$(PDM) run bandit --configfile ./pyproject.toml -r ./$(NAME)

.PHONY: format
format:
@if [ -z $(PDM) ]; then echo "Poetry could not be found. See https://python-poetry.org/docs/"; exit 2; fi
$(PDM) run isort --settings-path ./pyproject.toml $(NAME)
$(PDM) run black --config ./pyproject.toml $(NAME)

.PHONY: test
test:
@if [ -z $(PDM) ]; then echo "Poetry could not be found. See https://python-poetry.org/docs/"; exit 2; fi
$(PDM) run pytest ./tests --cov-report xml --cov-fail-under 95 --cov ./$(NAME) -vv
Loading

0 comments on commit 52b36bc

Please sign in to comment.