Skip to content

Commit ca252c8

Browse files
authored
refactor the CI (#28)
* use templates for the unit test CI * increase the information printed by the formatter / linter CI * check isort * install on ubuntu 20.04 instead of 16.04 * add a check using blackdoc * try setting the python version for isort * globally set the python version * try using conda instead * copy xarray's codecov configuration * set the junit family * try to fix the displayed python version * back to pip * run the py38 CI on python 3.8 * run black since a new version was recently released * disable blackdoc CI for now, which is broken now that black got updated
1 parent a335615 commit ca252c8

File tree

10 files changed

+156
-52
lines changed

10 files changed

+156
-52
lines changed

.codecov.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
codecov:
2+
ci:
3+
# by default, codecov doesn't recognize azure as a CI provider
4+
- dev.azure.com
5+
require_ci_to_pass: yes
6+
7+
coverage:
8+
status:
9+
project:
10+
default:
11+
# Require 1% coverage, i.e., always succeed
12+
target: 1
13+
patch: false
14+
changes: false
15+
16+
comment: off

azure-pipelines.yml

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
# Create and test a Python package on multiple Python versions.
33
# Add steps that analyze code, save the dist with the build record, publish to a PyPI-compatible index, and more:
44
# https://docs.microsoft.com/azure/devops/pipelines/languages/python
5-
65
trigger:
76
- master
87

98
jobs:
109
- job: Linux
1110
pool:
12-
vmImage: 'ubuntu-16.04'
11+
vmImage: 'ubuntu-20.04'
1312
strategy:
1413
matrix:
1514
Python36:
@@ -23,58 +22,67 @@ jobs:
2322
upstream_dev: true
2423

2524
steps:
26-
- task: UsePythonVersion@0
27-
inputs:
28-
versionSpec: '$(python.version)'
29-
displayName: 'Use Python $(python.version)'
30-
31-
- script: |
32-
python -m pip install --upgrade pip setuptools wheel
33-
displayName: 'Upgrade pip and build tools'
34-
35-
- script: |
36-
pip install -r requirements.txt
37-
displayName: 'Install dependencies'
38-
39-
- script: |
40-
python -m pip install \
41-
-i https://pypi.anaconda.org/scipy-wheels-nightly/simple \
42-
--no-deps \
43-
--pre \
44-
--upgrade \
45-
numpy
46-
python -m pip install --upgrade \
47-
git+https://github.com/hgrecco/pint \
48-
git+https://github.com/pydata/xarray
49-
displayName: 'Install upstream-dev dependencies'
50-
condition: eq(variables['UPSTREAM_DEV'], 'true')
51-
52-
- script: |
53-
pip install pytest pytest-azurepipelines pytest-cov
54-
pytest --verbose --cov=./ --cov-report=xml
55-
displayName: 'pytest'
56-
57-
- script: |
58-
curl https://codecov.io/bash > codecov.sh
59-
bash codecov.sh -t aba016f6-96be-4bc3-bdbe-caa6b6aff815
60-
displayName: 'Upload coverage to codecov.io'
25+
- template: ci/install.yml
26+
- template: ci/unit-tests.yml
6127

6228
- job: LintFlake8
29+
variables:
30+
python.version: '3.8'
6331
pool:
64-
vmImage: 'ubuntu-16.04'
32+
vmImage: 'ubuntu-20.04'
6533
steps:
6634
- task: UsePythonVersion@0
35+
inputs:
36+
versionSpec: '$(python.version)'
37+
displayName: 'Use Python $(python.version)'
6738
- bash: python -m pip install flake8
6839
displayName: Install flake8
69-
- bash: flake8
40+
- bash: python -m pip list
41+
displayName: Version Info
42+
- bash: python -m flake8
7043
displayName: flake8 lint checks
7144

45+
- job: FormattingIsort
46+
variables:
47+
python.version: '3.8'
48+
pool:
49+
vmImage: 'ubuntu-20.04'
50+
steps:
51+
- template: ci/install.yml
52+
- script: |
53+
python -m isort --check .
54+
displayName: isort formatting check
55+
7256
- job: FormattingBlack
57+
variables:
58+
python.version: '3.8'
7359
pool:
74-
vmImage: 'ubuntu-16.04'
60+
vmImage: 'ubuntu-20.04'
7561
steps:
7662
- task: UsePythonVersion@0
63+
inputs:
64+
versionSpec: '$(python.version)'
65+
displayName: 'Use Python $(python.version)'
7766
- bash: python -m pip install black
7867
displayName: Install black
79-
- bash: black --check .
68+
- bash: python -m pip list
69+
displayName: Version Info
70+
- bash: python -m black --check .
8071
displayName: black formatting check
72+
73+
# - job: FormattingBlackdoc
74+
# variables:
75+
# python.version: '3.8'
76+
# pool:
77+
# vmImage: 'ubuntu-20.04'
78+
# steps:
79+
# - task: UsePythonVersion@0
80+
# inputs:
81+
# versionSpec: '$(python.version)'
82+
# displayName: 'Use Python $(python.version)'
83+
# - bash: python -m pip install blackdoc
84+
# displayName: Install blackdoc
85+
# - bash: python -m pip list
86+
# displayName: Version Info
87+
# - bash: python -m blackdoc --check .
88+
# displayName: blackdoc formatting check

ci/install.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
steps:
2+
- task: UsePythonVersion@0
3+
inputs:
4+
versionSpec: '$(python.version)'
5+
displayName: 'Use Python $(python.version)'
6+
7+
- script: |
8+
python -m pip install --upgrade pip setuptools wheel
9+
displayName: Upgrade pip and build tools
10+
11+
- script: |
12+
pip install -r ci/requirements.txt
13+
displayName: Install dependencies
14+
15+
- script: |
16+
python -m pip install \
17+
-i https://pypi.anaconda.org/scipy-wheels-nightly/simple \
18+
--no-deps \
19+
--pre \
20+
--upgrade \
21+
numpy
22+
python -m pip install --upgrade \
23+
git+https://github.com/hgrecco/pint \
24+
git+https://github.com/pydata/xarray
25+
displayName: Install upstream-dev dependencies
26+
condition: eq(variables['UPSTREAM_DEV'], 'true')
27+
28+
- bash: |
29+
python -m pip install --no-deps -e .
30+
displayName: Install pint-xarray
31+
32+
- bash: |
33+
python -m pip list
34+
displayName: Version Info

ci/requirements.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
pint
2+
numpy
3+
xarray
4+
isort
5+
black
6+
flake8
7+
pytest
8+
pytest-cov
9+
pytest-azurepipelines

ci/unit-tests.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
steps:
2+
- bash: |
3+
python -c 'import pint_xarray'
4+
displayName: Import pint-xarray
5+
6+
- bash: |
7+
pytest \
8+
--verbose \
9+
--cov=pint_xarray \
10+
--cov-report=xml \
11+
--junitxml=junit/test-results.xml
12+
13+
displayName: Run tests
14+
15+
- bash: |
16+
curl https://codecov.io/bash > codecov.sh
17+
bash codecov.sh -t aba016f6-96be-4bc3-bdbe-caa6b6aff815
18+
displayName: Upload coverage to codecov.io
19+
20+
- task: PublishTestResults@2
21+
condition: succeededOrFailed()
22+
inputs:
23+
testResultsFiles: '**/test-*.xml'
24+
failTaskOnFailedTests: false
25+
testRunTitle: '$(Agent.JobName)'

pint_xarray/accessors.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def is_dict_like(obj):
3636

3737

3838
def zip_mappings(*mappings, fill_value=None):
39-
""" zip mappings by combining values for common keys into a tuple
39+
"""zip mappings by combining values for common keys into a tuple
4040
4141
Works like itertools.zip_longest, so if a key is missing from a
4242
mapping, it is replaced by ``fill_value``.
@@ -237,7 +237,8 @@ def dequantify(self):
237237

238238
units = units_to_str_or_none(conversion.extract_units(self.da))
239239
new_obj = conversion.attach_unit_attributes(
240-
conversion.strip_units(self.da), units,
240+
conversion.strip_units(self.da),
241+
units,
241242
)
242243

243244
return new_obj
@@ -271,7 +272,7 @@ def registry(self, _):
271272
raise AttributeError("Don't try to change the registry once created")
272273

273274
def to(self, units=None, **unit_kwargs):
274-
""" convert the quantities in a DataArray
275+
"""convert the quantities in a DataArray
275276
276277
Parameters
277278
----------
@@ -528,7 +529,7 @@ def dequantify(self):
528529
return new_obj
529530

530531
def to(self, units=None, **unit_kwargs):
531-
""" convert the quantities in a DataArray
532+
"""convert the quantities in a DataArray
532533
533534
Parameters
534535
----------

pint_xarray/conversion.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
def array_attach_units(data, unit, registry=None):
8-
""" attach a unit to the data
8+
"""attach a unit to the data
99
1010
Parameters
1111
----------
@@ -46,7 +46,7 @@ def array_attach_units(data, unit, registry=None):
4646

4747

4848
def array_convert_units(data, unit):
49-
""" convert the units of an array
49+
"""convert the units of an array
5050
5151
This is roughly the same as ``data.to(unit)``.
5252
@@ -80,7 +80,7 @@ def array_convert_units(data, unit):
8080

8181

8282
def array_extract_units(data):
83-
""" extract the units of an array
83+
"""extract the units of an array
8484
8585
If ``data`` is not a quantity, the units are ``None``
8686
"""

pint_xarray/testing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
def assert_units_equal(a, b):
5-
""" assert that the units of two xarray objects are equal
5+
"""assert that the units of two xarray objects are equal
66
77
Raises an :py:exc:`AssertionError` if the units of both objects are not
88
equal. ``units`` attributes and attached unit objects are compared

pint_xarray/tests/test_conversion.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,11 @@ def test_attach_units(self, obj, units):
196196
{"a": "K", "b": "hPa", "u": "m"},
197197
id="Dataset",
198198
),
199-
pytest.param(Variable("x", []), {None: "hPa"}, id="Variable",),
199+
pytest.param(
200+
Variable("x", []),
201+
{None: "hPa"},
202+
id="Variable",
203+
),
200204
),
201205
)
202206
def test_attach_unit_attributes(self, obj, units):
@@ -366,7 +370,9 @@ def test_extract_units(self, typename, units):
366370
id="Dataset",
367371
),
368372
pytest.param(
369-
Variable("x", [], {"units": "hPa"}), {None: "hPa"}, id="Variable",
373+
Variable("x", [], {"units": "hPa"}),
374+
{None: "hPa"},
375+
id="Variable",
370376
),
371377
),
372378
)
@@ -440,7 +446,9 @@ def test_strip_units(self, obj):
440446
id="Dataset",
441447
),
442448
pytest.param(
443-
Variable("x", [], {"units": "hPa"}), {None: "hPa"}, id="Variable",
449+
Variable("x", [], {"units": "hPa"}),
450+
{None: "hPa"},
451+
id="Variable",
444452
),
445453
),
446454
)

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ build-backend = "setuptools.build_meta"
44

55
[tool.setuptools_scm]
66
fallback_version = "999"
7+
8+
[tool.pytest.ini_options]
9+
junit_family = "xunit2"

0 commit comments

Comments
 (0)