Skip to content

Commit

Permalink
Several initial updates:
Browse files Browse the repository at this point in the history
- update packages
- pytemplate/qtmlib -> pytket-phir
- add mypy and ruff configs
  • Loading branch information
qartik committed Sep 26, 2023
1 parent 4130350 commit 2f6b38a
Show file tree
Hide file tree
Showing 18 changed files with 323 additions and 112 deletions.
169 changes: 157 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,160 @@
# qtmlib/.gitignore file contents
# Byte-compiled / optimized / DLL files
__pycache__/
*.pyc
*.pyo
*.egg-info/
dist/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
.idea/
.vscode/
__pypackages__/
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
*.swp
.DS_Store
.qtmlib/
*.venv/
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/
40 changes: 33 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,44 @@
repos:
- repo: https://github.com/psf/black
rev: 23.7.0
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: black
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-toml
- id: check-yaml
- id: check-added-large-files
# Python-specific
- id: check-ast
- id: check-docstring-first
- id: debug-statements

- repo: https://github.com/crate-ci/typos
rev: v1.16.14
hooks:
- id: typos

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

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.278
rev: v0.0.291
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.5.1'
hooks:
- id: mypy
pass_filenames: false
args: [pytket/phir, tests]
additional_dependencies: [
lark-parser==0.12.0,
pytest==7.4.2,
types-setuptools==68.2.0.0,
]

# Building docs on precommit seems like this will be slow.
# - repo: https://github.com/pre-commit/mirrors-sphinx
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM python:3.11-slim-buster

# Set the working directory to /qtmlib
WORKDIR /qtmlib
# Set the working directory to /pytket-phir
WORKDIR /pytket-phir

# Copy the pyproject.toml and requirements.txt files to the container
COPY . .
Expand All @@ -10,4 +10,4 @@ COPY . .
RUN pip install --no-cache-dir -r requirements.txt

# Start the web server
CMD ["python", "-m", "pytemplate.main"]
CMD ["python", "-m", "pytket.phir.main"]
49 changes: 1 addition & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,4 @@
# 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.
# pytket-phir

## Installation

Expand Down
16 changes: 8 additions & 8 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
qtmlib
pytket-phir
======

.. toctree::
Expand All @@ -12,30 +12,30 @@ qtmlib
Installation
------------

To install qtmlib, simply run:
To install pytket-phir, simply run:

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

To use qtmlib, import the main module:
To use pytket-phir, import the main module:

.. code-block:: python
from qtmlib import main
from pytket-phir 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:
The utils module contains various utility functions that can be used in conjunction with pytket-phir. To use the utils module, import it like so:

.. code-block:: python
from qtmlib import utils
from pytket-phir import utils
utils.do_something()
utils.do_something()
50 changes: 50 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Global options:

; See doc at https://mypy.readthedocs.io/en/stable/config_file.html
[mypy]
follow_imports = silent
python_version = 3.10

exclude = (?x)(
^build/
)

## Disallow dynamic typing
disallow_any_unimported = true
disallow_any_expr = true
disallow_any_decorated = true
disallow_any_explicit = true
disallow_any_generics = true
disallow_subclassing_any = true

## Untyped definitions and calls
disallow_untyped_calls = true
disallow_untyped_defs = true
disallow_incomplete_defs = true
check_untyped_defs = true
disallow_untyped_decorators = true

## Configuring warnings
warn_redundant_casts = true
warn_unused_ignores = true
warn_return_any = true
; warn_unreachable = true # disabled because it can result in false positives

## Miscellaneous strictness flags
local_partial_types = true
implicit_reexport = false
strict_equality = true
strict = true

## Configuring error messages
; show_error_context = true
pretty = true

## Miscellaneous
scripts_are_modules = true
warn_unused_configs = true

# Per-module options:

[mypy-tests.*]
disallow_untyped_defs = false
Loading

0 comments on commit 2f6b38a

Please sign in to comment.