Skip to content

Commit 838d73d

Browse files
authored
Merge pull request #461 from nschloe/new-sphinx
New sphinx
2 parents 4fb6df4 + 7a42f37 commit 838d73d

File tree

8 files changed

+54
-149
lines changed

8 files changed

+54
-149
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2010-2020 Nico Schlömer
3+
Copyright (c) 2010-2021 Nico Schlömer
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ format:
2727
lint:
2828
black --check .
2929
flake8 .
30+
31+
doc:
32+
sphinx-build -M html doc/ build/

doc/Makefile

Lines changed: 0 additions & 89 deletions
This file was deleted.

doc/conf.py

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,46 @@
22
#
33
# This file only contains a selection of the most common options. For a full
44
# list see the documentation:
5-
# http://www.sphinx-doc.org/en/master/config
5+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
66

77
# -- Path setup --------------------------------------------------------------
88

9+
import pathlib
10+
911
# If extensions (or modules to document with autodoc) are in another directory,
1012
# add these directories to sys.path here. If the directory is relative to the
1113
# documentation root, use os.path.abspath to make it absolute, like shown here.
1214
#
13-
import os
14-
15+
# import os
1516
# import sys
1617
# sys.path.insert(0, os.path.abspath('.'))
17-
18+
from configparser import ConfigParser
1819

1920
# -- Project information -----------------------------------------------------
20-
2121
project = "tikzplotlib"
22-
copyright = "2010-2020, Nico Schlömer"
22+
copyright = "2010-2021, Nico Schlömer"
2323
author = "Nico Schlömer"
2424

25-
# https://packaging.python.org/single_source_version/
26-
this_dir = os.path.abspath(os.path.dirname(__file__))
27-
about = {}
28-
about_file = os.path.join(this_dir, "..", "tikzplotlib", "__about__.py")
29-
with open(about_file) as f:
30-
exec(f.read(), about)
31-
# The full version, including alpha/beta/rc tags.
32-
release = about["__version__"]
33-
34-
# WARNING: conf value "version" should not be empty for EPUB3
35-
version = about["__version__"]
25+
p = ConfigParser()
26+
this_dir = pathlib.Path(__file__).resolve().parent
27+
p.read(this_dir / ".." / "setup.cfg")
28+
release = p["metadata"]["version"]
3629

37-
# for sphinx 1.*
38-
master_doc = "index"
3930

4031
# -- General configuration ---------------------------------------------------
4132

4233
# Add any Sphinx extension module names here, as strings. They can be
4334
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
4435
# ones.
45-
extensions = [
46-
"sphinx.ext.autodoc",
47-
"sphinx.ext.doctest",
48-
"sphinx.ext.todo",
49-
"sphinx.ext.coverage",
50-
"sphinx.ext.imgmath",
51-
]
36+
extensions = ["sphinx.ext.autodoc"]
5237

5338
# Add any paths that contain templates here, relative to this directory.
5439
templates_path = ["_templates"]
5540

5641
# List of patterns, relative to source directory, that match files and
5742
# directories to ignore when looking for source files.
5843
# This pattern also affects html_static_path and html_extra_path.
59-
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
44+
exclude_patterns = []
6045

6146

6247
# -- Options for HTML output -------------------------------------------------

doc/index.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
.. tikzplotlib documentation master file, created by
2-
sphinx-quickstart on Tue Jul 30 11:59:20 2019.
2+
sphinx-quickstart on Thu Feb 4 12:49:27 2021.
33
You can adapt this file completely to your liking, but it should at least
44
contain the root `toctree` directive.
55
66
Welcome to tikzplotlib's documentation!
7-
===========================================
8-
9-
Contents:
7+
=======================================
108

119
.. toctree::
1210
:maxdepth: 2
11+
:caption: Contents:
1312

1413
Methods
1514
=======

doc/requirements.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

tikzplotlib/_cleanfigure.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,26 @@
77
STEP_DRAW_STYLES = ["steps-pre", "steps-post", "steps-mid"]
88

99

10-
def clean_figure(fig=None, target_resolution=600, scale_precision=1.0):
10+
def clean_figure(fig=None, target_resolution: int = 600, scale_precision: float = 1.0):
1111
"""Cleans figure as a preparation for tikz export.
1212
This will minimize the number of points required for the tikz figure.
1313
If the figure has subplots, it will recursively clean then up.
1414
1515
Note that this function modifies the figure directly (impure function).
1616
1717
:param fig: Matplotlib figure handle (Default value = None)
18+
1819
:param target_resolution: target resolution of final figure in PPI.
19-
If a scalar integer is provided, it is assumed to be square in both axis.
20-
If a list or an np.array is provided, it is interpreted as [H, W].
21-
By default 600
20+
If a scalar integer is provided, it is assumed to be
21+
square in both axis. If a list or an np.array is
22+
provided, it is interpreted as [H, W].
23+
By default 600
2224
:type target_resolution: int, list or np.array, optional
25+
2326
:param scalePrecision: scalar value indicating precision when scaling down.
24-
By default 1
27+
By default 1
2528
:type scalePrecision: float, optional
29+
2630
Examples
2731
--------
2832

tikzplotlib/_save.py

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pathlib
44
import tempfile
55
import warnings
6+
from typing import List, Optional, Set, Union
67

78
import matplotlib as mpl
89
import matplotlib.pyplot as plt
@@ -17,26 +18,26 @@
1718

1819
def get_tikz_code(
1920
figure="gcf",
20-
filepath=None,
21-
axis_width=None,
22-
axis_height=None,
23-
textsize=10.0,
24-
tex_relative_path_to_data=None,
25-
externalize_tables=False,
26-
override_externals=False,
27-
strict=False,
28-
wrap=True,
29-
add_axis_environment=True,
30-
extra_axis_parameters=None,
31-
extra_groupstyle_parameters={},
32-
extra_tikzpicture_parameters=None,
33-
dpi=None,
34-
show_info=False,
35-
include_disclaimer=True,
36-
standalone=False,
37-
float_format=".15g",
38-
table_row_sep="\n",
39-
flavor="latex",
21+
filepath: Optional[Union[str, pathlib.Path]] = None,
22+
axis_width: Optional[str] = None,
23+
axis_height: Optional[str] = None,
24+
textsize: float = 10.0,
25+
tex_relative_path_to_data: Optional[str] = None,
26+
externalize_tables: bool = False,
27+
override_externals: bool = False,
28+
strict: bool = False,
29+
wrap: bool = True,
30+
add_axis_environment: bool = True,
31+
extra_axis_parameters: Optional[Union[List, Set]] = None,
32+
extra_groupstyle_parameters: dict = {},
33+
extra_tikzpicture_parameters: Optional[Union[List, Set]] = None,
34+
dpi: Optional[int] = None,
35+
show_info: bool = False,
36+
include_disclaimer: bool = True,
37+
standalone: bool = False,
38+
float_format: str = ".15g",
39+
table_row_sep: str = "\n",
40+
flavor: str = "latex",
4041
):
4142
"""Main function. Here, the recursion into the image starts and the
4243
contents are picked up. The actual file gets written in this routine.
@@ -156,11 +157,12 @@ def get_tikz_code(
156157
if filepath:
157158
filepath = pathlib.Path(filepath)
158159
data["output dir"] = filepath.parent
160+
data["base name"] = filepath.stem
159161
else:
160162
directory = tempfile.mkdtemp()
161163
data["output dir"] = pathlib.Path(directory)
164+
data["base name"] = "tmp"
162165

163-
data["base name"] = filepath.stem if filepath else "tmp"
164166
data["strict"] = strict
165167
data["tikz libs"] = set()
166168
data["pgfplots libs"] = set()
@@ -239,7 +241,9 @@ def get_tikz_code(
239241
return code
240242

241243

242-
def save(filepath, *args, encoding=None, **kwargs):
244+
def save(
245+
filepath: Union[str, pathlib.Path], *args, encoding: Optional[str] = None, **kwargs
246+
):
243247
"""Same as `get_tikz_code()`, but actually saves the code to a file.
244248
245249
:param filepath: The file to which the TikZ output will be written.

0 commit comments

Comments
 (0)