Skip to content

Commit

Permalink
Format w/ black (#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
jarrodmillman committed Dec 26, 2020
1 parent 106180c commit 4d1d5ee
Show file tree
Hide file tree
Showing 9 changed files with 257 additions and 186 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/lint.yml
@@ -0,0 +1,32 @@
name: style

on: [push, pull_request]

jobs:
format:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7]

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Before install
run: |
python3 -m venv ~/venv
source ~/venv/bin/activate
- name: Install packages
run: |
pip install --upgrade pip wheel setuptools
pip install -r requirements/developer.txt
pip list
- name: Lint
run: pre-commit run --all-files --show-diff-on-failure --color always
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
@@ -0,0 +1,9 @@
# Install pre-commit hooks via
# pre-commit install

repos:
- repo: https://github.com/ambv/black
rev: 20.8b1
hooks:
- id: black
exclude: graphviz.py
75 changes: 41 additions & 34 deletions doc/source/conf.py
Expand Up @@ -13,9 +13,9 @@
# coming with Sphinx (named 'sphinx.addons.*') or your custom ones.
extensions = [
"sphinx.ext.autosummary",
'sphinx.ext.autodoc',
'sphinx.ext.imgmath',
'sphinx.ext.doctest',
"sphinx.ext.autodoc",
"sphinx.ext.imgmath",
"sphinx.ext.doctest",
"sphinx.ext.intersphinx",
"sphinx.ext.mathjax",
"sphinx.ext.todo",
Expand All @@ -25,27 +25,27 @@
]

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

# The suffix of source filenames.
source_suffix = '.rst'
source_suffix = ".rst"

# The encoding of source files.
source_encoding = 'utf-8'
# The encoding of source files.
source_encoding = "utf-8"

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General substitutions.
project = 'PyGraphviz'
copyright = f'2004-{date.today().year}, PyGraphviz Developers'
project = "PyGraphviz"
copyright = f"2004-{date.today().year}, PyGraphviz Developers"

# Sphinx gallery configuration
sphinx_gallery_conf = {
"examples_dirs": "../../examples",
"gallery_dirs": "auto_examples",
"ignore_pattern": "skip_",
"image_scrapers": ('pygraphviz',),
"image_scrapers": ("pygraphviz",),
}


Expand All @@ -54,22 +54,23 @@
#
# The short X.Y version.
import pygraphviz
version =pygraphviz.__version__

version = pygraphviz.__version__
# The full version, including alpha/beta/rc tags.
release = version


# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
# today_fmt = '%B %d, %Y'

# List of documents that shouldn't be included in the build.
unused_docs = []

# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# add_function_parentheses = True

# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
Expand All @@ -78,7 +79,7 @@
show_authors = True

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"


# Options for HTML output
Expand All @@ -95,62 +96,68 @@
# The style sheet to use for HTML and HTML Help pages. A file of that name
# must exist either in Sphinx' static/ path, or in one of the custom paths
# given in html_static_path.
#html_style = 'sphinxdoc.css'
# html_style = 'sphinxdoc.css'

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
#html_static_path = ['static']
# html_static_path = ['static']

# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
html_last_updated_fmt = '%b %d, %Y'
html_last_updated_fmt = "%b %d, %Y"

# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# html_use_smartypants = True

# Content template for the index page.
html_index = 'contents.html'
html_index = "contents.html"

# Custom sidebar templates, maps page names to templates.
#html_sidebars = {'index': 'indexsidebar.html'}
# html_sidebars = {'index': 'indexsidebar.html'}

# Additional templates that should be rendered to pages, maps page names to
# templates.
#html_additional_pages = {'index': 'index.html'}
# html_additional_pages = {'index': 'index.html'}

# If true, the reST sources are included in the HTML build as _sources/<name>.
html_copy_source = False

html_use_opensearch = 'http://pygraphviz.github.io'
html_use_opensearch = "http://pygraphviz.github.io"

# Output file base name for HTML help builder.
htmlhelp_basename = 'PyGraphviz'
htmlhelp_basename = "PyGraphviz"

pngmath_use_preview = True

# Options for LaTeX output
# ------------------------

# The paper size ('letter' or 'a4').
latex_paper_size = 'letter'
latex_paper_size = "letter"

# The font size ('10pt', '11pt' or '12pt').
#latex_font_size = '10pt'
# latex_font_size = '10pt'

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, document class [howto/manual]).
latex_documents = [('index', 'pygraphviz.tex', 'PyGraphviz Documentation',
'PyGraphviz Developers', 'manual', 1)]
latex_documents = [
(
"index",
"pygraphviz.tex",
"PyGraphviz Documentation",
"PyGraphviz Developers",
"manual",
1,
)
]


#latex_use_parts = True
# latex_use_parts = True

# Additional stuff for the LaTeX preamble.
latex_elements = {
'fontpkg': '\\usepackage{palatino}'
}
latex_elements = {"fontpkg": "\\usepackage{palatino}"}

# Documents to append as an appendix to all manuals.
#latex_appendices = []
# latex_appendices = []
55 changes: 25 additions & 30 deletions doc/source/tutorial.rst
Expand Up @@ -13,11 +13,6 @@ Import PyGraphviz with

>>> import pygraphviz as pgv

or to bring into the current namespace without the "pgv" prefix

>>> from pygraphviz import *


Graphs
------

Expand All @@ -30,38 +25,38 @@ graph you want. The default is to create a strict graph
(no parallel edges or self-loops). To create a digraph with possible
parallel edges and self-loops use

>>> G=pgv.AGraph(strict=False,directed=True)
>>> G = pgv.AGraph(strict=False, directed=True)

You may specify a dot format file to be read on initialization:

>>> G=pgv.AGraph("Petersen.dot") # doctest: +SKIP
>>> G = pgv.AGraph("Petersen.dot") # doctest: +SKIP

Other options for intializing a graph are using a string,

>>> G=pgv.AGraph('graph {1 - 2}')
>>> G = pgv.AGraph("graph {1 - 2}")

using a dict of dicts,

>>> d={'1': {'2': None}, '2': {'1': None, '3': None}, '3': {'2': None}}
>>> A=pgv.AGraph(d)
>>> d = {"1": {"2": None}, "2": {"1": None, "3": None}, "3": {"2": None}}
>>> A = pgv.AGraph(d)

or using a SWIG pointer to the AGraph datastructure,

>>> h=A.handle
>>> C=pgv.AGraph(h)
>>> h = A.handle
>>> C = pgv.AGraph(h)


Nodes, and edges
----------------

Nodes and edges can be added one at a time

>>> G.add_node('a') # adds node 'a'
>>> G.add_edge('b','c') # adds edge 'b'-'c' (and also nodes 'b', 'c')
>>> G.add_node("a") # adds node 'a'
>>> G.add_edge("b", "c") # adds edge 'b'-'c' (and also nodes 'b', 'c')

or from lists or containers.

>>> nodelist=['f','g','h']
>>> nodelist = ["f", "g", "h"]
>>> G.add_nodes_from(nodelist)

If the node is not a string an attempt will be made to convert it
Expand All @@ -76,49 +71,49 @@ Attributes
To set the default attributes for graphs, nodes, and edges use
the graph_attr, node_attr, and edge_attr dictionaries

>>> G.graph_attr['label']='Name of graph'
>>> G.node_attr['shape']='circle'
>>> G.edge_attr['color']='red'
>>> G.graph_attr["label"] = "Name of graph"
>>> G.node_attr["shape"] = "circle"
>>> G.edge_attr["color"] = "red"

Graph attributes can be set when initializing the graph

>>> G=pgv.AGraph(ranksep='0.1')
>>> G = pgv.AGraph(ranksep="0.1")

Attributes can be added when adding nodes or edges,

>>> G.add_node(1, color='red')
>>> G.add_edge('b','c',color='blue')
>>> G.add_node(1, color="red")
>>> G.add_edge("b", "c", color="blue")

or through the node or edge attr dictionaries,

>>> n=G.get_node(1)
>>> n.attr['shape']='box'
>>> n = G.get_node(1)
>>> n.attr["shape"] = "box"


>>> e=G.get_edge('b','c')
>>> e.attr['color']='green'
>>> e = G.get_edge("b", "c")
>>> e.attr["color"] = "green"

Layout and Drawing
------------------
Pygraphviz provides several methods for layout and drawing of graphs.

To store and print the graph in dot format as a Python string use

>>> s=G.string()
>>> s = G.string()

To write to a file use

>>> G.write("file.dot")

To add positions to the nodes with a Graphviz layout algorithm

>>> G.layout() # default to neato
>>> G.layout(prog='dot') # use dot
>>> G.layout() # default to neato
>>> G.layout(prog="dot") # use dot

To render the graph to an image

>>> G.draw('file.png') # write previously positioned graph to PNG file
>>> G.draw('file.ps',prog='circo') # use circo to position, write PS file
>>> G.draw("file.png") # write previously positioned graph to PNG file
>>> G.draw("file.ps", prog="circo") # use circo to position, write PS file



Expand Down

0 comments on commit 4d1d5ee

Please sign in to comment.