From 0380e2f2b3e4833d4e12fb766af1672d6965e333 Mon Sep 17 00:00:00 2001 From: Anton Chernyatevich Date: Tue, 13 Jun 2023 18:15:31 +0300 Subject: [PATCH 1/9] Initial repo configuration --- .github/workflows/ci.yml | 62 ++++++++++++++++++++++++++++++++++++++++ .gitignore | 45 +++++++++++++++++++++++++++++ CHANGELOG.md | 0 MANIFEST.in | 6 ++++ arrayfire/__init__.py | 0 arrayfire/py.typed | 0 arrayfire/version.py | 13 +++++++++ examples/__init__.py | 0 requirements.txt | 6 ++++ setup.cfg | 61 +++++++++++++++++++++++++++++++++++++++ setup.py | 3 ++ tests/__init__.py | 0 12 files changed, 196 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 .gitignore create mode 100644 CHANGELOG.md create mode 100644 MANIFEST.in create mode 100644 arrayfire/__init__.py create mode 100644 arrayfire/py.typed create mode 100644 arrayfire/version.py create mode 100644 examples/__init__.py create mode 100644 requirements.txt create mode 100644 setup.cfg create mode 100644 setup.py create mode 100644 tests/__init__.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..a271cc7 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,62 @@ +name: CI + +on: + pull_request: + branches: + - master + push: + branches: + - master + +env: + DEFAULT_PYTHON_VERSION: 3.10 + +jobs: + build: + runs-on: ubuntu-latest + + # steps: + # - uses: actions/checkout@v3 + + # - name: Set up Python 3.10 + # uses: actions/setup-python@v1 + # with: + # python-version: "3.10" + + # - name: Install dependencies + # run: | + # python -m pip install --upgrade pip + # pip install -r requirements.txt + + # - name: Test with pytest + # run: pytest + + # - name: Install AF + # run: apt install arrayfire + + # - name: Test array_api + # run: python -m pytest arrayfire/array_api + + style: + name: Code Style + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: ${{ env.DEFAULT_PYTHON_VERSION }} + + - name: Install requirements + run: | + grep -E '^black' dev-requirements.txt | xargs pip install + + - name: Debug info + run: | + pip freeze + + - name: Run black + run: | + black --check . diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..669ba4b --- /dev/null +++ b/.gitignore @@ -0,0 +1,45 @@ +# build artifacts + +.eggs/ +.mypy_cache +arrayfire.egg-info/ +build/ +dist/ + + +# dev tools + +venv/ + + +# jupyter notebooks + +.ipynb_checkpoints + + +# miscellaneous + +.cache/ +doc/_build/ +*.swp +.DS_Store + + +# python + +*.pyc +*.pyo +__pycache__ + + +# testing and continuous integration + +.coverage +.pytest_cache/ + +# documentation build artifacts + +docs/*.md +docs/api +site/ +mkdocs.yml diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..e69de29 diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..67dc44b --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,6 @@ +include LICENSE +include README.md +recursive-include arrayfire * +global-exclude .DS_Store *.py[cod] +prune **/__pycache__ +prune **/.mypy_cache diff --git a/arrayfire/__init__.py b/arrayfire/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/arrayfire/py.typed b/arrayfire/py.typed new file mode 100644 index 0000000..e69de29 diff --git a/arrayfire/version.py b/arrayfire/version.py new file mode 100644 index 0000000..ac0c75a --- /dev/null +++ b/arrayfire/version.py @@ -0,0 +1,13 @@ +import os + +_MAJOR = "0" +_MINOR = "1" +# On main and in a nightly release the patch should be one ahead of the last +# released build. +_PATCH = "0" +# This is mainly for nightly builds which have the suffix ".dev$DATE". See +# https://semver.org/#is-v123-a-semantic-version for the semantics. +_SUFFIX = os.environ.get("ALLENNLP_VERSION_SUFFIX", "") + +VERSION_SHORT = "{0}.{1}".format(_MAJOR, _MINOR) +VERSION = "{0}.{1}.{2}{3}".format(_MAJOR, _MINOR, _PATCH, _SUFFIX) diff --git a/examples/__init__.py b/examples/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..b1210db --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +# Build requirements +setuptools +wheel + +# Development requirements +-e .[dev,test] diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..ba7eb51 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,61 @@ +[metadata] +name = arrayfire +description = ArrayFire Python Wrapper +licence = BSD +long_description = file: README.md +long_description_content_type = text/markdown +maintainer = ArrayFire +maintainer_email = technical@arrayfire.com +url = http://arrayfire.com +classifiers = + Programming Language :: Python + Programming Language :: Python :: 3 + Programming Language :: Python :: 3.10 + +[options] +packages = find: +install_requires = + scikit-build +python_requires = + >=3.10.0 + +[options.packages.find] +include = arrayfire +exclude = + examples + tests +install_requires = + numpy~=1.22.0 + +[options.extras_require] +dev = + autopep8~=1.6.0 + isort~=5.10.1 + flake8~=4.0.1 + flake8-quotes~=3.2.0 + mypy~=1.3.0 +test = + pytest~=7.1.2 + pytest-cov~=3.0.0 + pytest-isort~=3.0.0 + pytest-flake8~=1.1.1 + pytest-mypy~=0.3.0 + +[tool:isort] +line_length = 119 +multi_line_output = 4 + +[flake8] +exclude = venv +application-import-names = arrayfire +import-order-style = pep8 +inline-quotes = double +max-line-length = 119 + +[mypy] +exclude = venv +disallow_incomplete_defs = true +disallow_untyped_defs = true +ignore_missing_imports = true +show_error_codes = true +warn_return_any = true \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..6068493 --- /dev/null +++ b/setup.py @@ -0,0 +1,3 @@ +from setuptools import setup + +setup() diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 From 9e7a26b11eca490ce86b26d99e71fd48ef2c3e7b Mon Sep 17 00:00:00 2001 From: Anton Chernyatevich Date: Tue, 13 Jun 2023 20:32:36 +0300 Subject: [PATCH 2/9] Add vanilla CI and change setup --- .github/workflows/ci.yml | 30 ++++-------------------------- setup.cfg | 14 ++++++++++++-- setup.py | 7 ++++++- 3 files changed, 22 insertions(+), 29 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a271cc7..2e57744 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,30 +15,8 @@ jobs: build: runs-on: ubuntu-latest - # steps: - # - uses: actions/checkout@v3 - - # - name: Set up Python 3.10 - # uses: actions/setup-python@v1 - # with: - # python-version: "3.10" - - # - name: Install dependencies - # run: | - # python -m pip install --upgrade pip - # pip install -r requirements.txt - - # - name: Test with pytest - # run: pytest - - # - name: Install AF - # run: apt install arrayfire - - # - name: Test array_api - # run: python -m pytest arrayfire/array_api - style: - name: Code Style + name: Code Style and Lint runs-on: ubuntu-latest steps: @@ -51,12 +29,12 @@ jobs: - name: Install requirements run: | - grep -E '^black' dev-requirements.txt | xargs pip install + pip install -e .[dev] - name: Debug info run: | pip freeze - - name: Run black + - name: Run flake8 run: | - black --check . + flake8 . diff --git a/setup.cfg b/setup.cfg index ba7eb51..050e9ce 100644 --- a/setup.cfg +++ b/setup.cfg @@ -4,13 +4,23 @@ description = ArrayFire Python Wrapper licence = BSD long_description = file: README.md long_description_content_type = text/markdown -maintainer = ArrayFire -maintainer_email = technical@arrayfire.com +author = ArrayFire +author_email = technical@arrayfire.com url = http://arrayfire.com classifiers = + Intended Audience :: Science/Research + Development Status :: 5 - Production/Stable + License :: OSI Approved :: BSD License Programming Language :: Python Programming Language :: Python :: 3 Programming Language :: Python :: 3.10 + Topic :: Scientific/Engineering + Topic :: Scientific/Engineering :: Artificial Intelligence + Topic :: Scientific/Engineering :: Information Analysis + Topic :: Scientific/Engineering :: Mathematics + Topic :: Software Development :: Libraries +keywords = + arrayfire parallel computing gpu cpu opencl [options] packages = find: diff --git a/setup.py b/setup.py index 6068493..7510bce 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,8 @@ from setuptools import setup -setup() +VERSION: dict[str, str] = {} + +with open("arrafire/version.py", "r") as version_file: + exec(version_file.read(), VERSION) + +setup(version=VERSION["VERSION"]) From 6dedaf39aa08c0dc4f387615a81c0166229419e5 Mon Sep 17 00:00:00 2001 From: Anton Chernyatevich Date: Tue, 13 Jun 2023 20:35:37 +0300 Subject: [PATCH 3/9] hotfix ci --- .github/workflows/ci.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2e57744..3cc98c0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,9 +12,6 @@ env: DEFAULT_PYTHON_VERSION: 3.10 jobs: - build: - runs-on: ubuntu-latest - style: name: Code Style and Lint runs-on: ubuntu-latest From 0b85405b9b262b3732c2125336ffbe73dadff6b3 Mon Sep 17 00:00:00 2001 From: Anton Chernyatevich Date: Tue, 13 Jun 2023 20:46:51 +0300 Subject: [PATCH 4/9] Add version test --- .github/workflows/ci.yml | 6 ++--- arrayfire/version.py | 2 +- tests/test_version.py | 51 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 4 deletions(-) create mode 100755 tests/test_version.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3cc98c0..73b572a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ env: DEFAULT_PYTHON_VERSION: 3.10 jobs: - style: + tests: name: Code Style and Lint runs-on: ubuntu-latest @@ -32,6 +32,6 @@ jobs: run: | pip freeze - - name: Run flake8 + - name: Run tests run: | - flake8 . + pytest . diff --git a/arrayfire/version.py b/arrayfire/version.py index ac0c75a..ae862ac 100644 --- a/arrayfire/version.py +++ b/arrayfire/version.py @@ -7,7 +7,7 @@ _PATCH = "0" # This is mainly for nightly builds which have the suffix ".dev$DATE". See # https://semver.org/#is-v123-a-semantic-version for the semantics. -_SUFFIX = os.environ.get("ALLENNLP_VERSION_SUFFIX", "") +_SUFFIX = os.environ.get("AF_VERSION_SUFFIX", "") VERSION_SHORT = "{0}.{1}".format(_MAJOR, _MINOR) VERSION = "{0}.{1}.{2}{3}".format(_MAJOR, _MINOR, _PATCH, _SUFFIX) diff --git a/tests/test_version.py b/tests/test_version.py new file mode 100755 index 0000000..25acd56 --- /dev/null +++ b/tests/test_version.py @@ -0,0 +1,51 @@ +import re + +import pytest + +from arrayfire.version import VERSION + +# Regex to check that the current version set in `arrayfire.version` adheres to +# PEP 440, as well as some of our own internal conventions, such as the `.dev` +# suffix being used only for nightly builds. +# 0.0.0rc0.post0.dev20200424 +VALID_VERSION_RE = re.compile( + r"^" + r"(0|[1-9]\d*)" # major + r"\.(0|[1-9]\d*)" # minor + r"\.(0|[1-9]\d*)" # patch + r"(rc(0|[1-9]\d*))?" # patch suffix + r"(\.post(0|[1-9]\d*))?" # [.postN] + r"(\.dev2020[0-9]{4})?" # [.devDATE] + r"$" +) + + +def is_valid(version: str) -> bool: + return VALID_VERSION_RE.match(version) is not None + + +@pytest.mark.parametrize( + "version, valid", + [ + # Valid versions: + ("1.0.0", True), + ("1.0.0rc3", True), + ("1.0.0.post0", True), + ("1.0.0.post1", True), + ("1.0.0rc3.post0", True), + ("1.0.0rc3.post0.dev20200424", True), + # Invalid versions: + ("1.0.0.rc3", False), + ("1.0.0rc01", False), + ("1.0.0rc3.dev2020424", False), + ], +) +def test_is_valid_helper(version: str, valid: bool) -> None: + assert is_valid(version) is valid + + +def test_version() -> None: + """ + Ensures current version is consistent with our conventions. + """ + assert is_valid(VERSION) From f5a674ca31f53a35a5eb07f4a130bbcfcb8bd734 Mon Sep 17 00:00:00 2001 From: Anton Chernyatevich Date: Tue, 13 Jun 2023 20:47:56 +0300 Subject: [PATCH 5/9] Fix codestyle --- .github/workflows/ci.yml | 38 +++++++++++++++++++------------------- .vscode/settings.json | 3 +++ 2 files changed, 22 insertions(+), 19 deletions(-) create mode 100755 .vscode/settings.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 73b572a..b083699 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,15 +1,15 @@ name: CI on: - pull_request: - branches: + pull_request: + branches: - master - push: - branches: + push: + branches: - master env: - DEFAULT_PYTHON_VERSION: 3.10 + DEFAULT_PYTHON_VERSION: 3.10 jobs: tests: @@ -17,21 +17,21 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v3 - - name: Setup Python - uses: actions/setup-python@v4 - with: - python-version: ${{ env.DEFAULT_PYTHON_VERSION }} + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: ${{ env.DEFAULT_PYTHON_VERSION }} - - name: Install requirements - run: | - pip install -e .[dev] + - name: Install requirements + run: | + pip install -e .[dev] - - name: Debug info - run: | - pip freeze + - name: Debug info + run: | + pip freeze - - name: Run tests - run: | - pytest . + - name: Run tests + run: | + pytest . diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100755 index 0000000..69fa7bc --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.analysis.typeCheckingMode": "basic" +} \ No newline at end of file From a65fad41df6943131f459089f560915e5171204f Mon Sep 17 00:00:00 2001 From: Anton Chernyatevich Date: Tue, 13 Jun 2023 20:49:38 +0300 Subject: [PATCH 6/9] hotifx --- .github/workflows/ci.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b083699..ba5cc33 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,8 +12,7 @@ env: DEFAULT_PYTHON_VERSION: 3.10 jobs: - tests: - name: Code Style and Lint + build: runs-on: ubuntu-latest steps: @@ -26,7 +25,7 @@ jobs: - name: Install requirements run: | - pip install -e .[dev] + pip install -r requirements.txt - name: Debug info run: | From b6f7bcfb940bc0d07270f2f6724cf974d0774590 Mon Sep 17 00:00:00 2001 From: Anton Chernyatevich Date: Tue, 13 Jun 2023 20:51:45 +0300 Subject: [PATCH 7/9] Extend .gitignore --- .gitignore | 1 + .vscode/settings.json | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) delete mode 100755 .vscode/settings.json diff --git a/.gitignore b/.gitignore index 669ba4b..a509724 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ dist/ # dev tools venv/ +.vscode/ # jupyter notebooks diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100755 index 69fa7bc..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "python.analysis.typeCheckingMode": "basic" -} \ No newline at end of file From 8a24f539361900fe4085100d9df728a7b00b3c92 Mon Sep 17 00:00:00 2001 From: Anton Chernyatevich Date: Tue, 13 Jun 2023 20:56:22 +0300 Subject: [PATCH 8/9] hotfix python version in ci --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ba5cc33..1300c1d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ on: - master env: - DEFAULT_PYTHON_VERSION: 3.10 + DEFAULT_PYTHON_VERSION: "3.10" jobs: build: From 7017ac5f2cec21f27c793cf678831a1ea4da476c Mon Sep 17 00:00:00 2001 From: Anton Chernyatevich Date: Tue, 13 Jun 2023 21:02:34 +0300 Subject: [PATCH 9/9] Change setup --- setup.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 7510bce..13c7482 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,11 @@ +from pathlib import Path + from setuptools import setup VERSION: dict[str, str] = {} -with open("arrafire/version.py", "r") as version_file: + +with (Path().absolute() / "arrayfire" / "version.py").open("r") as version_file: exec(version_file.read(), VERSION) setup(version=VERSION["VERSION"])