Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dlucchetti committed Sep 26, 2023
0 parents commit 4130350
Show file tree
Hide file tree
Showing 15 changed files with 293 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
__pycache__
*.pyc
*.pyo
*.pyd
*.egg-info
dist
build
46 changes: 46 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Python application

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

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: 3.11
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
python -m pip install -e .
- name: Pre-commit checks
run: |
python -m pip install pre-commit
pre-commit run --all-files
- name: Run tests
run: |
python -m pytest
# TODO in the future
# - name: Sphinx documentation build
# run: |
# python -m pip install sphinx
# sphinx-build -b html docs/ docs/_build/

# - name: Build and push Docker image
# uses: docker/build-push-action@v2
# with:
# context: .
# push: true
# tags: nathfitz/test:latest
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# qtmlib/.gitignore file contents
__pycache__/
*.pyc
*.pyo
*.egg-info/
dist/
build/
.idea/
.vscode/
__pypackages__/
*.log
*.swp
.DS_Store
.qtmlib/
*.venv/
23 changes: 23 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
repos:
- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black

- repo: https://github.com/RobertCraigie/pyright-python
rev: v1.1.317
hooks:
- id: pyright

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.278
hooks:
- id: ruff

# Building docs on precommit seems like this will be slow.
# - repo: https://github.com/pre-commit/mirrors-sphinx
# rev: v4.2.0
# hooks:
# - id: sphinx
# stages: [commit]
# language_version: python3.11
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM python:3.11-slim-buster

# Set the working directory to /qtmlib
WORKDIR /qtmlib

# Copy the pyproject.toml and requirements.txt files to the container
COPY . .

# Install the dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Start the web server
CMD ["python", "-m", "pytemplate.main"]
70 changes: 70 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# pytemplate

This is a Python 3.11 app called pytemplate. It uses toml instead of setup.py for configuration. The project includes Docker, Pyright, Ruff, GitHub Actions, Black, pre-commit, and Sphinx.

## Project Structure

The project structure is as follows:

```sh
pytemplate
├── .github
│ └── workflows
│ └── python-app.yml
├── .pre-commit-config.yaml
├── .vscode
│ ├── launch.json
│ └── settings.json
├── docs
│ ├── conf.py
│ ├── index.rst
│ └── _static
├── qtmlib
│ ├── __init__.py
│ ├── main.py
│ └── utils.py
├── tests
│ ├── __init__.py
│ ├── test_main.py
│ └── test_utils.py
├── .dockerignore
├── .gitignore
├── Dockerfile
├── pyproject.toml
├── README.md
└── requirements.txt
```

The source code is located in the `pytemplate` folder, which contains the `__init__.py`, `main.py`, and `utils.py` files. The tests are located in the `tests` folder, which contains the `test_main.py` and `test_utils.py` files.

The project uses toml for configuration instead of setup.py. The configuration file is located in `pyproject.toml`.

The project includes Docker, with a Dockerfile located in the root directory. The `.dockerignore` file is also located in the root directory.

The project includes Pyright for static type checking, pre-commit for code formatting, Black for code formatting and Ruff for linting. The configuration for these tools is located in the `.pre-commit-config.yaml` file.

The project includes Sphinx for documentation, with the documentation located in the `docs` folder. The `conf.py` file contains the configuration for Sphinx.

The project includes GitHub Actions for continuous integration, with the configuration located in the `.github/workflows/python-app.yml` file.

## Installation

To install the project, clone the repository and run:

```sh
python -m venv .venv
source .venv/bin/activate
pip install -U pip setuptools
pip install -r requirements.txt
pre-commit install
```

Then install the project using:

```sh
pip install -e .
```

## Testing

Just issue `pytest` from the root directory.
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Docs configuration file."""
41 changes: 41 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
qtmlib
======

.. toctree::
:maxdepth: 2
:caption: Contents:

installation
usage
utils

Installation
------------

To install qtmlib, simply run:

.. code-block:: bash
pip install qtmlib
Usage
-----

To use qtmlib, import the main module:

.. code-block:: python
from qtmlib import main
main.run()
Utils
-----

The utils module contains various utility functions that can be used in conjunction with qtmlib. To use the utils module, import it like so:

.. code-block:: python
from qtmlib import utils
utils.do_something()
35 changes: 35 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "pytemplate"
version = "0.0.1"
description = "A python library"
requires-python = ">=3.11"
authors = [{name = "Author", email = "[email protected]" }]

[tool.setuptools.packages.find]
where = ["."]

[tool.ruff]
# See https://beta.ruff.rs/docs/rules/
select = ["E", "F", "B", "RUF", "PT", "UP", "C4", "D"]
extend-exclude = ["**/*.ipynb"]
target-version = "py311"

[tool.ruff.pydocstyle]
# Use Google-style docstrings.
convention = "google"

# See https://microsoft.github.io/pyright/#/getting-started
[tool.pyright]
include = ["pytemplate","tests"]
ignore = ["**/*.ipynb"]
pythonVersion = "3.11"
typeCheckingMode = "strict"

[tool.pytest.ini_options]
pythonpath = [
"."
]
1 change: 1 addition & 0 deletions pytemplate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Init file for qtmlib."""
10 changes: 10 additions & 0 deletions pytemplate/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""This is the main module of the qtmlib package."""


def hello_world():
"""Print 'Hello, world!' to the console."""
hw = "Hello, World!"
return hw


print(hello_world())
6 changes: 6 additions & 0 deletions pytemplate/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""Utility functions for the qtmlib package."""


def add_numbers(a: int, b: int) -> int:
"""Add two numbers and returns the result."""
return a + b
7 changes: 7 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
black
pre-commit
pyright
pytest
pytest-lazy-fixture
sphinx
wheel
8 changes: 8 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""Tests for qtmlib.main module."""

from pytemplate.main import hello_world


def test_hello_world():
"""Test the hello_world function."""
assert hello_world() == "Hello, World!"
10 changes: 10 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""Tests for qtmlib.utils."""

from pytemplate.utils import add_numbers


def test_add():
"""Test the add function."""
assert add_numbers(2, 3) == 5
assert add_numbers(0, 0) == 0
assert add_numbers(-1, 1) == 0

0 comments on commit 4130350

Please sign in to comment.