generated from CQCL/pytemplate
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4130350
Showing
15 changed files
with
293 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
__pycache__ | ||
*.pyc | ||
*.pyo | ||
*.pyd | ||
*.egg-info | ||
dist | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Docs configuration file.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = [ | ||
"." | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Init file for qtmlib.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
black | ||
pre-commit | ||
pyright | ||
pytest | ||
pytest-lazy-fixture | ||
sphinx | ||
wheel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |