Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dobizz authored Oct 31, 2023
0 parents commit f5cfad8
Show file tree
Hide file tree
Showing 19 changed files with 403 additions and 0 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python application

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
python-version:
- '3.8'
- '3.9'
- '3.10'
- '3.11'

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest coverage
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Install project
run: |
pip install -e .
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
coverage run -m pytest
- name: Show test coverage
run: |
coverage report -mi --fail-under=80
160 changes: 160 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# 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.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/
35 changes: 35 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-yaml
- id: check-toml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-docstring-first
- id: debug-statements
- id: requirements-txt-fixer
- id: name-tests-test
- repo: https://github.com/psf/black
rev: 23.9.1
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
name: isort (python)
args: ["--profile", "black"]
- repo: https://github.com/pycqa/flake8
rev: 5.0.4
hooks:
- id: flake8
args: [--max-line-length=79]
additional_dependencies: [flake8-isort]
- repo: https://github.com/commitizen-tools/commitizen
rev: v3.10.0
hooks:
- id: commitizen
- id: commitizen-branch
stages:
- push
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": false,
"envFile": "${workspaceFolder}/.env"
}
]
}
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# python-project-template
18 changes: 18 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[project]
name = "myproject"
version = "0.0.0"

[tool.pytest.ini_options]
pythonpath = [
"src"
]

[tool.commitizen]
name = "cz_conventional_commits"
tag_format = "$version"
version_scheme = "pep440"
version_provider = "pep621"
major_version_zero = true
version_files = [
"src/myproject/__init__.py:__version__",
]
4 changes: 4 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
commitizen
coverage
pre-commit
pytest
Empty file added requirements.txt
Empty file.
32 changes: 32 additions & 0 deletions scripts/setup-dev.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
@echo off

:: Define the path to the requirements file
if exist "requirements-dev.txt" (
set requirements_file=requirements-dev.txt
) else if exist "..\requirements-dev.txt" (
set requirements_file=..\requirements-dev.txt
) else (
echo No requirements file found. Please make sure requirements-dev.txt exists in the current directory or one level up.
exit /b 1
)

:: Check if pip is installed
where pip >nul 2>&1
if errorlevel 1 (
echo pip is not installed. Please install Python and try again.
exit /b 1
)

:: Install requirements
pip install -r "%requirements_file%"

:: Check if the installation was successful
if %errorlevel% equ 0 (
echo Requirements installed successfully.
) else (
echo Failed to install requirements.
)

:: Install pre-commit hooks
pre-commit install
pre-commit install --hook-type commit-msg --hook-type pre-push
31 changes: 31 additions & 0 deletions scripts/setup-dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Define the path to the requirements file
if [ -f "requirements-dev.txt" ]; then
requirements_file="requirements-dev.txt"
elif [ -f "../requirements-dev.txt" ]; then
requirements_file="../requirements-dev.txt"
else
echo "No requirements file found. Please make sure requirements-dev.txt exists in the current directory or one level up."
exit 1
fi

# Check if pip is installed
if ! command -v pip &> /dev/null
then
echo "pip is not installed. Please install Python and try again."
exit 1
fi

# Install requirements
pip install -r "$requirements_file"

# Check if the installation was successful
if [ $? -eq 0 ]
then
echo "Requirements installed successfully."
else
echo "Failed to install requirements."
fi

# Install pre-commit hooks
pre-commit install
pre-commit install --hook-type commit-msg --hook-type pre-push
14 changes: 14 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from pathlib import Path

from setuptools import find_packages, setup

requirements = Path("requirements.txt").read_text().split("\n")

setup(
packages=find_packages(where="src"),
package_dir={"": "src"},
install_requires=[
# Add your dependencies here
*requirements
],
)
2 changes: 2 additions & 0 deletions src/mymodule/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def myfunction(*args) -> int:
return sum(args)
5 changes: 5 additions & 0 deletions src/myproject/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
__version__ = "0.0.0"


def info() -> str:
return f"Using myproject v{__version__}"
Empty file added tests/conftest.py
Empty file.
Empty file.
Loading

0 comments on commit f5cfad8

Please sign in to comment.