From 56d4a8d6bf921e9c5304d5cc9d70695492eec566 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Fri, 3 Dec 2021 13:46:52 +0100 Subject: [PATCH 1/4] try windows tests --- .github/workflows/ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9afc7fa7..646b8556 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,9 +20,10 @@ jobs: uses: pre-commit/action@v2.0.3 build: - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} strategy: matrix: + os: [ubuntu-latest, windows-latest, macOS-latest] python-version: ["3.7", "3.8", "3.9", "3.10"] steps: - uses: actions/setup-python@v2 @@ -36,4 +37,4 @@ jobs: pip install tox tox -- --cov tikzplotlib --cov-report xml --cov-report term - uses: codecov/codecov-action@v1 - if: ${{ matrix.python-version == '3.9' }} + if: ${{ matrix.python-version == '3.10' && matrix.os == 'ubuntu-latest' }} From 0956bac68da0b94dbd4831ad762b3f3f7cd84c47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Fri, 3 Dec 2021 14:37:58 +0100 Subject: [PATCH 2/4] some fixes for filepath --- src/tikzplotlib/_files.py | 27 ++++++++++++--------------- src/tikzplotlib/_image.py | 6 +++++- src/tikzplotlib/_quadmesh.py | 3 ++- tests/test_viridis.py | 7 ++++++- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/tikzplotlib/_files.py b/src/tikzplotlib/_files.py index 55589021..51dcb872 100644 --- a/src/tikzplotlib/_files.py +++ b/src/tikzplotlib/_files.py @@ -1,9 +1,13 @@ -import pathlib +from pathlib import Path def _gen_filepath(data, nb_key, ext): - name = data["base name"] + f"-{data[nb_key]:03d}{ext}" - return pathlib.Path(data["output dir"]) / name + rel_filepath = Path(f"{data['base name']}-{data[nb_key]:03d}{ext}") + + if data["rel data path"]: + rel_filepath = Path(data["rel data path"]) / rel_filepath + + return Path(data["output dir"]) / rel_filepath, rel_filepath def new_filepath(data, file_kind, ext): @@ -25,19 +29,12 @@ def new_filepath(data, file_kind, ext): if nb_key not in data.keys(): data[nb_key] = -1 - data[nb_key] = data[nb_key] + 1 - filepath = _gen_filepath(data, nb_key, ext) + data[nb_key] += 1 + filepath, rel_filepath = _gen_filepath(data, nb_key, ext) if not data["override externals"]: # Make sure not to overwrite anything. - file_exists = filepath.is_file() - while file_exists: - data[nb_key] = data[nb_key] + 1 - filepath = _gen_filepath(data, nb_key, ext) - file_exists = filepath.is_file() - - if data["rel data path"]: - rel_filepath = pathlib.Path(data["rel data path"]) / filepath - else: - rel_filepath = filepath.name + while filepath.is_file(): + data[nb_key] += 1 + filepath, rel_filepath = _gen_filepath(data, nb_key, ext) return filepath, rel_filepath diff --git a/src/tikzplotlib/_image.py b/src/tikzplotlib/_image.py index a9bf09f8..5bfba377 100644 --- a/src/tikzplotlib/_image.py +++ b/src/tikzplotlib/_image.py @@ -52,9 +52,13 @@ def draw_image(data, obj): # Explicitly use \pgfimage as includegrapics command, as the default # \includegraphics fails unexpectedly in some cases ff = data["float format"] + # Always use slash in file paths, see + # + # + posix_filepath = rel_filepath.as_posix() content.append( "\\addplot graphics [includegraphics cmd=\\pgfimage," f"xmin={extent[0]:{ff}}, xmax={extent[1]:{ff}}, " - f"ymin={extent[2]:{ff}}, ymax={extent[3]:{ff}}] {{{rel_filepath}}};\n" + f"ymin={extent[2]:{ff}}, ymax={extent[3]:{ff}}] {{{posix_filepath}}};\n" ) return data, content diff --git a/src/tikzplotlib/_quadmesh.py b/src/tikzplotlib/_quadmesh.py index 0f4eb633..b4060a21 100644 --- a/src/tikzplotlib/_quadmesh.py +++ b/src/tikzplotlib/_quadmesh.py @@ -53,10 +53,11 @@ def draw_quadmesh(data, obj): # Explicitly use \pgfimage as includegrapics command, as the default # \includegraphics fails unexpectedly in some cases ff = data["float format"] + posix_filepath = rel_filepath.as_posix() content.append( "\\addplot graphics [includegraphics cmd=\\pgfimage," f"xmin={extent[0]:{ff}}, xmax={extent[1]:{ff}}, " - f"ymin={extent[2]:{ff}}, ymax={extent[3]:{ff}}] {{{rel_filepath}}};\n" + f"ymin={extent[2]:{ff}}, ymax={extent[3]:{ff}}] {{{posix_filepath}}};\n" ) return data, content diff --git a/tests/test_viridis.py b/tests/test_viridis.py index 7421193e..b4f8ef00 100644 --- a/tests/test_viridis.py +++ b/tests/test_viridis.py @@ -16,4 +16,9 @@ def plot(): def test(): from .helpers import assert_equality - assert_equality(plot, __file__[:-3] + "_reference.tex") + # test relative data path + assert_equality( + plot, + __file__[:-3] + "_reference.tex", + # tex_relative_path_to_data="data/files" + ) From f51e55a8f80f17869bb3f1ac82bbe3a6fc18c175 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Fri, 3 Dec 2021 14:41:40 +0100 Subject: [PATCH 3/4] more path simplifications --- src/tikzplotlib/_files.py | 4 ++-- src/tikzplotlib/_save.py | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/tikzplotlib/_files.py b/src/tikzplotlib/_files.py index 51dcb872..c9eb080f 100644 --- a/src/tikzplotlib/_files.py +++ b/src/tikzplotlib/_files.py @@ -5,9 +5,9 @@ def _gen_filepath(data, nb_key, ext): rel_filepath = Path(f"{data['base name']}-{data[nb_key]:03d}{ext}") if data["rel data path"]: - rel_filepath = Path(data["rel data path"]) / rel_filepath + rel_filepath = data["rel data path"] / rel_filepath - return Path(data["output dir"]) / rel_filepath, rel_filepath + return data["output dir"] / rel_filepath, rel_filepath def new_filepath(data, file_kind, ext): diff --git a/src/tikzplotlib/_save.py b/src/tikzplotlib/_save.py index 3efaad42..1814b729 100644 --- a/src/tikzplotlib/_save.py +++ b/src/tikzplotlib/_save.py @@ -1,9 +1,9 @@ from __future__ import annotations import enum -import pathlib import tempfile import warnings +from pathlib import Path import matplotlib as mpl import matplotlib.pyplot as plt @@ -18,7 +18,7 @@ def get_tikz_code( figure="gcf", - filepath: str | pathlib.Path | None = None, + filepath: str | Path | None = None, axis_width: str | None = None, axis_height: str | None = None, textsize: float = 10.0, @@ -152,18 +152,20 @@ def get_tikz_code( data = {} data["axis width"] = axis_width data["axis height"] = axis_height - data["rel data path"] = tex_relative_path_to_data + data["rel data path"] = ( + None if tex_relative_path_to_data is None else Path(tex_relative_path_to_data) + ) data["externalize tables"] = externalize_tables data["override externals"] = override_externals data["externals search path"] = externals_search_path if filepath: - filepath = pathlib.Path(filepath) + filepath = Path(filepath) data["output dir"] = filepath.parent data["base name"] = filepath.stem else: directory = tempfile.mkdtemp() - data["output dir"] = pathlib.Path(directory) + data["output dir"] = Path(directory) data["base name"] = "tmp" data["strict"] = strict @@ -247,7 +249,7 @@ def get_tikz_code( return code -def save(filepath: str | pathlib.Path, *args, encoding: str | None = None, **kwargs): +def save(filepath: str | Path, *args, encoding: str | None = None, **kwargs): """Same as `get_tikz_code()`, but actually saves the code to a file. :param filepath: The file to which the TikZ output will be written. From 682d565bba85a89476443b86263b284f75038a75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Fri, 3 Dec 2021 14:41:49 +0100 Subject: [PATCH 4/4] version bump --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index fb5e7dac..a7fe7267 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = tikzplotlib -version = 0.9.15 +version = 0.9.16 author = Nico Schlömer author_email = nico.schloemer@gmail.com description = Convert matplotlib figures into TikZ/PGFPlots