diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..1d3b6f9 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +__pycache__ +*.pyc +*.pyo +*.pyd +*.egg-info +dist +build \ No newline at end of file diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml new file mode 100644 index 0000000..75be90f --- /dev/null +++ b/.github/workflows/python-app.yml @@ -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 \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a86b1d6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +# qtmlib/.gitignore file contents +__pycache__/ +*.pyc +*.pyo +*.egg-info/ +dist/ +build/ +.idea/ +.vscode/ +__pypackages__/ +*.log +*.swp +.DS_Store +.qtmlib/ +*.venv/ \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..19f77d4 --- /dev/null +++ b/.pre-commit-config.yaml @@ -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 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1225c17 --- /dev/null +++ b/Dockerfile @@ -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"] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..7706cec --- /dev/null +++ b/README.md @@ -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. diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..f9d637a --- /dev/null +++ b/docs/conf.py @@ -0,0 +1 @@ +"""Docs configuration file.""" diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..fea026f --- /dev/null +++ b/docs/index.rst @@ -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() \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..0922809 --- /dev/null +++ b/pyproject.toml @@ -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 = "author@email.com" }] + +[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 = [ + "." +] diff --git a/pytemplate/__init__.py b/pytemplate/__init__.py new file mode 100644 index 0000000..491c274 --- /dev/null +++ b/pytemplate/__init__.py @@ -0,0 +1 @@ +"""Init file for qtmlib.""" diff --git a/pytemplate/main.py b/pytemplate/main.py new file mode 100644 index 0000000..40ced22 --- /dev/null +++ b/pytemplate/main.py @@ -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()) diff --git a/pytemplate/utils.py b/pytemplate/utils.py new file mode 100644 index 0000000..38bc7fc --- /dev/null +++ b/pytemplate/utils.py @@ -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 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..37ef5e4 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,7 @@ +black +pre-commit +pyright +pytest +pytest-lazy-fixture +sphinx +wheel diff --git a/tests/test_main.py b/tests/test_main.py new file mode 100644 index 0000000..01b3f34 --- /dev/null +++ b/tests/test_main.py @@ -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!" diff --git a/tests/test_utils.py b/tests/test_utils.py new file mode 100644 index 0000000..378ed6b --- /dev/null +++ b/tests/test_utils.py @@ -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