From ed5cc389d72c2026517997f8d5caad144ca5f2ca Mon Sep 17 00:00:00 2001 From: Max Jones <14077947+maxrjones@users.noreply.github.com> Date: Fri, 12 Apr 2024 18:36:54 -0400 Subject: [PATCH 1/7] Update gitignore --- .gitignore | 137 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..29c61a5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,137 @@ +processed/ +.DS_Store + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST +carbonplan_data/_version.py + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# web +.next +node_modules From 3e5291a5186d466a21ce31e8c6e1e07138f2bab0 Mon Sep 17 00:00:00 2001 From: Max Jones <14077947+maxrjones@users.noreply.github.com> Date: Tue, 16 Apr 2024 15:13:57 -0400 Subject: [PATCH 2/7] Update pre-commit --- .pre-commit-config.yaml | 49 +++++++--- carbonplan_styles/__init__.py | 2 +- carbonplan_styles/altair.py | 113 ++++++++++++---------- carbonplan_styles/colors.py | 66 ++++++------- carbonplan_styles/mpl/__init__.py | 127 ++++++++++++++----------- carbonplan_styles/mpl/colormaps.py | 10 +- carbonplan_styles/tests/test_altair.py | 2 +- carbonplan_styles/tests/test_mpl.py | 66 ++++++------- demo/theme_demo.ipynb | 28 +++--- setup.py | 56 +++++------ 10 files changed, 280 insertions(+), 239 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2c94aa5..3f717b1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,35 +1,54 @@ +ci: + autoupdate_schedule: yearly + repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.6.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer - id: check-docstring-first - id: check-json - id: check-yaml - - id: double-quote-string-fixer + - id: debug-statements + - id: mixed-line-ending + + - repo: https://github.com/asottile/pyupgrade + rev: v3.15.2 + hooks: + - id: pyupgrade + args: + - "--py38-plus" - repo: https://github.com/psf/black - rev: 23.3.0 + rev: 24.3.0 hooks: - id: black - args: ["--line-length", "100", "--skip-string-normalization"] + - id: black-jupyter - - repo: https://github.com/PyCQA/flake8 - rev: 6.0.0 + - repo: https://github.com/keewis/blackdoc + rev: v0.3.9 hooks: - - id: flake8 - - repo: https://github.com/asottile/seed-isort-config - rev: v2.2.0 + - id: blackdoc + + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: "v0.3.5" hooks: - - id: seed-isort-config - - repo: https://github.com/PyCQA/isort - rev: 5.12.0 + - id: ruff + args: ["--fix"] + + - repo: https://github.com/pre-commit/mirrors-prettier + rev: v4.0.0-alpha.8 hooks: - - id: isort + - id: prettier - repo: https://github.com/pre-commit/mirrors-prettier - rev: v3.0.0-alpha.9-for-vscode + rev: "v4.0.0-alpha.8" hooks: - id: prettier - language_version: system + name: prettier-markdown + entry: prettier --write --parser mdx + files: "\\.(\ + |md|markdown|mdown|mkdn\ + |mdx\ + )$" diff --git a/carbonplan_styles/__init__.py b/carbonplan_styles/__init__.py index 50d4d55..7baa003 100644 --- a/carbonplan_styles/__init__.py +++ b/carbonplan_styles/__init__.py @@ -5,7 +5,7 @@ try: version = get_distribution(__name__).version except DistributionNotFound: # pragma: no cover - version = '0.0.0' # pragma: no cover + version = "0.0.0" # pragma: no cover __version__ = version diff --git a/carbonplan_styles/altair.py b/carbonplan_styles/altair.py index 8153325..a2c79d7 100644 --- a/carbonplan_styles/altair.py +++ b/carbonplan_styles/altair.py @@ -1,60 +1,65 @@ -font = 'relative-mono-11-pitch-pro, Menlo, monospace' -labelfont = 'relative-mono-11-pitch-pro, Menlo, monospace' -sourcefont = 'relative-mono-11-pitch-pro, Menlo, monospace' +font = "relative-mono-11-pitch-pro, Menlo, monospace" +labelfont = "relative-mono-11-pitch-pro, Menlo, monospace" +sourcefont = "relative-mono-11-pitch-pro, Menlo, monospace" def theme(colors): - markColor = colors['text'] - axisColor = colors['text'] - gridColor = colors['grey'] - backgroundColor = colors['background'] + markColor = colors["text"] + axisColor = colors["text"] + gridColor = colors["grey"] + backgroundColor = colors["background"] fontWeight = 400 symbolSize = 200 axis = { - 'domainColor': gridColor, - 'gridColor': gridColor, - 'tickColor': gridColor, - 'labelFont': labelfont, - 'titleFont': font, - 'labelColor': axisColor, - 'titleColor': axisColor, + "domainColor": gridColor, + "gridColor": gridColor, + "tickColor": gridColor, + "labelFont": labelfont, + "titleFont": font, + "labelColor": axisColor, + "titleColor": axisColor, } return { - 'config': { - 'arc': {'fill': markColor}, - 'area': {'fill': markColor}, - 'axisX': {'grid': False}, - 'axisY': {'grid': False}, - 'axisBottom': axis, - 'axisLeft': axis, - 'view': {'stroke': None}, - 'background': backgroundColor, - 'group': {'fill': backgroundColor}, - 'legend': { - 'labelFont': labelfont, - 'symbolSize': symbolSize, - 'symbolType': 'circle', - 'titleFont': font, + "config": { + "arc": {"fill": markColor}, + "area": {"fill": markColor}, + "axisX": {"grid": False}, + "axisY": {"grid": False}, + "axisBottom": axis, + "axisLeft": axis, + "view": {"stroke": None}, + "background": backgroundColor, + "group": {"fill": backgroundColor}, + "legend": { + "labelFont": labelfont, + "symbolSize": symbolSize, + "symbolType": "circle", + "titleFont": font, }, - 'line': {'color': markColor, 'stroke': markColor}, - 'trail': {'color': markColor, 'stroke': markColor}, - 'path': {'stroke': markColor}, - 'point': {'filled': True, 'color': markColor, 'size': symbolSize, 'cursor': 'pointer'}, - 'range': { - 'category': [ + "line": {"color": markColor, "stroke": markColor}, + "trail": {"color": markColor, "stroke": markColor}, + "path": {"stroke": markColor}, + "point": { + "filled": True, + "color": markColor, + "size": symbolSize, + "cursor": "pointer", + }, + "range": { + "category": [ colors[c] for c in [ - 'blue', - 'orange', - 'green', - 'red', - 'purple', - 'pink', - 'grey', - 'yellow', - 'teal', + "blue", + "orange", + "green", + "red", + "purple", + "pink", + "grey", + "yellow", + "teal", ] ], # TODO. @@ -77,26 +82,30 @@ def theme(colors): # "#e4007c", # ], }, - 'symbol': {'shape': 'circle'}, - 'style': { - 'bar': {'fill': markColor}, - 'text': {'font': sourcefont, 'fontWeight': fontWeight}, + "symbol": {"shape": "circle"}, + "style": { + "bar": {"fill": markColor}, + "text": {"font": sourcefont, "fontWeight": fontWeight}, + }, + "title": {"anchor": "start", "fontWeight": fontWeight, "font": font}, + "header": { + "fontWeight": fontWeight, + "labelFont": labelfont, + "titleFont": font, }, - 'title': {'anchor': 'start', 'fontWeight': fontWeight, 'font': font}, - 'header': {'fontWeight': fontWeight, 'labelFont': labelfont, 'titleFont': font}, }, } def dark(): - '''CarbonPlan dark theme entrypoint''' + """CarbonPlan dark theme entrypoint""" from .colors import dark return theme(dark) def light(): - '''CarbonPlan light theme entrypoint''' + """CarbonPlan light theme entrypoint""" from .colors import light return theme(light) diff --git a/carbonplan_styles/colors.py b/carbonplan_styles/colors.py index b8da60a..c49c9cc 100644 --- a/carbonplan_styles/colors.py +++ b/carbonplan_styles/colors.py @@ -1,45 +1,45 @@ dark = { - 'text': '#ebebec', - 'background': '#1b1e23', - 'primary': '#e4e4e4', - 'secondary': '#808080', - 'muted': '#363a3e', - 'red': '#f07071', - 'orange': '#ea9755', - 'yellow': '#d4c05e', - 'green': '#7eb36a', - 'teal': '#64b9c4', - 'blue': '#85a2f7', - 'purple': '#bc85d9', - 'pink': '#e587b6', - 'grey': '#a9b4c4', + "text": "#ebebec", + "background": "#1b1e23", + "primary": "#e4e4e4", + "secondary": "#808080", + "muted": "#363a3e", + "red": "#f07071", + "orange": "#ea9755", + "yellow": "#d4c05e", + "green": "#7eb36a", + "teal": "#64b9c4", + "blue": "#85a2f7", + "purple": "#bc85d9", + "pink": "#e587b6", + "grey": "#a9b4c4", } light = { - 'text': '#1b1e23', - 'background': '#FFFFFF', - 'primary': '#1b1e23', - 'secondary': '#808080', - 'muted': '#b0afb1', - 'red': '#f07071', - 'orange': '#ea9755', - 'yellow': '#d4c05e', - 'green': '#7eb36a', - 'teal': '#64b9c4', - 'blue': '#85a2f7', - 'purple': '#bc85d9', - 'pink': '#e587b6', - 'grey': '#a9b4c4', + "text": "#1b1e23", + "background": "#FFFFFF", + "primary": "#1b1e23", + "secondary": "#808080", + "muted": "#b0afb1", + "red": "#f07071", + "orange": "#ea9755", + "yellow": "#d4c05e", + "green": "#7eb36a", + "teal": "#64b9c4", + "blue": "#85a2f7", + "purple": "#bc85d9", + "pink": "#e587b6", + "grey": "#a9b4c4", } -def colors(mode='dark'): - if mode in ['dark', 'carbonplan_dark']: +def colors(mode="dark"): + if mode in ["dark", "carbonplan_dark"]: return dark - elif mode in ['light', 'carbonplan_light']: + elif mode in ["light", "carbonplan_light"]: return light else: - raise ValueError('unknown color mode %s' % mode) + raise ValueError("unknown color mode %s" % mode) def hex_to_rgb(hex): @@ -60,7 +60,7 @@ def hex_to_rgb(hex): ---------- https://towardsdatascience.com/beautiful-custom-colormaps-with-matplotlib-5bab3d1f0e72 """ - hex = hex.strip('#') # removes hash symbol if present + hex = hex.strip("#") # removes hash symbol if present lv = len(hex) return tuple(int(hex[i : i + lv // 3], 16) for i in range(0, lv, lv // 3)) diff --git a/carbonplan_styles/mpl/__init__.py b/carbonplan_styles/mpl/__init__.py index ff85b3e..4865662 100644 --- a/carbonplan_styles/mpl/__init__.py +++ b/carbonplan_styles/mpl/__init__.py @@ -8,65 +8,79 @@ from ..colors import colors, hex_to_rgb, rgb_to_dec from . import colormaps # noqa -palette_colors = ['blue', 'orange', 'green', 'red', 'purple', 'pink', 'grey', 'yellow', 'teal'] +palette_colors = [ + "blue", + "orange", + "green", + "red", + "purple", + "pink", + "grey", + "yellow", + "teal", +] def get_style_config(mode): c = colors(mode=mode) - if mode == 'light': - background = 'white' # instead of c['background'] + if mode == "light": + background = "white" # instead of c['background'] else: - background = c['background'] + background = c["background"] style = { - 'axes.facecolor': background, - 'axes.edgecolor': c['secondary'], - 'axes.grid': False, - 'axes.axisbelow': True, - 'axes.labelcolor': c['text'], - 'figure.facecolor': background, - 'grid.color': c['secondary'], - 'grid.linestyle': '-', - 'text.color': c['text'], - 'xtick.color': c['secondary'], - 'ytick.color': c['secondary'], - 'xtick.labelcolor': c['blue'], - 'ytick.labelcolor': c['blue'], - 'xtick.direction': 'out', - 'ytick.direction': 'out', - 'lines.markeredgewidth': 0.0, - 'lines.solid_capstyle': 'round', - 'patch.edgecolor': c['secondary'], - 'patch.force_edgecolor': True, - 'image.cmap': 'cool_light', - 'font.weight': '400', - 'font.family': 'monospace', - 'font.monospace': ['relative-mono-11-pitch-pro', 'Menlo', 'monospace'], - 'font.sans-serif': [ - 'relative-book-pro', - 'Roboto', - 'system-ui', - '-apple-system', - 'BlinkMacSystemFont', + "axes.facecolor": background, + "axes.edgecolor": c["secondary"], + "axes.grid": False, + "axes.axisbelow": True, + "axes.labelcolor": c["text"], + "figure.facecolor": background, + "grid.color": c["secondary"], + "grid.linestyle": "-", + "text.color": c["text"], + "xtick.color": c["secondary"], + "ytick.color": c["secondary"], + "xtick.labelcolor": c["blue"], + "ytick.labelcolor": c["blue"], + "xtick.direction": "out", + "ytick.direction": "out", + "lines.markeredgewidth": 0.0, + "lines.solid_capstyle": "round", + "patch.edgecolor": c["secondary"], + "patch.force_edgecolor": True, + "image.cmap": "cool_light", + "font.weight": "400", + "font.family": "monospace", + "font.monospace": ["relative-mono-11-pitch-pro", "Menlo", "monospace"], + "font.sans-serif": [ + "relative-book-pro", + "Roboto", + "system-ui", + "-apple-system", + "BlinkMacSystemFont", ], - 'xtick.bottom': True, - 'xtick.top': False, - 'ytick.left': True, - 'ytick.right': False, - 'axes.spines.left': True, - 'axes.spines.bottom': True, - 'axes.spines.right': False, - 'axes.spines.top': False, - 'scatter.marker': 'o', - 'scatter.edgecolors': None, + "xtick.bottom": True, + "xtick.top": False, + "ytick.left": True, + "ytick.right": False, + "axes.spines.left": True, + "axes.spines.bottom": True, + "axes.spines.right": False, + "axes.spines.top": False, + "scatter.marker": "o", + "scatter.edgecolors": None, } return style, c def set_theme( - context='notebook', style='carbonplan_light', font='monospace', font_scale=1, rc=None + context="notebook", + style="carbonplan_light", + font="monospace", + font_scale=1, + rc=None, ): """Set multiple theme parameters in one step. @@ -93,7 +107,7 @@ def set_theme( # set style style_dict, colors_dict = get_style_config(style) - sns.set_style(style_dict, rc={'font.family': font}) + sns.set_style(style_dict, rc={"font.family": font}) # set color palette c = [colors_dict[k] for k in palette_colors] @@ -127,12 +141,12 @@ def get_continuous_cmap(hex_list, float_list=None, name=None): """ warnings.warn( - 'get_continuous_cmap is deprecated, use carbonplan_styles.mpl.colormaps instead', + "get_continuous_cmap is deprecated, use carbonplan_styles.mpl.colormaps instead", DeprecationWarning, ) if name is None: - name = '-'.join(hex_list) + name = "-".join(hex_list) rgb_list = [rgb_to_dec(hex_to_rgb(i)) for i in hex_list] @@ -142,9 +156,10 @@ def get_continuous_cmap(hex_list, float_list=None, name=None): float_list = list(np.linspace(0, 1, len(rgb_list))) cdict = dict() - for num, col in enumerate(['red', 'green', 'blue']): + for num, col in enumerate(["red", "green", "blue"]): cdict[col] = [ - [float_list[i], rgb_list[i][num], rgb_list[i][num]] for i in range(len(float_list)) + [float_list[i], rgb_list[i][num], rgb_list[i][num]] + for i in range(len(float_list)) ] cmap = mcolors.LinearSegmentedColormap(name, segmentdata=cdict, N=256) @@ -153,13 +168,13 @@ def get_continuous_cmap(hex_list, float_list=None, name=None): def get_colormap(name): warnings.warn( - 'get_colormap is deprecated, use carbonplan_styles.mpl.colormaps instead', + "get_colormap is deprecated, use carbonplan_styles.mpl.colormaps instead", DeprecationWarning, ) - if name == 'blues': - return get_continuous_cmap(['#CFE0F9', '#588EF9', '#0432A5']) - elif name == 'pinks': - return get_continuous_cmap(['#F9C7ED', '#E563BA', '#770361']) - elif name == 'reds': - return get_continuous_cmap(['#F9D3BD', '#E87A3D', '#752003']) + if name == "blues": + return get_continuous_cmap(["#CFE0F9", "#588EF9", "#0432A5"]) + elif name == "pinks": + return get_continuous_cmap(["#F9C7ED", "#E563BA", "#770361"]) + elif name == "reds": + return get_continuous_cmap(["#F9D3BD", "#E87A3D", "#752003"]) diff --git a/carbonplan_styles/mpl/colormaps.py b/carbonplan_styles/mpl/colormaps.py index 216d909..cde088d 100644 --- a/carbonplan_styles/mpl/colormaps.py +++ b/carbonplan_styles/mpl/colormaps.py @@ -8,19 +8,19 @@ mod_dir = pathlib.Path(__file__).parent.parent -@functools.lru_cache() +@functools.lru_cache def colormaps(): - '''return a dictionary of colormaps''' + """return a dictionary of colormaps""" - with open(mod_dir / 'data' / 'colormaps.json', mode='r') as f: + with open(mod_dir / "data" / "colormaps.json") as f: data = json.load(f) cmaps = {} for k, v in data.items(): - key = k.replace('-', '_') + key = k.replace("-", "_") cmaps[key] = ListedColormap(v, name=key) - key_r = key + '_r' + key_r = key + "_r" cmaps[key_r] = cmaps[key].reversed() return cmaps diff --git a/carbonplan_styles/tests/test_altair.py b/carbonplan_styles/tests/test_altair.py index 7a9516c..703c4de 100644 --- a/carbonplan_styles/tests/test_altair.py +++ b/carbonplan_styles/tests/test_altair.py @@ -2,7 +2,7 @@ import pytest -@pytest.mark.parametrize('theme', ['carbonplan_dark', 'carbonplan_light']) +@pytest.mark.parametrize("theme", ["carbonplan_dark", "carbonplan_light"]) def test_enable_theme(theme): assert theme in alt.themes.names() assert alt.themes.enable(theme) diff --git a/carbonplan_styles/tests/test_mpl.py b/carbonplan_styles/tests/test_mpl.py index 0ddf485..8b8ec9c 100644 --- a/carbonplan_styles/tests/test_mpl.py +++ b/carbonplan_styles/tests/test_mpl.py @@ -7,49 +7,49 @@ from carbonplan_styles.mpl import colormaps, set_theme -@pytest.mark.parametrize('style', ['carbonplan_dark', 'carbonplan_light']) +@pytest.mark.parametrize("style", ["carbonplan_dark", "carbonplan_light"]) def test_set_style(style): set_theme(style=style) def test_colormaps(): base_names = [ - 'reds', - 'oranges', - 'yellows', - 'greens', - 'teals', - 'blues', - 'purples', - 'pinks', - 'greys', - 'fire', - 'earth', - 'water', - 'heart', - 'wind', - 'warm', - 'cool', - 'pinkgreen', - 'redteal', - 'orangeblue', - 'yellowpurple', - 'redgrey', - 'orangegrey', - 'yellowgrey', - 'greengrey', - 'tealgrey', - 'bluegrey', - 'purplegrey', - 'pinkgrey', - 'rainbow', - 'sinebow', + "reds", + "oranges", + "yellows", + "greens", + "teals", + "blues", + "purples", + "pinks", + "greys", + "fire", + "earth", + "water", + "heart", + "wind", + "warm", + "cool", + "pinkgreen", + "redteal", + "orangeblue", + "yellowpurple", + "redgrey", + "orangegrey", + "yellowgrey", + "greengrey", + "tealgrey", + "bluegrey", + "purplegrey", + "pinkgrey", + "rainbow", + "sinebow", ] explicit_cmaps = colormaps.colormaps() - for pieces in itertools.product(base_names, ['_light', '_dark'], '', '_r'): - cmap_name = ''.join(pieces) + for pieces in itertools.product(base_names, ["_light", "_dark"], "", "_r"): + cmap_name = "".join(pieces) exp_cmap = explicit_cmaps[cmap_name] assert isinstance(exp_cmap, ListedColormap) diff --git a/demo/theme_demo.ipynb b/demo/theme_demo.ipynb index 2a21b18..f4c542c 100644 --- a/demo/theme_demo.ipynb +++ b/demo/theme_demo.ipynb @@ -61,7 +61,7 @@ "source": [ "from carbonplan_styles.colors import colors\n", "\n", - "c = colors(mode='light')\n", + "c = colors(mode=\"light\")\n", "c" ] }, @@ -89,7 +89,7 @@ "from carbonplan_styles.mpl.colormaps import colormaps\n", "\n", "# print all CarbonPlan colormaps\n", - "print(list(colormaps()))\n" + "print(list(colormaps()))" ] }, { @@ -122,7 +122,7 @@ ], "source": [ "# after importing `carbonplan_styles.mpl`, any of the CarbonPlan colormaps can be used in matplotlib\n", - "plt.pcolor(np.random.random((10, 10)), cmap='redteal_light')\n", + "plt.pcolor(np.random.random((10, 10)), cmap=\"redteal_light\")\n", "plt.colorbar()" ] }, @@ -217,7 +217,9 @@ ], "source": [ "# Load some sample data\n", - "df = pd.read_csv('https://raw.githubusercontent.com/vega/vega-datasets/master/data/co2-concentration.csv')\n", + "df = pd.read_csv(\n", + " \"https://raw.githubusercontent.com/vega/vega-datasets/master/data/co2-concentration.csv\"\n", + ")\n", "df.head()" ] }, @@ -255,7 +257,7 @@ } ], "source": [ - "set_theme(style='carbonplan_dark')\n", + "set_theme(style=\"carbonplan_dark\")\n", "\n", "df.plot()" ] @@ -294,7 +296,7 @@ } ], "source": [ - "set_theme(style='carbonplan_light')\n", + "set_theme(style=\"carbonplan_light\")\n", "df.plot()" ] }, @@ -374,11 +376,9 @@ } ], "source": [ - "alt.themes.enable('carbonplan_dark')\n", + "alt.themes.enable(\"carbonplan_dark\")\n", "alt.Chart(df).mark_line().encode(\n", - " x='Date:T',\n", - " y=alt.Y('CO2:Q', scale=alt.Scale(domain=(310, 420))\n", - " )\n", + " x=\"Date:T\", y=alt.Y(\"CO2:Q\", scale=alt.Scale(domain=(310, 420)))\n", ").properties(width=350, height=250)" ] }, @@ -458,12 +458,10 @@ } ], "source": [ - "alt.themes.enable('carbonplan_light')\n", + "alt.themes.enable(\"carbonplan_light\")\n", "alt.Chart(df).mark_line().encode(\n", - " x='Date:T',\n", - " y=alt.Y('CO2:Q', scale=alt.Scale(domain=(310, 420))\n", - " )\n", - ").properties(width=350, height=250)\n" + " x=\"Date:T\", y=alt.Y(\"CO2:Q\", scale=alt.Scale(domain=(310, 420)))\n", + ").properties(width=350, height=250)" ] }, { diff --git a/setup.py b/setup.py index 666e5ed..b565cf7 100644 --- a/setup.py +++ b/setup.py @@ -2,53 +2,53 @@ from setuptools import find_packages, setup -with open('requirements.txt') as f: - install_requires = f.read().strip().split('\n') +with open("requirements.txt") as f: + install_requires = f.read().strip().split("\n") -if os.path.exists('README.md'): - with open('README.md') as f: +if os.path.exists("README.md"): + with open("README.md") as f: long_description = f.read() else: - long_description = '' + long_description = "" CLASSIFIERS = [ - 'Development Status :: 2 - Pre-Alpha', - 'License :: OSI Approved :: MIT License', - 'Operating System :: OS Independent', - 'Intended Audience :: Science/Research', - 'Programming Language :: Python', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Topic :: Scientific/Engineering', + "Development Status :: 2 - Pre-Alpha", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Intended Audience :: Science/Research", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Topic :: Scientific/Engineering", ] ENTRY_POINTS = { - 'altair.vegalite.v4.theme': [ - 'carbonplan_dark = carbonplan_styles.altair:dark', - 'carbonplan_light = carbonplan_styles.altair:light', + "altair.vegalite.v4.theme": [ + "carbonplan_dark = carbonplan_styles.altair:dark", + "carbonplan_light = carbonplan_styles.altair:light", ], } setup( - name='carbonplan-styles', - description='CarbonPlan plotting styles', + name="carbonplan-styles", + description="CarbonPlan plotting styles", long_description=long_description, - long_description_content_type='text/markdown', - python_requires='>=3.7', - maintainer='CarbonPlan', - maintainer_email='tech@carbonplan.org', - url='https://github.com/carbonplan/styles', - license='MIT', + long_description_content_type="text/markdown", + python_requires=">=3.7", + maintainer="CarbonPlan", + maintainer_email="tech@carbonplan.org", + url="https://github.com/carbonplan/styles", + license="MIT", packages=find_packages(), include_package_data=True, entry_points=ENTRY_POINTS, install_requires=install_requires, - keywords=['matplotlib', 'altair'], + keywords=["matplotlib", "altair"], classifiers=CLASSIFIERS, - use_scm_version={'version_scheme': 'post-release', 'local_scheme': 'dirty-tag'}, - setup_requires=['setuptools_scm', 'setuptools>=30.3.0'], + use_scm_version={"version_scheme": "post-release", "local_scheme": "dirty-tag"}, + setup_requires=["setuptools_scm", "setuptools>=30.3.0"], ) From 6db41c955b26cdcaca1179db5bead461d688bf2e Mon Sep 17 00:00:00 2001 From: Max Jones <14077947+maxrjones@users.noreply.github.com> Date: Tue, 16 Apr 2024 16:12:23 -0400 Subject: [PATCH 3/7] Update packaging structure --- .isort.cfg | 2 - carbonplan_styles/mpl/__init__.py | 3 +- dev-requirements.txt | 4 -- pyproject.toml | 114 ++++++++++++++++++++++++++++++ requirements.txt | 4 -- setup.cfg | 22 ------ setup.py | 54 -------------- 7 files changed, 115 insertions(+), 88 deletions(-) delete mode 100644 .isort.cfg delete mode 100644 dev-requirements.txt create mode 100644 pyproject.toml delete mode 100644 requirements.txt delete mode 100644 setup.cfg delete mode 100644 setup.py diff --git a/.isort.cfg b/.isort.cfg deleted file mode 100644 index 9657836..0000000 --- a/.isort.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[settings] -known_third_party = altair,matplotlib,numpy,pkg_resources,pytest,seaborn,setuptools diff --git a/carbonplan_styles/mpl/__init__.py b/carbonplan_styles/mpl/__init__.py index 4865662..b99e515 100644 --- a/carbonplan_styles/mpl/__init__.py +++ b/carbonplan_styles/mpl/__init__.py @@ -158,8 +158,7 @@ def get_continuous_cmap(hex_list, float_list=None, name=None): cdict = dict() for num, col in enumerate(["red", "green", "blue"]): cdict[col] = [ - [float_list[i], rgb_list[i][num], rgb_list[i][num]] - for i in range(len(float_list)) + [float_list[i], rgb_list[i][num], rgb_list[i][num]] for i in range(len(float_list)) ] cmap = mcolors.LinearSegmentedColormap(name, segmentdata=cdict, N=256) diff --git a/dev-requirements.txt b/dev-requirements.txt deleted file mode 100644 index 22f1f21..0000000 --- a/dev-requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -pytest -pytest-sugar -pytest-cov --r requirements.txt diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..9721867 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,114 @@ +[build-system] +requires = ["setuptools>=64", "setuptools-scm[toml]>=6.2", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "carbonplan-styles" +description = "CarbonPlan plotting styles" +readme = "README.md" +license = { text = "MIT" } +authors = [{ name = "CarbonPlan", email = "tech@carbonplan.org" }] +requires-python = ">=3.9" +keywords=["matplotlib", "altair"] +classifiers = [ + "Development Status :: 2 - Pre-Alpha", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Intended Audience :: Science/Research", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Topic :: Scientific/Engineering", +] +dynamic = ["version"] + +dependencies = [ + "altair", + "carbonplan", + "matplotlib", + "seaborn", +] + +[project.optional-dependencies] +dev = ["pytest","pytest-sugar","pytest-cov"] + + +[project.entry-points."altair.vegalite.v5.theme"] +carbonplan_dark = "carbonplan_styles.altair:dark" +carbonplan_light = "carbonplan_styles.altair:light" + +[project.urls] +repository = "https://github.com/carbonplan/style" + +[tool.setuptools.packages.find] +include = ["carbonplan_styles*"] + +[tool.setuptools_scm] +local_scheme = "node-and-date" +fallback_version = "999" + + +[tool.black] +line-length = 100 +target-version = ['py39'] +skip-string-normalization = true + + +[tool.ruff] +line-length = 100 +target-version = "py39" +builtins = ["ellipsis"] +# Exclude a variety of commonly ignored directories. +exclude = [ + ".bzr", + ".direnv", + ".eggs", + ".git", + ".hg", + ".mypy_cache", + ".nox", + ".pants.d", + ".ruff_cache", + ".svn", + ".tox", + ".venv", + "__pypackages__", + "_build", + "buck-out", + "build", + "dist", + "node_modules", + "venv", +] +per-file-ignores = {} +# E402: module level import not at top of file +# E501: line too long - let black worry about that +# E731: do not assign a lambda expression, use a def +ignore = ["E402", "E501", "E731"] +select = [ + # Pyflakes + "F", + # Pycodestyle + "E", + "W", + # isort + "I", + # Pyupgrade + "UP", +] + + +[tool.ruff.mccabe] +max-complexity = 18 + +[tool.ruff.isort] +known-first-party = ["carbonplan_styles"] +known-third-party = ["altair","matplotlib","numpy","pkg_resources","pytest","seaborn","setuptools"] + + +[tool.pytest.ini_options] +console_output_style = "count" +addopts = "--cov=./ --cov-report=xml --verbose" diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index d158e73..0000000 --- a/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -altair -carbonplan -matplotlib -seaborn diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 09e3814..0000000 --- a/setup.cfg +++ /dev/null @@ -1,22 +0,0 @@ -[flake8] -exclude = docs -ignore = E203,E266,E501,W503,E722,E402,C901 -max-line-length = 100 -max-complexity = 18 -select = B,C,E,F,W,T4,B9 - -[isort] -known_first_party=xpublish -known_third_party=cachey,dask,fastapi,numcodecs,numpy,pandas,pkg_resources,pytest,setuptools,starlette,uvicorn,xarray,zarr -multi_line_output=3 -include_trailing_comma=True -force_grid_wrap=0 -combine_as_imports=True -line_length=100 -skip= - docs/source/conf.py - setup.py - .binder/test.py - -[tool:pytest] -log_cli = True diff --git a/setup.py b/setup.py deleted file mode 100644 index b565cf7..0000000 --- a/setup.py +++ /dev/null @@ -1,54 +0,0 @@ -import os - -from setuptools import find_packages, setup - -with open("requirements.txt") as f: - install_requires = f.read().strip().split("\n") - - -if os.path.exists("README.md"): - with open("README.md") as f: - long_description = f.read() -else: - long_description = "" - - -CLASSIFIERS = [ - "Development Status :: 2 - Pre-Alpha", - "License :: OSI Approved :: MIT License", - "Operating System :: OS Independent", - "Intended Audience :: Science/Research", - "Programming Language :: Python", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Topic :: Scientific/Engineering", -] - -ENTRY_POINTS = { - "altair.vegalite.v4.theme": [ - "carbonplan_dark = carbonplan_styles.altair:dark", - "carbonplan_light = carbonplan_styles.altair:light", - ], -} - - -setup( - name="carbonplan-styles", - description="CarbonPlan plotting styles", - long_description=long_description, - long_description_content_type="text/markdown", - python_requires=">=3.7", - maintainer="CarbonPlan", - maintainer_email="tech@carbonplan.org", - url="https://github.com/carbonplan/styles", - license="MIT", - packages=find_packages(), - include_package_data=True, - entry_points=ENTRY_POINTS, - install_requires=install_requires, - keywords=["matplotlib", "altair"], - classifiers=CLASSIFIERS, - use_scm_version={"version_scheme": "post-release", "local_scheme": "dirty-tag"}, - setup_requires=["setuptools_scm", "setuptools>=30.3.0"], -) From 763fb817e7bd7f524da5a61a258c0b0dc390a0fa Mon Sep 17 00:00:00 2001 From: Max Jones <14077947+maxrjones@users.noreply.github.com> Date: Tue, 16 Apr 2024 16:15:05 -0400 Subject: [PATCH 4/7] Update test workflow --- .github/workflows/main.yaml | 39 +++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 69d8ae6..bd08dba 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -15,26 +15,31 @@ jobs: name: ${{ matrix.python-version }}-build runs-on: ubuntu-latest strategy: + fail-fast: false matrix: - python-version: ["3.8", "3.9", "3.10"] + python-version: ["3.9", "3.10", "3.11", "3.12"] steps: - - uses: actions/checkout@v3 - - name: Setup Python - uses: actions/setup-python@v4.5.0 + - uses: actions/checkout@v4 + - name: Install Conda environment from environment.yml + uses: mamba-org/setup-micromamba@v1 with: - python-version: ${{ matrix.python-version }} - architecture: x64 - - uses: actions/cache@v3 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/dev-requirements.txt') }} - restore-keys: | - ${{ runner.os }}-pip- - - run: | - python -m pip install -r dev-requirements.txt - python -m pip install --no-deps -e . - python -m pip list - - name: Running Tests + environment-name: carbonplan + condarc: | + channels: + - conda-forge + - nodefaults + cache-downloads: false + cache-environment: true + create-args: >- + python=${{ matrix.python-version }} + - name: Install package + run: | + python -m pip install -e .[dev] + - name: Conda list information + run: | + conda env list + conda list + - name: Run tests run: | python -m pytest --junitxml=test-reports/junit.xml --cov=./ --verbose - name: Upload coverage to Codecov From e28b4a89cecc4e980f6ac58e5ecfb406c4448f99 Mon Sep 17 00:00:00 2001 From: Max Jones <14077947+maxrjones@users.noreply.github.com> Date: Tue, 16 Apr 2024 16:25:52 -0400 Subject: [PATCH 5/7] Fix pre-commit update schedule --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3f717b1..6856686 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,5 @@ ci: - autoupdate_schedule: yearly + autoupdate_schedule: quarterly repos: - repo: https://github.com/pre-commit/pre-commit-hooks From 6d3bd2ffa282b622350824f1e8652fe89fc174be Mon Sep 17 00:00:00 2001 From: Max Jones <14077947+maxrjones@users.noreply.github.com> Date: Tue, 16 Apr 2024 16:28:00 -0400 Subject: [PATCH 6/7] Update test workflow --- .github/workflows/main.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index bd08dba..0a1b9d6 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -14,6 +14,9 @@ jobs: test: name: ${{ matrix.python-version }}-build runs-on: ubuntu-latest + defaults: + run: + shell: bash -l {0} strategy: fail-fast: false matrix: From 527bf1ac270a60fb5ea29863ce9ab0887e794b75 Mon Sep 17 00:00:00 2001 From: Max Jones <14077947+maxrjones@users.noreply.github.com> Date: Tue, 16 Apr 2024 16:31:14 -0400 Subject: [PATCH 7/7] Drop Python 3.9 --- .github/workflows/main.yaml | 2 +- pyproject.toml | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 0a1b9d6..9d36709 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -20,7 +20,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.9", "3.10", "3.11", "3.12"] + python-version: ["3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v4 - name: Install Conda environment from environment.yml diff --git a/pyproject.toml b/pyproject.toml index 9721867..cb39c8b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,7 +8,7 @@ description = "CarbonPlan plotting styles" readme = "README.md" license = { text = "MIT" } authors = [{ name = "CarbonPlan", email = "tech@carbonplan.org" }] -requires-python = ">=3.9" +requires-python = ">=3.10" keywords=["matplotlib", "altair"] classifiers = [ "Development Status :: 2 - Pre-Alpha", @@ -17,7 +17,6 @@ classifiers = [ "Intended Audience :: Science/Research", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12",