Skip to content

Commit

Permalink
Merge pull request #52 from mmarkov/implement-library-path
Browse files Browse the repository at this point in the history
Implement library path.
Fixes #10.
  • Loading branch information
hagberg committed May 21, 2015
2 parents 9ed7597 + 7158697 commit b5f7bcd
Show file tree
Hide file tree
Showing 6 changed files with 233 additions and 202 deletions.
15 changes: 15 additions & 0 deletions INSTALL.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ or install it with::
and an attempt will be made to find and install an appropriate version
that matches your operating system and Python version.

Providing path to graphviz
--------------------------

We tried our best to discover graphviz location automatically, but if you
would like specify specific location for graphviz you may provide additrional parameters to specify graphviz location


include-path= path to graphviz include files
library-path= path to graphviz library files

For example

::

python setup.py install --include-path=/usr/local/Cellar/graphviz/2.38.0/include/graphviz --library-path=/usr/local/Cellar/graphviz/2.38.0/lib

Installing from Source
======================
Expand Down
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
include MANIFEST.in
include setup_egg.py
include setup_extra.py
include INSTALL.txt

Expand Down
127 changes: 31 additions & 96 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,98 +8,28 @@
from __future__ import division

from glob import glob

import os
from setuptools import setup, Extension
import sys
if os.path.exists('MANIFEST'): os.remove('MANIFEST')

from setuptools import setup, Extension
from setup_commands import AddExtensionDevelopCommand, AddExtensionInstallCommand
from setup_extra import get_graphviz_dirs

from setup_extra import pkg_config, dotneato_config

if os.path.exists('MANIFEST'): os.remove('MANIFEST')

if sys.argv[-1] == 'setup.py':
print("To install, run 'python setup.py install'")
print()

if sys.version_info[:2] < (2, 6):
print("PyGraphviz requires Python version 2.6 or later (%d.%d detected)." % \
print("PyGraphviz requires Python version 2.6 or later (%d.%d detected)." %
sys.version_info[:2])
sys.exit(-1)

include_dirs = None
library_dirs = None
define_macros = []

# If the setup script couldn't find your graphviz installation you can
# specify it here by uncommenting these lines or providing your own:
# You must set both 'library_dirs' and 'include_dirs'

# Linux, generic UNIX
#library_dirs='/usr/lib/graphviz'
#include_dirs='/usr/include/graphviz'

# OSX, Linux, alternate location
#library_dirs='/usr/local/lib/graphviz'
#include_dirs='/usr/local/include/graphviz'

# OSX (Fink)
#library_dirs='/sw/lib/graphviz'
#include_dirs='/sw/include/graphviz'

# OSX (MacPorts)
#library_dirs='/opt/local/lib/graphviz'
#include_dirs='/opt/local/include/graphviz'

# Windows
# Unknown - use command line -I and -L switches to set

if sys.platform == "win32":
define_macros.append(('GVDLL', None))

else:
# Attempt to find Graphviz installation
if library_dirs is None and include_dirs is None:
print("Trying pkg-config")
include_dirs,library_dirs = pkg_config()

if library_dirs is None and include_dirs is None:
print("Trying dotneato-config")
include_dirs, library_dirs = dotneato_config()

if library_dirs is None or include_dirs is None:
print()
print("""Your Graphviz installation could not be found.
1) You don't have Graphviz installed:
Install Graphviz (http://graphviz.org)
2) Your Graphviz package might incomplete.
Install the binary development subpackage (e.g. libgraphviz-dev or similar.)
3) You are using Windows
There are no PyGraphviz binary packages for Windows but you might be
able to build it from this source. See
http://networkx.lanl.gov/pygraphviz/reference/faq.html
If you think your installation is correct you will need to manually
change the include_dirs and library_dirs variables in setup.py to
point to the correct locations of your graphviz installation.
The current setting of library_dirs and include_dirs is:""")
print("library_dirs=%s"%library_dirs)
print("include_dirs=%s"%include_dirs)
print()
raise OSError("Error locating graphviz.")

print("library_dirs=%s" % library_dirs)
print("include_dirs=%s" % include_dirs)

if library_dirs:
library_dirs = [library_dirs]

if include_dirs:
include_dirs = [include_dirs]

# Write the version information.
#TODO rework this import hack with import graphviz.release or import graphviz.version ( doesn't work now because of code in the __init__)
sys.path.insert(0, 'pygraphviz')
import release
release.write_versionfile()
Expand All @@ -113,26 +43,24 @@
(os.path.join(docdirbase, 'examples'), glob("examples/*.dat")),
(os.path.join(docdirbase, 'examples'), glob("examples/*.dat.gz")),
]

extension_args = {}
if sys.platform != "win32":
extension_args['runtime_library_dirs'] = library_dirs

extension = [
Extension(
"pygraphviz._graphviz",
["pygraphviz/graphviz_wrap.c"],
include_dirs=include_dirs,
library_dirs=library_dirs,
libraries=["cgraph", "cdt"],
define_macros=define_macros,
**extension_args
)
]

package_data = {'': ['*.txt'], }

if __name__ == "__main__":
define_macros = []
if sys.platform == "win32":
define_macros = define_macros.append(('GVDLL', None))

extension = [
Extension(
"pygraphviz._graphviz",
["pygraphviz/graphviz_wrap.c"],
include_dirs=[],
library_dirs=[],
libraries=["cgraph", "cdt"],
define_macros=define_macros
)
]

setup(
name=release.name,
version=release.version,
Expand All @@ -149,5 +77,12 @@
packages=packages,
data_files=data,
ext_modules=extension,
package_data=package_data
cmdclass={
'install': AddExtensionInstallCommand,
'develop': AddExtensionDevelopCommand,
},
package_data=package_data,
include_package_data = True,
test_suite='nose.collector',
tests_require=['nose>=0.10.1', 'doctest-ignore-unicode>=0.1.0',],
)
65 changes: 65 additions & 0 deletions setup_commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Setup commands for PyGraphviz.
"""
# Copyright (C) 2006-2014 by
# Aric Hagberg <hagberg@lanl.gov>
# Dan Schult <dschult@colgate.edu>
# Manos Renieris, http://www.cs.brown.edu/~er/
# Distributed with BSD license.
# All rights reserved, see LICENSE for details.
#
# Derived from http://www.niteoweb.com/blog/setuptools-run-custom-code-during-install
# Author: Maksym Markov <maksym.markov@gmail.com>

from setuptools.command.develop import develop
from setuptools.command.install import install

from setup_extra import get_graphviz_dirs

def add_extensions(command_subclass):
"""A decorator for classes subclassing one of the setuptools commands.
It modifies the run() method so that it prints a friendly greeting.
"""
orig_init = command_subclass.__init__
orig_initialize_options = command_subclass.initialize_options
orig_run = command_subclass.run
command_subclass.user_options.extend([('include-path=', None, 'path to graphviz include files.'),
('library-path=', None, 'path to graphviz library files.')])

def __init__(self, *args, **kws):
orig_init(self, *args, **kws)

def modified_initialize_options(self):
self.include_path = None
self.library_path = None
orig_initialize_options(self)

def modified_run(self):
# Add extension here
# if there is no library_path and include_path passed form command line then try identify them
if (not self.include_path) or (not self.library_path):
self.include_path, self.library_path = get_graphviz_dirs()
if self.distribution and self.distribution.ext_modules:
for m in self.distribution.ext_modules:
if m.name == 'pygraphviz._graphviz':
m.include_dirs.append(self.include_path)
m.library_dirs.append(self.library_path)
orig_run(self)

command_subclass.__init__ = __init__
command_subclass.initialize_options = modified_initialize_options
command_subclass.run = modified_run

return command_subclass


@add_extensions
class AddExtensionDevelopCommand(develop):
pass

@add_extensions
class AddExtensionInstallCommand(install):
pass
61 changes: 0 additions & 61 deletions setup_egg.py

This file was deleted.

Loading

0 comments on commit b5f7bcd

Please sign in to comment.