Skip to content

perf: faster test suite with xdist #190

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

Closed
wants to merge 17 commits into from
Closed
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
24 changes: 20 additions & 4 deletions .github/workflows/build-ultraplot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ jobs:

- name: Test Ultraplot
run: |
pytest --cov=ultraplot --cov-branch --cov-report term-missing --cov-report=xml ultraplot
pytest \
-n auto \
--cov=ultraplot \
--cov-branch \
--cov-report term-missing \
--cov-report=xml \
ultraplot

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
Expand All @@ -52,7 +58,6 @@ jobs:
slug: Ultraplot/ultraplot

compare-baseline:
needs: build-ultraplot
runs-on: ubuntu-latest
defaults:
run:
Expand All @@ -77,14 +82,25 @@ jobs:
git fetch origin ${{ github.event.pull_request.base.sha }}
git checkout ${{ github.event.pull_request.base.sha }}
python -c "import ultraplot as plt; plt.config.Configurator()._save_yaml('ultraplot.yml')"
pytest -W ignore --mpl-generate-path=baseline --mpl-default-style="./ultraplot.yml"
pytest \
-W ignore \
--mpl-generate-path=baseline \
--mpl-default-style="./ultraplot.yml"
git checkout ${{ github.sha }} # Return to PR branch

- name: Image Comparison Ultraplot
run: |
mkdir -p results
python -c "import ultraplot as plt; plt.config.Configurator()._save_yaml('ultraplot.yml')"
pytest -W ignore --mpl --mpl-baseline-path=baseline --mpl-generate-summary=html --mpl-results-path=./results/ --mpl-default-style="./ultraplot.yml" --store-failed-only ultraplot/tests
pytest \
-W ignore \
--mpl \
--mpl-baseline-path=baseline \
--mpl-generate-summary=html \
--mpl-results-path=./results/ \
--mpl-default-style="./ultraplot.yml" \
--store-failed-only \
ultraplot/tests

# Return the html output of the comparison even if failed
- name: Upload comparison failures
Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies:
- pytest
- pytest-mpl
- pytest-cov
- pytest-xdist
- jupyter
- pip
- pint
Expand Down
23 changes: 14 additions & 9 deletions ultraplot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
version = __version__

# Import dependencies early to isolate import times
from . import internals, externals, tests # noqa: F401
from .internals.benchmarks import _benchmark
from . import internals, externals, tests # noqa: F401 E402
from .internals.benchmarks import _benchmark # noqa: E402

with _benchmark("pyplot"):
from matplotlib import pyplot # noqa: F401
Expand Down Expand Up @@ -56,16 +56,21 @@
from .demos import * # noqa: F401 F403

# Dynamically add registered classes to top-level namespace
from . import proj as crs # backwards compatibility # noqa: F401
from .constructor import NORMS, LOCATORS, FORMATTERS, SCALES, PROJS
from . import proj as crs # backwards compatibility # noqa: F401 E402
from .constructor import NORMS, LOCATORS, FORMATTERS, SCALES, PROJS # noqa: E402

_globals = globals()
for _src in (NORMS, LOCATORS, FORMATTERS, SCALES, PROJS):
for _key, _cls in _src.items():
if isinstance(_cls, type): # i.e. not a scale preset
_globals[_cls.__name__] = _cls # may overwrite ultraplot names
# Register objects
from .config import register_cmaps, register_cycles, register_colors, register_fonts
from .config import (
register_cmaps,
register_cycles,
register_colors,
register_fonts,
) # noqa: E402

with _benchmark("cmaps"):
register_cmaps(default=True)
Expand All @@ -78,8 +83,8 @@

# Validate colormap names and propagate 'cycle' to 'axes.prop_cycle'
# NOTE: cmap.sequential also updates siblings 'cmap' and 'image.cmap'
from .config import rc
from .internals import rcsetup, warnings
from .config import rc # noqa: E402
from .internals import rcsetup, warnings # noqa: E402


rcsetup.VALIDATE_REGISTERED_CMAPS = True
Expand All @@ -98,7 +103,7 @@

# Validate color names now that colors are registered
# NOTE: This updates all settings with 'color' in name (harmless if it's not a color)
from .config import rc_ultraplot, rc_matplotlib
from .config import rc_ultraplot, rc_matplotlib # noqa: E402

rcsetup.VALIDATE_REGISTERED_COLORS = True
for _src in (rc_ultraplot, rc_matplotlib):
Expand All @@ -110,4 +115,4 @@
except ValueError as err:
warnings._warn_ultraplot(f"Invalid user rc file setting: {err}")
_src[_key] = "black" # fill value
from .colors import _cmap_database as colormaps
from .colors import _cmap_database as colormaps # noqa: E402 F401
2 changes: 1 addition & 1 deletion ultraplot/internals/warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def next_release():

def _warn_ultraplot(message):
"""
Emit a `UltraPlotWarning` and show the stack level outside of matplotlib and
Emit a `UltraplotWarning` and show the stack level outside of matplotlib and
ultraplot. This is adapted from matplotlib's warning system.
"""
frame = sys._getframe()
Expand Down
3 changes: 0 additions & 3 deletions ultraplot/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ def __init__(self, config):
self.result_dir = Path(config.getoption("--mpl-results-path", "./results"))
self.baseline_dir = Path(config.getoption("--mpl-baseline-path", "./baseline"))

print(f"Store Failed MPL Plugin initialized")
print(f"Result dir: {self.result_dir}")

def _has_mpl_marker(self, report: pytest.TestReport):
"""Check if the test has the mpl_image_compare marker."""
return report.keywords.get("mpl_image_compare", False)
Expand Down
2 changes: 1 addition & 1 deletion ultraplot/tests/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_ignored_keywords():
subplotpars={"left": 0.2},
)
# only capture ultraplot warnings not general mpl warnings, e.g. deprecation warnings
record = [r for r in record if "UltraPlotWarning" in str(r)]
record = [r for r in record if "UltraplotWarning" in str(r)]
assert len(record) == 3
with warnings.catch_warnings(record=True) as record:
fig.subplots_adjust(left=0.2)
Expand Down