Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added QOL Improvements to the library #4

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Test

on:
pull_request:
push:
branches:
- main
tags:
- '*'

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Miniconda
uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
auto-activate-base: false
- name: Install dependencies
shell: bash -l {0}
run: |
make conda-install
- name: Lint code with pre-commit
shell: bash -l {0}
run: |
make lint
- name: Install mcl with pip
shell: bash -l {0}
run: |
make build
- name: Run pytest
shell: bash -l {0}
run: |
make test
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
repos:
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.2
hooks:
- id: mypy
args: [--config-file=mypy.ini]

- repo: https://github.com/PyCQA/flake8
rev: 7.1.1
hooks:
- id: flake8
17 changes: 17 additions & 0 deletions MAKEFILE
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.PHONY: build test docs env all
all:
make lint && make build && make test
build:
python -m pip install -vv -e .
test:
pytest -vv
lint:
pre-commit run --verbose --all-files
docs:
cd docs && make html
conda-env:
conda create -n mcl
conda-install:
conda install python=3.12 pytest pre-commit numpy
clean:
git clean -dfX
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Minimal Core Language (MCL)
===========================

An experimental Minimal Core (Numba) Language.
30 changes: 30 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = "mcl"
version = "0.0.1"
authors = [
{name = "Numba Developers", email="[email protected]"},
]
description = "An experimental Minimal Core (Numba) Language"
readme = "README.md"
requires-python = ">=3.11"
keywords = ["mcl"]
license = {text = "BSD-2-Clause"}
classifiers = [
"Programming Language :: Python :: 3",
]
dependencies = []

[tool.setuptools.packages]
find = {}

[project.optional-dependencies]
dev = [
"pytest",
"numpy",
"pre-commit"
]
35 changes: 1 addition & 34 deletions test.py → tests/test_array.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,8 @@
# pytest me
import pytest
import logging
from mcl.machine_types import i32, i64, intp, memref
from mcl.vm import Type
from mcl.machine_types import i32, intp, memref
from mcl.ndarray import Array, DType, Int32



def test_i32():
a = i32(321)

assert not isinstance(a, Type)
assert not issubclass(type(a), Type) # metaclass not subclass
assert type(a).__mcl_type_descriptor__.machine_repr == "i32"

b = i32(123)
c = a + b

out = c == i32(444)
assert isinstance(out, bool)
assert out


def test_i64():
a = i32(123)
b = i64(321)

c = b + i64(a)
assert c == i64(444)


def test_final():
with pytest.raises(TypeError, match="final type cannot be subclassed"):
class sub_i32(i32):
pass


def test_array():
shape = (intp(3), intp(4))
i32_dtype = DType(Int32)
Expand Down
33 changes: 33 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# pytest me
import pytest
from mcl.machine_types import i32, i64
from mcl.vm import Type

def test_i32():
a = i32(321)

assert not isinstance(a, Type)
assert not issubclass(type(a), Type) # metaclass not subclass
assert type(a).__mcl_type_descriptor__.machine_repr == "i32"

b = i32(123)
c = a + b

out = c == i32(444)
assert isinstance(out, bool)
assert out


def test_i64():
a = i32(123)
b = i64(321)

c = b + i64(a)
assert c == i64(444)


def test_final():
with pytest.raises(TypeError, match="final type cannot be subclassed"):
class sub_i32(i32):
pass