Skip to content

Commit

Permalink
initialise project
Browse files Browse the repository at this point in the history
  • Loading branch information
kimxworrall committed Sep 16, 2024
1 parent 73a0733 commit 0078ccd
Show file tree
Hide file tree
Showing 11 changed files with 530 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/ci-pyright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: CI - Pyright

on:
# Trigger the workflow on push or pull request,
# but only for the master branch
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]

env:
PYRIGHT_VERSION: 1.0

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Upgrade pip
run: |
pip install --upgrade pip
- name: Install the package
run: |
pip install .[dev]
- name: Pyright
uses: jakebailey/pyright-action@v1
with:
version: "1.1.309"
38 changes: 38 additions & 0 deletions .github/workflows/code-formatting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This workflow check the format all files in the repository
# * It checks that all nonempty files have a newline at the end
# * It checks that there are no whitespaces at the end of lines
# * It checks that Python files are formatted with ruff

name: Code Formatting

on:
pull_request:
push:
branches: [main]

jobs:
code-formatting:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.10']

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip' # caching pip dependencies
cache-dependency-path: |
setup.py
requirements.txt
- name: Upgrade pip
run: |
pip install --upgrade pip
- name: Run code formatting checks with pre-commit
uses: pre-commit/[email protected]
130 changes: 130 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# 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/
pip-wheel-metadata/
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/

# 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
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.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
Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__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/
17 changes: 17 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: mixed-line-ending
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.3
hooks:
- id: ruff
types_or: [ python, pyi, jupyter ]
args: [ --fix, --exit-non-zero-on-fix ]
- id: ruff-format
types_or: [ python, pyi, jupyter ]
82 changes: 82 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += --no-builtin-variables

# allow overriding the name of the venv directory
VENV_DIR ?= venv

# use a default prefix for coverage data files
COVERAGE_FILE ?= .coverage

# use different coverage data file per coverage run, otherwise combine complains
TESTS_COVERAGE_FILE = ${COVERAGE_FILE}.tests

# make tasks run all commands in a single shell
.ONESHELL:

# these targets don't produce files:
.PHONY: ${VENV_DIR}/ venv clean clean-caches filecheck pytest pytest-nb tests-toy tests
.PHONY: coverage-report-html coverage-report-md

# set up the venv with all dependencies for development
${VENV_DIR}/: requirements.txt
python3 -m venv ${VENV_DIR}
. ${VENV_DIR}/bin/activate
python3 -m pip --require-virtualenv install -r requirements.txt

# make sure `make venv` always works no matter what $VENV_DIR is
venv: ${VENV_DIR}/

# remove all caches
clean-caches:
rm -rf .pytest_cache *.egg-info .coverage.*
find . -type f -name "*.cover" -delete

# remove all caches and the venv
clean: clean-caches
rm -rf ${VENV_DIR}

# run filecheck tests
filecheck:
lit -vv tests/filecheck --order=smart --timeout=20

# run pytest tests
pytest:
pytest tests -W error -vv

# run all tests
tests: pytest tests-toy filecheck pytest-nb tests-marimo tests-marimo-mlir pyright
@echo All tests done.

# set up all precommit hooks
precommit-install:
pre-commit install

# run all precommit hooks and apply them
precommit:
pre-commit run --all

# run pyright on all files in the current git commit
pyright:
# We make sure to generate the python typing stubs before running pyright
xdsl-stubgen
pyright $(shell git diff --staged --name-only -- '*.py')

# run coverage over all tests and combine data files
coverage: coverage-tests coverage-filecheck-tests
coverage combine --append

# run coverage over tests
coverage-tests:
COVERAGE_FILE=${TESTS_COVERAGE_FILE} pytest -W error --cov --cov-config=.coveragerc

# run coverage over filecheck tests
coverage-filecheck-tests:
lit -v tests/filecheck/ -DCOVERAGE

# generate html coverage report
coverage-report-html:
coverage html

# generate markdown coverage report
coverage-report-md:
coverage report --format=markdown
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# inconspiquous
A testing ground for quantum computing compilation ideas in xdsl


Empty file added inconspiquous/__init__.py
Empty file.
8 changes: 8 additions & 0 deletions inconspiquous/inconspiquous-opt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env python3

import sys

from tools.inconspiquous_opt_main import main

if __name__ == "__main__":
sys.exit(main())
17 changes: 17 additions & 0 deletions inconspiquous/tools/inconspiquous_opt_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from xdsl.xdsl_opt_main import xDSLOptMain

class OptMain(xDSLOptMain):
def register_all_dialects(self):
super().register_all_dialects()
## Add custom dialects
# FIXME: override upstream qref dialect. Remove this after upstreaming full downstream qref dialect.
self.ctx._registered_dialects.pop("qref", None) # pyright: ignore


def main():
xdsl_main = OptMain()
xdsl_main.run()


if "__main__" == __name__:
main()
19 changes: 19 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[project]
name = "inconspiquous"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.10"
dependencies = [
"ruff>=0.6.5",
"xdsl>=0.22.0",
]

[project.optional-dependencies]
dev = [
"pyright>=1.1.380",
"pytest>=8.3.3",
"lit<16.0.0",
"filecheck==0.0.23",
"pre-commit==3.3.1",
]
Loading

0 comments on commit 0078ccd

Please sign in to comment.