From e13dbde1f47edd9f9b44297d54307a29ca461c4d Mon Sep 17 00:00:00 2001 From: beckermr Date: Wed, 29 Jan 2025 05:32:49 -0600 Subject: [PATCH 1/7] prod: clean out old envs and add pre-commit --- .github/workflows/build-docs.yml | 2 +- .github/workflows/build-ultraplot.yml | 2 +- .github/workflows/linter.yml | 28 --------- .pre-commit-config.yaml | 59 +++++++++--------- .readthedocs.yml | 2 +- .travis.yml | 42 ------------- environment-dev.yml | 26 -------- environment.yml | 25 ++++++-- {ci => logo}/PermanentMarker-Regular.ttf | Bin .../environment-logo.yml | 0 {ci => logo}/logo.py | 0 {ci => logo}/run-linter.sh | 0 {ci => logo}/whyUltraPlot.svg | 0 requirements.txt | 4 -- 14 files changed, 51 insertions(+), 139 deletions(-) delete mode 100644 .github/workflows/linter.yml delete mode 100644 .travis.yml delete mode 100644 environment-dev.yml rename {ci => logo}/PermanentMarker-Regular.ttf (100%) rename ci/environment.yml => logo/environment-logo.yml (100%) rename {ci => logo}/logo.py (100%) rename {ci => logo}/run-linter.sh (100%) rename {ci => logo}/whyUltraPlot.svg (100%) delete mode 100644 requirements.txt diff --git a/.github/workflows/build-docs.yml b/.github/workflows/build-docs.yml index 3fd774df2..fe6790d2d 100644 --- a/.github/workflows/build-docs.yml +++ b/.github/workflows/build-docs.yml @@ -13,7 +13,7 @@ jobs: - uses: actions/checkout@v4 - uses: mamba-org/setup-micromamba@v2.0.4 with: - environment-file: ./environment-dev.yml + environment-file: ./environment.yml - name: "Build docs" shell: bash -el {0} run: | diff --git a/.github/workflows/build-ultraplot.yml b/.github/workflows/build-ultraplot.yml index 56dccfcac..e082dd60c 100644 --- a/.github/workflows/build-ultraplot.yml +++ b/.github/workflows/build-ultraplot.yml @@ -15,7 +15,7 @@ jobs: - uses: actions/checkout@v4 - uses: mamba-org/setup-micromamba@v2.0.4 with: - environment-file: ./environment-dev.yml + environment-file: ./environment.yml init-shell: bash create-args: >- --verbose diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml deleted file mode 100644 index 5ba74fadc..000000000 --- a/.github/workflows/linter.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: Linter check -on: - push: - branches: [main] - pull_request: - branches: [main] - -jobs: - linter: - runs-on: ubuntu-latest - timeout-minutes: 15 - steps: - - uses: actions/checkout@v4 - - uses: mamba-org/setup-micromamba@v2.0.4 - with: - environment-file: ./environment-dev.yml - init-shell: bash - create-args: --verbose - cache-environment: true - cache-downloads: false - - - name: "Apply linter" - shell: bash -el {0} - run: | - micromamba activate ultraplot-dev - pip install . - pip install black - black --check --diff ultraplot diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8a0eb377f..8f0e66f0e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,39 +1,36 @@ -# See: https://pre-commit.com/hooks.html -# Must put flake8 in separate group so 'black' is executed first -# WARNING: Make sure to keep flags in sync with ci/run-linter.sh +ci: + autofix_commit_msg: | + [pre-commit.ci] auto fixes from pre-commit.com hooks + + for more information, see https://pre-commit.ci + autofix_prs: false + autoupdate_commit_msg: '[pre-commit.ci] pre-commit autoupdate' + autoupdate_schedule: monthly + skip: [] + submodules: false + repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.1.0 + rev: v5.0.0 hooks: - - id: double-quote-string-fixer - - id: check-docstring-first - - id: check-merge-conflict - - id: end-of-file-fixer - - id: trailing-whitespace + - id: end-of-file-fixer + - id: trailing-whitespace - - repo: https://github.com/pre-commit/mirrors-isort - rev: v5.10.1 + - repo: https://github.com/asottile/pyupgrade + rev: v3.19.1 hooks: - - id: isort - args: ['--line-width=88', '--multi-line=3', '--force-grid-wrap=0', '--trailing-comma'] - exclude: '(^docs|__init__)' + - id: pyupgrade + args: + - --py10-plus - - repo: https://github.com/PyCQA/flake8 - rev: 4.0.1 + - repo: https://github.com/crate-ci/typos + rev: dictgen-v0.3.1 hooks: - - id: flake8 - args: ['--max-line-length=88', '--ignore=W503,E402,E731,E741'] + - id: typos - # apply once this handles long tables better - # - repo: https://github.com/PyCQA/doc8 - # rev: 0.10.1 - # hooks: - # - id: doc8 - # args: ['--max-line-length', '88', '--allow-long-titles'] - - # apply after function keyword args can be ignored - # - repo: https://github.com/ambv/black - # rev: 22.1.0 - # hooks: - # - id: black - # args: ['--line-length', '88', '--skip-string-normalization'] + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.8.6 + hooks: + - id: ruff + args: [ --fix ] + - id: ruff-format diff --git a/.readthedocs.yml b/.readthedocs.yml index 385709145..9aec82860 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -18,7 +18,7 @@ build: conda: - environment: ./environment-dev.yml + environment: ./environment.yml sphinx: configuration: ./docs/conf.py diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 1a9f3475b..000000000 --- a/.travis.yml +++ /dev/null @@ -1,42 +0,0 @@ -# Travis Continuos Integration -# Currently only tests notebook files -# Based on https://conda.pydata.org/docs/travis.html -sudo: false # use container based build -language: python -dist: focal -notifications: - email: false - -python: - - "3.7" - -before_install: - - | - MODIFIED_FILES=$(git diff --name-only "$TRAVIS_COMMIT_RANGE" 2>/dev/null) - if [ $? -eq 0 ] && ! echo "$MODIFIED_FILES" | grep -qvE '(.md)|(.rst)|(.html)|(.png)|(.ico)' - then - echo "Only doc files were updated, not running the CI." - exit - fi - - wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh - - bash miniconda.sh -b -p $HOME/miniconda - - export PATH="$HOME/miniconda/bin:$PATH" - - hash -r - - conda config --set always_yes yes --set changeps1 no --set show_channel_urls true - - conda update -q conda - - conda info -a - -install: - - conda env create --file ci/environment.yml - - source activate ultra-dev - - conda list - - which conda - - which python - - python setup.py sdist bdist_wheel - - pip install --user ./dist/*.whl - -script: - - ci/run-linter.sh - - pushd docs - - make html - - popd diff --git a/environment-dev.yml b/environment-dev.yml deleted file mode 100644 index 336ba4aa0..000000000 --- a/environment-dev.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: ultraplot-dev -channels: - - conda-forge -dependencies: - - python>=3.10,<3.13 - - numpy - - matplotlib>=3.9 - - cartopy - - xarray - - seaborn - - pandas - - pytest - - pytest-mpl - - jupyter - - pip - - pint - - sphinx - - nbsphinx - - jupytext - - sphinx-copybutton - - sphinx-autoapi - - sphinx-automodapi - - sphinx-rtd-theme - - basemap >=1.4.1 - - pip: - - git+https://github.com/ultraplot/UltraTheme.git diff --git a/environment.yml b/environment.yml index 6485e16a1..336ba4aa0 100644 --- a/environment.yml +++ b/environment.yml @@ -1,11 +1,26 @@ -name: ultraplot +name: ultraplot-dev channels: - conda-forge - - nodefaults dependencies: - - python>=3.9,<3.13 + - python>=3.10,<3.13 + - numpy + - matplotlib>=3.9 + - cartopy + - xarray + - seaborn + - pandas - pytest - pytest-mpl - - numpy>=1.20.0 - - matplotlib>=3.9 + - jupyter - pip + - pint + - sphinx + - nbsphinx + - jupytext + - sphinx-copybutton + - sphinx-autoapi + - sphinx-automodapi + - sphinx-rtd-theme + - basemap >=1.4.1 + - pip: + - git+https://github.com/ultraplot/UltraTheme.git diff --git a/ci/PermanentMarker-Regular.ttf b/logo/PermanentMarker-Regular.ttf similarity index 100% rename from ci/PermanentMarker-Regular.ttf rename to logo/PermanentMarker-Regular.ttf diff --git a/ci/environment.yml b/logo/environment-logo.yml similarity index 100% rename from ci/environment.yml rename to logo/environment-logo.yml diff --git a/ci/logo.py b/logo/logo.py similarity index 100% rename from ci/logo.py rename to logo/logo.py diff --git a/ci/run-linter.sh b/logo/run-linter.sh similarity index 100% rename from ci/run-linter.sh rename to logo/run-linter.sh diff --git a/ci/whyUltraPlot.svg b/logo/whyUltraPlot.svg similarity index 100% rename from ci/whyUltraPlot.svg rename to logo/whyUltraPlot.svg diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index b20c5e8c7..000000000 --- a/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -pytest -pytest-mpl -numpy -matplotlib>=3.9.3 From 2d36f5773fafa1e6d0979fc4853d4a09185d89ca Mon Sep 17 00:00:00 2001 From: beckermr Date: Wed, 29 Jan 2025 05:33:42 -0600 Subject: [PATCH 2/7] prod: add pre-commit to env --- environment.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/environment.yml b/environment.yml index 336ba4aa0..3fe4a8c28 100644 --- a/environment.yml +++ b/environment.yml @@ -22,5 +22,6 @@ dependencies: - sphinx-automodapi - sphinx-rtd-theme - basemap >=1.4.1 + - pre-commit - pip: - git+https://github.com/ultraplot/UltraTheme.git From 2b8301076fa8d23007dd2490b9cfb68ae53d710a Mon Sep 17 00:00:00 2001 From: beckermr Date: Wed, 29 Jan 2025 05:38:17 -0600 Subject: [PATCH 3/7] prod: use black in pre-commit --- .pre-commit-config.yaml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8f0e66f0e..3a9d19631 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -33,4 +33,9 @@ repos: hooks: - id: ruff args: [ --fix ] - - id: ruff-format + + - repo: https://github.com/psf/black-pre-commit-mirror + rev: 24.8.0 + hooks: + - id: black + language_version: python3.10 From db94b909d23e1a43bf5271498d514d880209132f Mon Sep 17 00:00:00 2001 From: beckermr Date: Wed, 29 Jan 2025 05:45:42 -0600 Subject: [PATCH 4/7] prod: remove a few extra hooks --- .pre-commit-config.yaml | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3a9d19631..081f171e7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,30 +10,18 @@ ci: submodules: false repos: - - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v5.0.0 - hooks: - - id: end-of-file-fixer - - id: trailing-whitespace - - repo: https://github.com/asottile/pyupgrade rev: v3.19.1 hooks: - id: pyupgrade args: - - --py10-plus + - --py310-plus - repo: https://github.com/crate-ci/typos rev: dictgen-v0.3.1 hooks: - id: typos - - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.8.6 - hooks: - - id: ruff - args: [ --fix ] - - repo: https://github.com/psf/black-pre-commit-mirror rev: 24.8.0 hooks: From 57e303224a3c0dddf14e294fbaef6076aa9f98d0 Mon Sep 17 00:00:00 2001 From: beckermr Date: Wed, 29 Jan 2025 05:55:48 -0600 Subject: [PATCH 5/7] prod: remove a few more hooks --- .pre-commit-config.yaml | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 081f171e7..36dba903a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,20 +10,7 @@ ci: submodules: false repos: - - repo: https://github.com/asottile/pyupgrade - rev: v3.19.1 - hooks: - - id: pyupgrade - args: - - --py310-plus - - - repo: https://github.com/crate-ci/typos - rev: dictgen-v0.3.1 - hooks: - - id: typos - - repo: https://github.com/psf/black-pre-commit-mirror rev: 24.8.0 hooks: - id: black - language_version: python3.10 From ca89f27f0dc2b7125531dbc38e904fad0447807e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 29 Jan 2025 11:56:52 +0000 Subject: [PATCH 6/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- logo/logo.py | 160 ++++++++++++++++++++++++++++----------------------- 1 file changed, 88 insertions(+), 72 deletions(-) diff --git a/logo/logo.py b/logo/logo.py index e9f791b19..019d4074f 100644 --- a/logo/logo.py +++ b/logo/logo.py @@ -2,39 +2,47 @@ import ultraplot as plt, numpy as np from matplotlib.font_manager import FontProperties -from matplotlib import patheffects as pe +from matplotlib import patheffects as pe from matplotlib.patches import Rectangle from scipy.ndimage import gaussian_filter -font = FontProperties(fname='./PermanentMarker-Regular.ttf') +font = FontProperties(fname="./PermanentMarker-Regular.ttf") fs = 38 left = 0.575 sw = 3 -fig, ax = plt.subplots(figsize = (3, 1.25)) -ax.text(left, 0.5, "Ultra", - fontsize = fs, - fontproperties = font, - va = "center", - ha = "right", - color = "steelblue", - path_effects = [ - pe.Stroke(linewidth = sw, foreground = "white"), +fig, ax = plt.subplots(figsize=(3, 1.25)) +ax.text( + left, + 0.5, + "Ultra", + fontsize=fs, + fontproperties=font, + va="center", + ha="right", + color="steelblue", + path_effects=[ + pe.Stroke(linewidth=sw, foreground="white"), pe.Normal(), ], - transform = ax.transAxes) -ax.text(left, 0.5, "Plot", - fontsize = fs, + transform=ax.transAxes, +) +ax.text( + left, + 0.5, + "Plot", + fontsize=fs, # fontproperties = font, - va = "center", - ha = "left", - color = "white", - path_effects = [ - pe.Stroke(linewidth = sw, foreground = "steelblue"), - pe.Normal(), + va="center", + ha="left", + color="white", + path_effects=[ + pe.Stroke(linewidth=sw, foreground="steelblue"), + pe.Normal(), ], - transform = ax.transAxes) + transform=ax.transAxes, +) shift = 0.033 import colorengine as ce @@ -44,9 +52,7 @@ colors = ce.vivid(colors) for idx, color in enumerate(colors): s = idx * shift - ax.axhline(0.275 - 2.3 * s, 0.59 + s, 0.9 - s, color = color, - ls = '-', - lw = 3) + ax.axhline(0.275 - 2.3 * s, 0.59 + s, 0.9 - s, color=color, ls="-", lw=3) ax.axis(False) # fig.set_facecolor("lightgray") @@ -60,15 +66,16 @@ square_size_y = 0.1 # Base square size in y direction square_size_x = square_size_y / fig_aspect # Adjust x size to maintain square shape -n_squares_x = int(1.0 / square_size_x) + 1 # Calculate number of squares needed in x direction +n_squares_x = ( + int(1.0 / square_size_x) + 1 +) # Calculate number of squares needed in x direction # Create alpha mask with Gaussian fade -x = np.linspace(-2, 2, n_squares_x -) +x = np.linspace(-2, 2, n_squares_x) y = np.linspace(-2, 2, n_squares_y) X, Y = np.meshgrid(x, y) R = np.sqrt(X**2 + Y**2) -alpha = np.exp(-R**2/0.75) # Adjust the 1.0 to control fade rate +alpha = np.exp(-(R**2) / 0.75) # Adjust the 1.0 to control fade rate alpha = gaussian_filter(alpha, sigma=0.5) # Adjust sigma for smoothness # Create colormap gradient @@ -77,29 +84,29 @@ for i in range(n_squares_x): for j in range(n_squares_y): if (i + j) % 2 == 0: # Checkerboard pattern - color = cmap(i/n_squares_x) # Color varies along x-axis + color = cmap(i / n_squares_x) # Color varies along x-axis rect = Rectangle( - (i*square_size_x - 0.3, j*square_size_y + 0.075), - square_size_x, square_size_y, + (i * square_size_x - 0.3, j * square_size_y + 0.075), + square_size_x, + square_size_y, facecolor=color, alpha=alpha[j, i], - transform=ax.transAxes + transform=ax.transAxes, ) ax.add_patch(rect) - fig.savefig( "UltraPlotLogo.svg", - transparent = True, - bbox_inches = "tight", - ) + transparent=True, + bbox_inches="tight", +) fig.savefig( "UltraPlotLogo.png", - transparent = True, - bbox_inches = "tight", - ) + transparent=True, + bbox_inches="tight", +) fig.show() @@ -107,39 +114,47 @@ import ultraplot as plt, numpy as np from matplotlib.font_manager import FontProperties -from matplotlib import patheffects as pe +from matplotlib import patheffects as pe from matplotlib.patches import Rectangle from scipy.ndimage import gaussian_filter -font = FontProperties(fname='./PermanentMarker-Regular.ttf') +font = FontProperties(fname="./PermanentMarker-Regular.ttf") fs = 38 left = 0.5 sw = 3 -fig, ax = plt.subplots(figsize = (2, 2)) -ax.text(left, 0.52, "Ultra", - fontsize = fs, - fontproperties = font, - va = "bottom", - ha = "center", - color = "steelblue", - path_effects = [ - pe.Stroke(linewidth = sw, foreground = "white"), +fig, ax = plt.subplots(figsize=(2, 2)) +ax.text( + left, + 0.52, + "Ultra", + fontsize=fs, + fontproperties=font, + va="bottom", + ha="center", + color="steelblue", + path_effects=[ + pe.Stroke(linewidth=sw, foreground="white"), pe.Normal(), ], - transform = ax.transAxes) -ax.text(left, 0.48, "Plot", - fontsize = fs, + transform=ax.transAxes, +) +ax.text( + left, + 0.48, + "Plot", + fontsize=fs, # fontproperties = font, - va = "top", - ha = "center", - color = "white", - path_effects = [ - pe.Stroke(linewidth = sw, foreground = "steelblue"), - pe.Normal(), + va="top", + ha="center", + color="white", + path_effects=[ + pe.Stroke(linewidth=sw, foreground="steelblue"), + pe.Normal(), ], - transform = ax.transAxes) + transform=ax.transAxes, +) shift = 0.033 import colorengine as ce @@ -160,15 +175,16 @@ square_size_y = 0.1 # Base square size in y direction square_size_x = square_size_y / fig_aspect # Adjust x size to maintain square shape -n_squares_x = int(1.0 / square_size_x) + 1 # Calculate number of squares needed in x direction +n_squares_x = ( + int(1.0 / square_size_x) + 1 +) # Calculate number of squares needed in x direction # Create alpha mask with Gaussian fade -x = np.linspace(-2, 2, n_squares_x -) +x = np.linspace(-2, 2, n_squares_x) y = np.linspace(-2, 2, n_squares_y) X, Y = np.meshgrid(x, y) R = np.sqrt(X**2 + Y**2) -alpha = np.exp(-R**2/0.75) # Adjust the 1.0 to control fade rate +alpha = np.exp(-(R**2) / 0.75) # Adjust the 1.0 to control fade rate alpha = gaussian_filter(alpha, sigma=0.5) # Adjust sigma for smoothness # Create colormap gradient @@ -177,21 +193,21 @@ for i in range(n_squares_x): for j in range(n_squares_y): if (i + j) % 2 == 0: # Checkerboard pattern - color = cmap(i/n_squares_x) # Color varies along x-axis + color = cmap(i / n_squares_x) # Color varies along x-axis rect = Rectangle( - (i*square_size_x, j*square_size_y + 0.075), - square_size_x, square_size_y, + (i * square_size_x, j * square_size_y + 0.075), + square_size_x, + square_size_y, facecolor=color, alpha=alpha[j, i], - transform=ax.transAxes + transform=ax.transAxes, ) ax.add_patch(rect) - fig.savefig( "UltraPlotLogoSquare.png", - transparent = True, - bbox_inches = "tight", - ) + transparent=True, + bbox_inches="tight", +) fig.show() From 0bb4627add78f5d668fe382f672a6120542b1521 Mon Sep 17 00:00:00 2001 From: beckermr Date: Wed, 29 Jan 2025 05:59:05 -0600 Subject: [PATCH 7/7] doc: add pre-commit to readme --- README.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index dc6b79c7e..4d6612ea2 100644 --- a/README.rst +++ b/README.rst @@ -1,7 +1,7 @@ .. image:: UltraPlotLogo.svg :width: 100% -|build-status| |docs| |pypi| |code-style| |pr-welcome| |license| +|build-status| |docs| |pypi| |code-style| |pre-commit| |pr-welcome| |license| A succinct `matplotlib `__ wrapper for making beautiful, publication-quality graphics. It builds upon ProPlot_ and transports it into the modern age (supporting mpl 3.9.0+). @@ -63,3 +63,7 @@ inside the ``ultraplot`` folder. .. |license| image:: https://img.shields.io/github/license/ultraplot/ultraplot.svg :alt: license :target: LICENSE.txt + +.. |pre-commit| image:: https://results.pre-commit.ci/badge/github/Ultraplot/ultraplot/main.svg + :target: https://results.pre-commit.ci/latest/github/Ultraplot/ultraplot/main + :alt: pre-commit.ci status