Skip to content

Commit 678f9ea

Browse files
authored
Add style checking with pre-commit + black, and a CI job (data-apis#684)
Signed-off-by: nstarman <[email protected]>
1 parent 2e07238 commit 678f9ea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+767
-165
lines changed

.git-blame-ignore-revs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
# Move special cases to notes sections
55
816fba3b75c38cbb1bb6fe5b1342adc5eab694f3
66
0a2fa71a32b924cc92718db29910a6cbbc5e9341
7-
931144e7d7d5c8b23393aa730ef28962a35b113b
7+
931144e7d7d5c8b23393aa730ef28962a35b113b

.github/workflows/ci.yml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#/
2+
# @license MIT
3+
#
4+
# Copyright (c) 2022 Python Data APIs Consortium.
5+
#
6+
# Permission is hereby granted, free of charge, to any person obtaining a copy
7+
# of this software and associated documentation files (the "Software"), to deal
8+
# in the Software without restriction, including without limitation the rights
9+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
# copies of the Software, and to permit persons to whom the Software is
11+
# furnished to do so, subject to the following conditions:
12+
#
13+
# The above copyright notice and this permission notice shall be included in all
14+
# copies or substantial portions of the Software.
15+
#
16+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
# SOFTWARE.
23+
#/
24+
25+
# Workflow name:
26+
name: ci
27+
28+
# Workflow triggers:
29+
on:
30+
pull_request:
31+
push:
32+
branches: [main,]
33+
34+
# Workflow jobs:
35+
jobs:
36+
37+
main:
38+
runs-on: ubuntu-latest
39+
steps:
40+
- uses: actions/checkout@v3
41+
- uses: actions/setup-python@v4
42+
with:
43+
python-version: 3.8
44+
- uses: pre-commit/[email protected]
45+
- uses: pre-commit-ci/[email protected]
46+
if: always()

.github/workflows/pages.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ jobs:
4545

4646
# Avoid running this workflow for forks and allow skipping CI:
4747
if: "github.repository == 'data-apis/array-api' && !contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.head_commit.message, '[skip github]')"
48-
48+
4949
# Define a sequence of job steps...
5050
steps:
51-
51+
5252
# Checkout the repository:
5353
- name: 'Checkout repository'
5454
uses: actions/checkout@v2

.pre-commit-config.yaml

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.4.0
4+
hooks:
5+
- id: check-added-large-files
6+
# Prevent giant files from being committed.
7+
- id: check-ast
8+
# Simply check whether files parse as valid python.
9+
- id: check-case-conflict
10+
# Check for files with names that would conflict on a case-insensitive
11+
# filesystem like MacOS HFS+ or Windows FAT.
12+
- id: check-json
13+
# Attempts to load all json files to verify syntax.
14+
- id: check-merge-conflict
15+
# Check for files that contain merge conflict strings.
16+
- id: check-symlinks
17+
# Checks for symlinks which do not point to anything.
18+
- id: check-toml
19+
# Attempts to load all TOML files to verify syntax.
20+
- id: check-xml
21+
# Attempts to load all xml files to verify syntax.
22+
- id: check-yaml
23+
# Attempts to load all yaml files to verify syntax.
24+
exclude: ".*(.github.*)$"
25+
- id: debug-statements
26+
# Check for debugger imports and py37+ breakpoint() calls in python
27+
# source.
28+
- id: detect-private-key
29+
# Checks for the existence of private keys.
30+
- id: end-of-file-fixer
31+
# Makes sure files end in a newline and only a newline.
32+
- id: trailing-whitespace
33+
# Trims trailing whitespace.
34+
exclude_types: [python]
35+
36+
- repo: https://github.com/pre-commit/pygrep-hooks
37+
rev: v1.10.0
38+
hooks:
39+
- id: python-check-mock-methods
40+
# Prevent common mistakes of assert mck.not_called(), assert
41+
# mck.called_once_with(...) and mck.assert_called.
42+
- id: text-unicode-replacement-char
43+
# Forbid files which have a UTF-8 Unicode replacement character.
44+
- id: python-check-blanket-noqa
45+
# Enforce that all noqa annotations always occur with specific codes.
46+
47+
- repo: https://github.com/psf/black-pre-commit-mirror
48+
rev: 23.7.0
49+
hooks:
50+
- id: black

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,4 @@ The following is a list of fixes and points of clarification with regard to the
196196
- `linspace`: conversion of `start` and `stop` should follow type promotion rules ([gh-568](https://github.com/data-apis/array-api/pull/568))
197197
- `nonzero`: clarify that, for arrays having a boolean data type, non-zero elements are those elements which equal `True` ([gh-441](https://github.com/data-apis/array-api/pull/441))
198198
- `trunc`: fix description ([gh-511](https://github.com/data-apis/array-api/pull/511))
199-
- `vecdot`: clarify broadcasting behavior ([gh-417](https://github.com/data-apis/array-api/pull/417) and [gh-473](https://github.com/data-apis/array-api/pull/473))
199+
- `vecdot`: clarify broadcasting behavior ([gh-417](https://github.com/data-apis/array-api/pull/417) and [gh-473](https://github.com/data-apis/array-api/pull/473))

CODE_OF_CONDUCT.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Please note that the Consortium for Python Data API Standards has a Code of
22
Conduct that we ask everyone to respect, see:
3-
https://github.com/data-apis/.github/blob/master/CODE_OF_CONDUCT.md
3+
https://github.com/data-apis/.github/blob/master/CODE_OF_CONDUCT.md

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -244,4 +244,4 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
244244

245245
<!-- ALL-CONTRIBUTORS-LIST:END -->
246246

247-
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
247+
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!

pyproject.toml

+3
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ doc = [
2929
[build-system]
3030
requires = ["setuptools"]
3131
build-backend = "setuptools.build_meta"
32+
33+
[tool.black]
34+
line-length = 88

spec/2021.12/benchmark_suite.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Benchmark suite
22

3-
Adding a benchmark suite is planned in the future.
3+
Adding a benchmark suite is planned in the future.

spec/2021.12/conf.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import sys
22
from pathlib import Path
3+
34
sys.path.insert(0, str(Path(__file__).parents[2] / "src"))
45

56
from array_api_stubs import _2021_12 as stubs_mod

spec/2021.12/design_topics/accuracy.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,4 @@ This specification does not specify accuracy requirements for statistical functi
7474
Linear Algebra
7575
--------------
7676

77-
This specification does not specify accuracy requirements for linear algebra functions; however, this specification does expect that a conforming implementation of the array API standard will make a best-effort attempt to ensure that its implementations are theoretically sound and numerically robust.
77+
This specification does not specify accuracy requirements for linear algebra functions; however, this specification does expect that a conforming implementation of the array API standard will make a best-effort attempt to ensure that its implementations are theoretically sound and numerically robust.

spec/2021.12/design_topics/parallelism.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ coordination of parallelization behavior in a stack of Python libraries are:
2121

2222
Option (1) may possibly fit in a future version of this array API standard.
2323
`array-api issue 4 <https://github.com/data-apis/array-api/issues/4>`_ contains
24-
more detailed discussion on the topic of parallelism.
24+
more detailed discussion on the topic of parallelism.

spec/2021.12/future_API_evolution.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,4 @@ than Python package versioning.
5757

5858
The frequency of releasing a new version of an API standard will likely be at
5959
regular intervals and on the order of one year, however no assumption on
60-
frequency of new versions appearing must be made.
60+
frequency of new versions appearing must be made.

spec/2021.12/usage_data.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,5 @@ See the [`python-record-api`](https://github.com/data-apis/python-record-api) re
8282
Design and usage data support specification decision-making in the following ways.
8383

8484
- Validate user stories to ensure that proposals satisfy existing needs.
85-
- Define scope to ensure that proposals address general array library design requirements (i.e., proposals must have broad applicability and be possible to implement with a reasonable amount of effort).
86-
- Inform technical design discussions to ensure that proposals are grounded in empirical data.
85+
- Define scope to ensure that proposals address general array library design requirements (i.e., proposals must have broad applicability and be possible to implement with a reasonable amount of effort).
86+
- Inform technical design discussions to ensure that proposals are grounded in empirical data.

spec/2021.12/use_cases.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,4 +232,4 @@ def check(x, y):
232232
# (this is different from Numpy, whose behaviour depends on
233233
# the *values* of the arguments -- see PyArray_CanCastArrayTo).
234234
self.assertEqual(got.dtype, x.dtype)
235-
```
235+
```

spec/2022.12/benchmark_suite.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Benchmark suite
22

3-
Adding a benchmark suite is planned in the future.
3+
Adding a benchmark suite is planned in the future.

spec/2022.12/conf.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import sys
22
from pathlib import Path
3+
34
sys.path.insert(0, str(Path(__file__).parents[2] / "src"))
45

56
from array_api_stubs import _2022_12 as stubs_mod

spec/2022.12/design_topics/accuracy.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,4 @@ This specification does not specify accuracy requirements for statistical functi
7474
Linear Algebra
7575
--------------
7676

77-
This specification does not specify accuracy requirements for linear algebra functions; however, this specification does expect that a conforming implementation of the array API standard will make a best-effort attempt to ensure that its implementations are theoretically sound and numerically robust.
77+
This specification does not specify accuracy requirements for linear algebra functions; however, this specification does expect that a conforming implementation of the array API standard will make a best-effort attempt to ensure that its implementations are theoretically sound and numerically robust.

spec/2022.12/design_topics/complex_numbers.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Branch cuts do not arise for single-valued trigonometric, hyperbolic, integer po
2727
In contrast to real-valued floating-point numbers which have well-defined behavior as specified in IEEE 754, complex-valued floating-point numbers have no equivalent specification. Accordingly, this specification chooses to follow C99 conventions for special cases and branch cuts for those functions supporting complex numbers. For those functions which do not have C99 equivalents (e.g., linear algebra APIs), the specification relies on dominant conventions among existing array libraries.
2828

2929
.. warning::
30-
All branch cuts documented in this specification are considered **provisional**. While conforming implementations of the array API standard should adopt the branch cuts described in this standard, consumers of array API standard implementations should **not** assume that branch cuts are consistent between implementations.
30+
All branch cuts documented in this specification are considered **provisional**. While conforming implementations of the array API standard should adopt the branch cuts described in this standard, consumers of array API standard implementations should **not** assume that branch cuts are consistent between implementations.
3131

3232
Provided no issues arise due to the choice of branch cut, the provisional status is likely to be removed in a future revision of this standard.
3333

@@ -58,4 +58,4 @@ Valued-based Promotion
5858

5959
According to the type promotion rules described in this specification (see :ref:`type-promotion`), only the data types of the input arrays participating in an operation matter, not their values. The same principle applies to situations in which one or more results of operations on real-valued arrays are mathematically defined in the complex domain, but not in their real domain.
6060

61-
By convention, the principal square root of :math:`-1` is :math:`j`, where :math:`j` is the imaginary unit. Despite this convention, for those operations supporting type promotion, conforming implementations must only consider input array data types when determining the data type of the output array. For example, if a real-valued input array is provided to :func:`~array_api.sqrt`, the output array must also be real-valued, even if the input array contains negative values. Accordingly, if a consumer of a conforming implementation of this specification desires for an operation's results to include the complex domain, the consumer should first cast the input array(s) to an appropriate complex floating-point data type before performing the operation.
61+
By convention, the principal square root of :math:`-1` is :math:`j`, where :math:`j` is the imaginary unit. Despite this convention, for those operations supporting type promotion, conforming implementations must only consider input array data types when determining the data type of the output array. For example, if a real-valued input array is provided to :func:`~array_api.sqrt`, the output array must also be real-valued, even if the input array contains negative values. Accordingly, if a consumer of a conforming implementation of this specification desires for an operation's results to include the complex domain, the consumer should first cast the input array(s) to an appropriate complex floating-point data type before performing the operation.

spec/2022.12/design_topics/parallelism.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ coordination of parallelization behavior in a stack of Python libraries are:
2121

2222
Option (1) may possibly fit in a future version of this array API standard.
2323
`array-api issue 4 <https://github.com/data-apis/array-api/issues/4>`_ contains
24-
more detailed discussion on the topic of parallelism.
24+
more detailed discussion on the topic of parallelism.

spec/2022.12/future_API_evolution.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,4 @@ than Python package versioning.
5757

5858
The frequency of releasing a new version of an API standard will likely be at
5959
regular intervals and on the order of one year, however no assumption on
60-
frequency of new versions appearing must be made.
60+
frequency of new versions appearing must be made.

spec/2022.12/usage_data.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,5 @@ See the [`python-record-api`](https://github.com/data-apis/python-record-api) re
8282
Design and usage data support specification decision-making in the following ways.
8383

8484
- Validate user stories to ensure that proposals satisfy existing needs.
85-
- Define scope to ensure that proposals address general array library design requirements (i.e., proposals must have broad applicability and be possible to implement with a reasonable amount of effort).
86-
- Inform technical design discussions to ensure that proposals are grounded in empirical data.
85+
- Define scope to ensure that proposals address general array library design requirements (i.e., proposals must have broad applicability and be possible to implement with a reasonable amount of effort).
86+
- Inform technical design discussions to ensure that proposals are grounded in empirical data.

spec/2022.12/use_cases.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,4 +232,4 @@ def check(x, y):
232232
# (this is different from Numpy, whose behaviour depends on
233233
# the *values* of the arguments -- see PyArray_CanCastArrayTo).
234234
self.assertEqual(got.dtype, x.dtype)
235-
```
235+
```

spec/_static/css/custom.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
s {
22
text-decoration: inherit;
3-
}
3+
}

spec/_templates/property.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
{{ name.split('.')[-1] | underline }}
44

5-
.. auto{{ objtype }}:: {{ objname }}
5+
.. auto{{ objtype }}:: {{ objname }}

spec/draft/benchmark_suite.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Benchmark suite
22

3-
Adding a benchmark suite is planned in the future.
3+
Adding a benchmark suite is planned in the future.

spec/draft/conf.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import sys
22
from pathlib import Path
3+
34
sys.path.insert(0, str(Path(__file__).parents[2] / "src"))
45

56
from array_api_stubs import _draft as stubs_mod

spec/draft/design_topics/accuracy.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,4 @@ This specification does not specify accuracy requirements for statistical functi
7474
Linear Algebra
7575
--------------
7676

77-
This specification does not specify accuracy requirements for linear algebra functions; however, this specification does expect that a conforming implementation of the array API standard will make a best-effort attempt to ensure that its implementations are theoretically sound and numerically robust.
77+
This specification does not specify accuracy requirements for linear algebra functions; however, this specification does expect that a conforming implementation of the array API standard will make a best-effort attempt to ensure that its implementations are theoretically sound and numerically robust.

spec/draft/design_topics/complex_numbers.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Branch cuts do not arise for single-valued trigonometric, hyperbolic, integer po
2727
In contrast to real-valued floating-point numbers which have well-defined behavior as specified in IEEE 754, complex-valued floating-point numbers have no equivalent specification. Accordingly, this specification chooses to follow C99 conventions for special cases and branch cuts for those functions supporting complex numbers. For those functions which do not have C99 equivalents (e.g., linear algebra APIs), the specification relies on dominant conventions among existing array libraries.
2828

2929
.. warning::
30-
All branch cuts documented in this specification are considered **provisional**. While conforming implementations of the array API standard should adopt the branch cuts described in this standard, consumers of array API standard implementations should **not** assume that branch cuts are consistent between implementations.
30+
All branch cuts documented in this specification are considered **provisional**. While conforming implementations of the array API standard should adopt the branch cuts described in this standard, consumers of array API standard implementations should **not** assume that branch cuts are consistent between implementations.
3131

3232
Provided no issues arise due to the choice of branch cut, the provisional status is likely to be removed in a future revision of this standard.
3333

@@ -58,4 +58,4 @@ Valued-based Promotion
5858

5959
According to the type promotion rules described in this specification (see :ref:`type-promotion`), only the data types of the input arrays participating in an operation matter, not their values. The same principle applies to situations in which one or more results of operations on real-valued arrays are mathematically defined in the complex domain, but not in their real domain.
6060

61-
By convention, the principal square root of :math:`-1` is :math:`j`, where :math:`j` is the imaginary unit. Despite this convention, for those operations supporting type promotion, conforming implementations must only consider input array data types when determining the data type of the output array. For example, if a real-valued input array is provided to :func:`~array_api.sqrt`, the output array must also be real-valued, even if the input array contains negative values. Accordingly, if a consumer of a conforming implementation of this specification desires for an operation's results to include the complex domain, the consumer should first cast the input array(s) to an appropriate complex floating-point data type before performing the operation.
61+
By convention, the principal square root of :math:`-1` is :math:`j`, where :math:`j` is the imaginary unit. Despite this convention, for those operations supporting type promotion, conforming implementations must only consider input array data types when determining the data type of the output array. For example, if a real-valued input array is provided to :func:`~array_api.sqrt`, the output array must also be real-valued, even if the input array contains negative values. Accordingly, if a consumer of a conforming implementation of this specification desires for an operation's results to include the complex domain, the consumer should first cast the input array(s) to an appropriate complex floating-point data type before performing the operation.

0 commit comments

Comments
 (0)