Skip to content

Commit

Permalink
Drop Py2 cruft
Browse files Browse the repository at this point in the history
  • Loading branch information
jarrodmillman committed Jul 8, 2020
1 parent 59cb172 commit c341911
Show file tree
Hide file tree
Showing 29 changed files with 40 additions and 118 deletions.
3 changes: 1 addition & 2 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Sphinx documentation build configuration file, created by
# sphinx-quickstart.py on Sat Mar 8 21:47:50 2008.
Expand Down Expand Up @@ -40,7 +39,7 @@

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


# The default replacements for |version| and |release|, also used in various
Expand Down
4 changes: 0 additions & 4 deletions examples/attributes.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/usr/bin/env python

from __future__ import absolute_import
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division

import pygraphviz as pgv
# strict (no parallel edges)
Expand Down
5 changes: 0 additions & 5 deletions examples/django_simple.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Simple example for rendering a graph with the Django web framework.
See
Expand All @@ -15,10 +14,6 @@
# Distributed with BSD license.
# All rights reserved, see LICENSE for details.

from __future__ import absolute_import
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division

__author__ = """Aric Hagberg (hagberg@lanl.gov)"""

Expand Down
6 changes: 1 addition & 5 deletions examples/miles.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
ACM Press, New York, 1993.
[2] http://www-cs-faculty.stanford.edu/~knuth/sgb.html
"""
from __future__ import absolute_import
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
import fileinput
__author__ = """Aric Hagberg (aric.hagberg@gmail.com)"""

Expand Down Expand Up @@ -50,7 +46,7 @@ def miles_graph():
for line in gzip.open("miles_dat.txt.gz",'rt'):
if line.startswith("*"): # skip comments
continue
numfind=re.compile("^\d+")
numfind=re.compile(r"^\d+")

if numfind.match(line): # this line is distances
dist=line.split()
Expand Down
5 changes: 0 additions & 5 deletions examples/simple.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
A simple example to create a graphviz dot file and draw a graph.
Expand All @@ -11,10 +10,6 @@
# Distributed with BSD license.
# All rights reserved, see LICENSE for details.

from __future__ import absolute_import
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division

__author__ = """Aric Hagberg (hagberg@lanl.gov)"""

Expand Down
5 changes: 0 additions & 5 deletions examples/star.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Create and draw a star with varying node properties.
Expand All @@ -11,10 +10,6 @@
# Distributed with BSD license.
# All rights reserved, see LICENSE for details.

from __future__ import absolute_import
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division

__author__ = """Aric Hagberg (hagberg@lanl.gov)"""

Expand Down
4 changes: 0 additions & 4 deletions examples/subgraph.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/usr/bin/env python

from __future__ import absolute_import
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division

import pygraphviz as pgv

Expand Down
5 changes: 0 additions & 5 deletions examples/utf8_encoding.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
# -*- coding: utf-8 -*-
"""
Example showing use of unicode and UTF-8 encoding.
"""

from __future__ import absolute_import
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division

import pygraphviz as pgv
# specify UTF-8 encoding (it is the default)
Expand Down
3 changes: 0 additions & 3 deletions pygraphviz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
# Distributed with BSD license.
# All rights reserved, see LICENSE for details.

from __future__ import absolute_import
from __future__ import print_function
from __future__ import division

# Release data
from . import release
Expand Down
33 changes: 13 additions & 20 deletions pygraphviz/agraph.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
A Python interface to Graphviz.
Expand All @@ -9,20 +8,14 @@
# Manos Renieris, http://www.cs.brown.edu/~er/
# Distributed with BSD license.
# All rights reserved, see LICENSE for details.
from __future__ import print_function

import re
import shlex
import subprocess
import sys
import threading
import warnings
try:
# Python 3
from collections.abc import MutableMapping
except ImportError:
# Python 2.7
from collections import MutableMapping
from collections.abc import MutableMapping

from . import graphviz as gv

Expand Down Expand Up @@ -56,13 +49,13 @@ def run(self):
self.pipe.close()


class _Action(object):
class _Action:
find, create = 0, 1

class DotError(ValueError):
"""Dot data parsing error"""

class AGraph(object):
class AGraph:
"""Class for Graphviz agraph type.
Example use
Expand Down Expand Up @@ -240,7 +233,7 @@ def __repr__(self):
name = gv.agnameof(self.handle)
if name is None:
return '<AGraph %s>' % self.handle
return '<AGraph %s %s>' % (name, self.handle)
return f'<AGraph {name} {self.handle}>'

def __eq__(self, other):
# two graphs are equal if they have exact same string representation
Expand Down Expand Up @@ -528,7 +521,7 @@ def remove_edge(self, u, v=None, key=None):
try:
gv.agdeledge(self.handle, e.handle)
except KeyError:
raise KeyError("Edge %s-%s not in graph." % (u, v))
raise KeyError(f"Edge {u}-{v} not in graph.")

delete_edge = remove_edge

Expand Down Expand Up @@ -1233,7 +1226,7 @@ def read(self, path):
raise DotError("Invalid Input")
else:
self._update_handle_references()
except IOError:
except OSError:
print("IO error reading file")

def write(self, path=None):
Expand All @@ -1250,7 +1243,7 @@ def write(self, path=None):
fh = self._get_fh(path, 'w')
try:
gv.agwrite(self.handle, fh)
except IOError:
except OSError:
print("IO error writing file")
finally:
if hasattr(fh, 'close') and not hasattr(path, 'write'):
Expand Down Expand Up @@ -1366,7 +1359,7 @@ def _run_prog(self, prog='nop', args=''):
p.wait()

if not data:
raise IOError(b"".join(errors).decode(self.encoding))
raise OSError(b"".join(errors).decode(self.encoding))

if len(errors) > 0:
warnings.warn(b"".join(errors).decode(self.encoding), RuntimeWarning)
Expand Down Expand Up @@ -1613,9 +1606,9 @@ class Node(_TEXT_TYPE):

def __new__(self, graph, name=None, nh=None):
if nh is not None:
n = super(Node, self).__new__(self, gv.agnameof(nh), graph.encoding)
n = super().__new__(self, gv.agnameof(nh), graph.encoding)
else:
n = super(Node, self).__new__(self, name)
n = super().__new__(self, name)
try:
nh = gv.agnode(graph.handle, n.encode(graph.encoding), _Action.find)
except KeyError:
Expand Down Expand Up @@ -1698,7 +1691,7 @@ def __new__(self, graph, source=None, target=None, key=None, eh=None):
key,
_Action.find)
except KeyError:
raise KeyError("Edge %s-%s not in graph." % (source, target))
raise KeyError(f"Edge {source}-{target} not in graph.")

tp = tuple.__new__(self, (s, t))
tp.ghandle = graph.handle
Expand Down Expand Up @@ -1897,8 +1890,8 @@ def _test_suite():
import sys
import unittest

if sys.version_info[:2] < (2, 4):
print("Python version 2.4 or later required for tests (%d.%d detected)." % sys.version_info[:2])
if sys.version_info[:2] < (3, 6):
print("Python version 3.6 or later required for tests (%d.%d detected)." % sys.version_info[:2])
sys.exit(-1)
# directory of package (relative to this)
nxbase = sys.path[0] + os.sep + os.pardir
Expand Down
2 changes: 1 addition & 1 deletion pygraphviz/graphviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def _swig_repr(self):
strthis = "proxy of " + self.this.__repr__()
except:
strthis = ""
return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
return f"<{self.__class__.__module__}.{self.__class__.__name__}; {strthis} >"

try:
_object = object
Expand Down
9 changes: 4 additions & 5 deletions pygraphviz/release.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""Release data for PyGraphviz."""

# Copyright (C) 2006-2018 by
Expand Down Expand Up @@ -36,7 +35,7 @@ def write_versionfile():
'''
if revision is not None:
rev = "'%s'" % (revision,)
rev = f"'{revision}'"
else:
rev = revision
subs = {'version': version,
Expand All @@ -50,11 +49,11 @@ def get_svn_revision():
base = os.path.split(__file__)[0]
entries_path = os.path.join(base, '.svn', 'entries')
if os.path.isfile(entries_path):
entries = open(entries_path, 'r').read()
entries = open(entries_path).read()
# Versions >= 7 of the entries file are flat text. The first line is
# the version number. The next set of digits after 'dir' is the revision.
if re.match('(\d+)', entries):
rev_match = re.search('\d+\s+dir\s+(\d+)', entries)
if re.match(r'(\d+)', entries):
rev_match = re.search(r'\d+\s+dir\s+(\d+)', entries)
if rev_match:
rev = rev_match.groups()[0]
if rev:
Expand Down
2 changes: 0 additions & 2 deletions pygraphviz/tests/test_attribute_defaults.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from nose.tools import *
import pygraphviz as pgv
from os import linesep
Expand Down
1 change: 0 additions & 1 deletion pygraphviz/tests/test_attributes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# -*- coding: utf-8 -*-
from nose.tools import *
import pygraphviz as pgv
1 change: 0 additions & 1 deletion pygraphviz/tests/test_clear.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from nose.tools import *
import pygraphviz as pgv

Expand Down
1 change: 0 additions & 1 deletion pygraphviz/tests/test_drawing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from nose.tools import *
import pygraphviz as pgv

Expand Down
2 changes: 0 additions & 2 deletions pygraphviz/tests/test_edge_attributes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from nose.tools import *
import pygraphviz as pgv
from os import linesep
Expand Down
1 change: 0 additions & 1 deletion pygraphviz/tests/test_graph.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import unicode_literals
from nose.tools import *
import pygraphviz as pgv
from os import linesep
Expand Down
1 change: 0 additions & 1 deletion pygraphviz/tests/test_html.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from nose.tools import *
import pygraphviz as pgv
from os import linesep
Expand Down
1 change: 0 additions & 1 deletion pygraphviz/tests/test_layout.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from nose.tools import *
import pygraphviz as pgv

Expand Down
2 changes: 0 additions & 2 deletions pygraphviz/tests/test_node_attributes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from nose.tools import *
import pygraphviz as pgv
from os import linesep
Expand Down
1 change: 0 additions & 1 deletion pygraphviz/tests/test_readwrite.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from nose.tools import assert_equal
from nose.tools import assert_true
from nose.tools import assert_false
Expand Down
14 changes: 4 additions & 10 deletions pygraphviz/tests/test_setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
from nose.tools import *
from mock import patch
from unittest.mock import patch

# inside distributed version, there is no setup_extra files already
sys.path.insert(0,'../..')
Expand All @@ -17,10 +17,7 @@ def _get_values():
def _get_dpkg_output():
r = """libgvc: /usr/local/include/graphviz/gvc.h
gphviz: /usr/local/lib/graphviz/graphviz.so"""
if sys.version_info >= (3, 0):
s = bytes(r, encoding='utf8')
else:
s = str(r)
s = bytes(r, encoding='utf8')
return s


Expand All @@ -43,9 +40,6 @@ def test_dpkg_config(subprocess_mock):

def test_b2str():
if setup_extra:
if sys.version_info >= (3, 0):
r = bytes('abc', encoding='utf8')
else:
r = str('abc')
r = bytes('abc', encoding='utf8')
s = setup_extra._b2str(r)
assert_equal(s, u'abc')
assert_equal(s, 'abc')
1 change: 0 additions & 1 deletion pygraphviz/tests/test_string.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from nose.tools import assert_equal, raises
import pygraphviz as pgv
from os import linesep
Expand Down
1 change: 0 additions & 1 deletion pygraphviz/tests/test_subgraph.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from nose.tools import *
import pygraphviz as pgv
from os import linesep
Expand Down
2 changes: 0 additions & 2 deletions pygraphviz/tests/test_unicode.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from nose.tools import *
import pygraphviz as pgv
import sys
Expand Down

0 comments on commit c341911

Please sign in to comment.