Skip to content

Commit 1889394

Browse files
authored
Add makefile and ci cache (#4)
* Add makefile and ci cache * Add style check * Add miniconda incubator to ci * Add dev reqs * Add make install * Move mypy and flake8 reqs out of setup.cfg * Fix mypy and flake errors. Add isort check * Remove double quotes plugin * Add style checker - black
1 parent 4e50fe8 commit 1889394

27 files changed

+555
-251
lines changed

.flake8

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[flake8]
2+
application-import-names = arrayfire
3+
import-order-style = pep8
4+
inline-quotes = double
5+
max-line-length = 119
6+
7+
8+
exclude =
9+
.venv/**
10+
build/**

.github/workflows/ci.yml

Lines changed: 103 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
name: CI
22

3+
concurrency:
4+
group: ${{ github.workflow }}-${{ github.ref }}
5+
cancel-in-progress: true
6+
37
on:
48
pull_request:
59
branches:
@@ -11,8 +15,13 @@ on:
1115
env:
1216
DEFAULT_PYTHON_VERSION: "3.8"
1317

18+
defaults:
19+
run:
20+
shell: bash -l {0}
21+
1422
jobs:
15-
build:
23+
style:
24+
name: Style
1625
runs-on: ubuntu-latest
1726

1827
steps:
@@ -25,12 +34,102 @@ jobs:
2534

2635
- name: Install requirements
2736
run: |
28-
pip install -r requirements.txt
37+
grep -E '^black' dev-requirements.txt | xargs pip install
38+
39+
- name: Debug info
40+
run: |
41+
pip freeze
42+
43+
- name: Run black
44+
run: |
45+
black --check .
46+
47+
checks:
48+
name: ${{ matrix.task.name }}
49+
runs-on: ${{ matrix.task.runs_on }}
50+
timeout-minutes: 30
51+
strategy:
52+
fail-fast: false
53+
matrix:
54+
task:
55+
- name: Lint
56+
runs_on: ubuntu-latest
57+
coverage_report: false
58+
platform: cpu
59+
run: |
60+
make flake8
61+
make import-sort
62+
make typecheck
63+
64+
- name: CPU Tests
65+
runs_on: ubuntu-latest
66+
coverage_report: true
67+
platform: cpu
68+
run: make tests
69+
70+
steps:
71+
- uses: actions/checkout@v3
72+
73+
- uses: conda-incubator/setup-miniconda@v2
74+
with:
75+
miniconda-version: "latest"
76+
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
77+
78+
- name: Set build variables
79+
run: |
80+
# Get the exact Python version to use in the cache key.
81+
echo "PYTHON_VERSION=$(python --version)" >> $GITHUB_ENV
82+
echo "RUNNER_ARCH=$(uname -m)" >> $GITHUB_ENV
83+
# Use week number in cache key so we can refresh the cache weekly.
84+
echo "WEEK_NUMBER=$(date +%V)" >> $GITHUB_ENV
85+
86+
- uses: actions/cache@v3
87+
id: virtualenv-cache
88+
with:
89+
path: .venv
90+
key: >
91+
${{ env.CACHE_PREFIX }}-${{ env.WEEK_NUMBER }}-${{ runner.os }}-${{ env.RUNNER_ARCH }}-
92+
${{ env.PYTHON_VERSION }}-${{ matrix.task.platform }}-${{ hashFiles('setup.py') }}-
93+
${{ hashFiles('*requirements.txt') }}
94+
95+
- name: Setup virtual environment (no cache hit)
96+
if: steps.virtualenv-cache.outputs.cache-hit != 'true'
97+
run: |
98+
python${{ env.DEFAULT_PYTHON_VERSION }} -m venv .venv
99+
source .venv/bin/activate
100+
make install
101+
102+
- name: Setup virtual environment (cache hit)
103+
if: steps.virtualenv-cache.outputs.cache-hit == 'true'
104+
run: |
105+
source .venv/bin/activate
106+
pip install --no-deps -e .[all]
29107
30108
- name: Debug info
31109
run: |
110+
source .venv/bin/activate
32111
pip freeze
33112
34-
- name: Run tests
113+
- name: ${{ matrix.task.name }}
114+
run: |
115+
source .venv/bin/activate
116+
${{ matrix.task.run }}
117+
118+
- name: Prepare coverage report
119+
if: matrix.task.coverage_report
120+
run: |
121+
mkdir coverage
122+
mv coverage.xml coverage/
123+
124+
- name: Save coverage report
125+
if: matrix.task.coverage_report
126+
uses: actions/upload-artifact@v3
127+
with:
128+
name: ${{ matrix.task.name }}-coverage
129+
path: ./coverage
130+
131+
- name: Clean up
132+
if: always()
35133
run: |
36-
pytest .
134+
source .venv/bin/activate
135+
pip uninstall --yes arrayfire

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ dist/
99

1010
# dev tools
1111

12-
venv/
12+
.venv/
1313
.vscode/
1414

1515

.isort.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[settings]
2+
line_length = 119
3+
multi_line_output = 4

Makefile

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
SRC = arrayfire
2+
3+
ifeq ($(shell uname),Darwin)
4+
ifeq ($(shell which gsed),)
5+
$(error Please install GNU sed with 'brew install gnu-sed')
6+
else
7+
SED = gsed
8+
endif
9+
else
10+
SED = sed
11+
endif
12+
13+
.PHONY : version
14+
version :
15+
@python -c 'from arrayfire.version import VERSION; print(f"ArrayFire Python v{VERSION}")'
16+
17+
.PHONY : install
18+
install :
19+
pip install --upgrade pip
20+
pip install pip-tools
21+
pip-compile requirements.in -o final_requirements.txt --allow-unsafe --rebuild --verbose
22+
pip install -e . -r final_requirements.txt
23+
24+
# Testing
25+
26+
.PHONY : flake8
27+
flake8 :
28+
flake8 arrayfire tests examples
29+
30+
.PHONY : import-sort
31+
import-sort :
32+
isort arrayfire tests examples
33+
34+
.PHONY : typecheck
35+
typecheck :
36+
mypy arrayfire tests examples --cache-dir=/dev/null
37+
38+
.PHONY : tests
39+
tests :
40+
pytest --color=yes -v -rf --durations=40 \
41+
--cov-config=.coveragerc \
42+
--cov=$(SRC) \
43+
--cov-report=xml
44+
45+
# Cleaning
46+
47+
.PHONY : clean
48+
clean :
49+
rm -rf .pytest_cache/
50+
rm -rf arrayfire.egg-info/
51+
rm -rf dist/
52+
rm -rf build/
53+
find . | grep -E '(\.mypy_cache|__pycache__|\.pyc|\.pyo$$)' | xargs rm -rf

arrayfire/__init__.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,19 @@
22
# array objects
33
"Array",
44
# dtypes
5-
"int16", "int32", "int64", "uint8", "uint16", "uint32", "uint64", "float32", "float64",
6-
"complex64", "complex128", "bool"]
5+
"int16",
6+
"int32",
7+
"int64",
8+
"uint8",
9+
"uint16",
10+
"uint32",
11+
"uint64",
12+
"float32",
13+
"float64",
14+
"complex64",
15+
"complex128",
16+
"bool",
17+
]
718

819
from .dtypes import bool, complex64, complex128, float32, float64, int16, int32, int64, uint8, uint16, uint32, uint64
920
from .library.array_object import Array

arrayfire/backend/__init__.py

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,44 @@
22
# Backend
33
"ArrayBuffer",
44
# Operators
5-
"add", "sub", "mul", "div", "mod", "pow", "bitnot", "bitand", "bitor", "bitxor", "bitshiftl", "bitshiftr", "lt",
6-
"le", "gt", "ge", "eq", "neq"]
5+
"add",
6+
"sub",
7+
"mul",
8+
"div",
9+
"mod",
10+
"pow",
11+
"bitnot",
12+
"bitand",
13+
"bitor",
14+
"bitxor",
15+
"bitshiftl",
16+
"bitshiftr",
17+
"lt",
18+
"le",
19+
"gt",
20+
"ge",
21+
"eq",
22+
"neq",
23+
]
724

825
from .backend import ArrayBuffer
926
from .wrapped.operators import (
10-
add, bitand, bitnot, bitor, bitshiftl, bitshiftr, bitxor, div, eq, ge, gt, le, lt, mod, mul, neq, pow, sub)
27+
add,
28+
bitand,
29+
bitnot,
30+
bitor,
31+
bitshiftl,
32+
bitshiftr,
33+
bitxor,
34+
div,
35+
eq,
36+
ge,
37+
gt,
38+
le,
39+
lt,
40+
mod,
41+
mul,
42+
neq,
43+
pow,
44+
sub,
45+
)

arrayfire/backend/backend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
from ..dtypes.helpers import c_dim_t, to_str
66

77
# HACK for osx
8-
# backend_api = ctypes.CDLL("/opt/arrayfire//lib/libafcpu.3.dylib")
8+
backend_api = ctypes.CDLL("/opt/arrayfire//lib/libafcpu.3.dylib")
99
# HACK for windows
10-
backend_api = ctypes.CDLL("C:/Program Files/ArrayFire/v3/lib/afcpu.dll")
10+
# backend_api = ctypes.CDLL("C:/Program Files/ArrayFire/v3/lib/afcpu.dll")
1111

1212

1313
def safe_call(c_err: int) -> None:

arrayfire/backend/wrapped/constant_array.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@ def _constant_complex(number: Union[int, float], shape: Tuple[int, ...], dtype:
1717

1818
safe_call(
1919
backend_api.af_constant_complex(
20-
ctypes.pointer(out), ctypes.c_double(number.real), ctypes.c_double(number.imag), 4,
21-
ctypes.pointer(c_shape.c_array), dtype.c_api_value)
20+
ctypes.pointer(out),
21+
ctypes.c_double(number.real),
22+
ctypes.c_double(number.imag),
23+
4,
24+
ctypes.pointer(c_shape.c_array),
25+
dtype.c_api_value,
26+
)
2227
)
2328
return out
2429

@@ -32,7 +37,8 @@ def _constant_long(number: Union[int, float], shape: Tuple[int, ...], dtype: Dty
3237

3338
safe_call(
3439
backend_api.af_constant_long(
35-
ctypes.pointer(out), ctypes.c_longlong(int(number.real)), 4, ctypes.pointer(c_shape.c_array))
40+
ctypes.pointer(out), ctypes.c_longlong(int(number.real)), 4, ctypes.pointer(c_shape.c_array)
41+
)
3642
)
3743
return out
3844

@@ -47,7 +53,8 @@ def _constant_ulong(number: Union[int, float], shape: Tuple[int, ...], dtype: Dt
4753

4854
safe_call(
4955
backend_api.af_constant_ulong(
50-
ctypes.pointer(out), ctypes.c_ulonglong(int(number.real)), 4, ctypes.pointer(c_shape.c_array))
56+
ctypes.pointer(out), ctypes.c_ulonglong(int(number.real)), 4, ctypes.pointer(c_shape.c_array)
57+
)
5158
)
5259
return out
5360

@@ -61,7 +68,8 @@ def _constant(number: Union[int, float], shape: Tuple[int, ...], dtype: Dtype, /
6168

6269
safe_call(
6370
backend_api.af_constant(
64-
ctypes.pointer(out), ctypes.c_double(number), 4, ctypes.pointer(c_shape.c_array), dtype.c_api_value)
71+
ctypes.pointer(out), ctypes.c_double(number), 4, ctypes.pointer(c_shape.c_array), dtype.c_api_value
72+
)
6573
)
6674
return out
6775

0 commit comments

Comments
 (0)