Skip to content

Commit a17dab2

Browse files
committed
imported files
1 parent c9d9287 commit a17dab2

File tree

12 files changed

+70185
-0
lines changed

12 files changed

+70185
-0
lines changed

.bumpversion.cfg

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[bumpversion]
2+
current_version = 0.1.0-dev
3+
commit = True
4+
tag = True
5+
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)-?(?P<release>dev)?
6+
serialize =
7+
{major}.{minor}.{patch}-{release}
8+
{major}.{minor}.{patch}
9+
10+
[bumpversion:file:pyproject.toml]
11+
12+
[bumpversion:file:doc/conf.py]
13+
14+
[bumpversion:file:README.rst]
15+
16+
[bumpversion:part:release]
17+
values =
18+
dev
19+
release
20+
optional_value = release
21+

.gitignore

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/.idea
2+
/venv
3+
/.venv
4+
5+
# Byte-compiled / optimized / DLL files
6+
__pycache__/
7+
*.py[cod]
8+
*$py.class
9+
10+
# C extensions
11+
*.so
12+
13+
# Distribution / packaging
14+
.Python
15+
build/
16+
develop-eggs/
17+
dist/
18+
downloads/
19+
eggs/
20+
.eggs/
21+
lib/
22+
lib64/
23+
parts/
24+
sdist/
25+
var/
26+
wheels/
27+
share/python-wheels/
28+
*.egg-info/
29+
.installed.cfg
30+
*.egg
31+
MANIFEST
32+
33+
# PyInstaller
34+
# Usually these files are written by a python script from a template
35+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
36+
*.manifest
37+
*.spec
38+
39+
# Installer logs
40+
pip-log.txt
41+
pip-delete-this-directory.txt
42+
43+
# Unit test / coverage reports
44+
htmlcov/
45+
.tox/
46+
.nox/
47+
.coverage
48+
.coverage.*
49+
.cache
50+
nosetests.xml
51+
coverage.xml
52+
*.cover
53+
*.py,cover
54+
.hypothesis/
55+
.pytest_cache/
56+
cover/
57+
58+
# Translations
59+
*.mo
60+
*.pot
61+
62+
# Django stuff:
63+
*.log
64+
local_settings.py
65+
db.sqlite3
66+
db.sqlite3-journal
67+
68+
# Flask stuff:
69+
instance/
70+
.webassets-cache
71+
72+
# Scrapy stuff:
73+
.scrapy
74+
75+
# Sphinx documentation
76+
docs/_build/
77+
78+
# PyBuilder
79+
.pybuilder/
80+
target/
81+
82+
# Jupyter Notebook
83+
.ipynb_checkpoints
84+
85+
# IPython
86+
profile_default/
87+
ipython_config.py
88+
89+
# pyenv
90+
# For a library or package, you might want to ignore these files since the code is
91+
# intended to run in multiple environments; otherwise, check them in:
92+
# .python-version
93+
94+
# pipenv
95+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
96+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
97+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
98+
# install all needed dependencies.
99+
#Pipfile.lock
100+
101+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
102+
__pypackages__/
103+
104+
# Celery stuff
105+
celerybeat-schedule
106+
celerybeat.pid
107+
108+
# SageMath parsed files
109+
*.sage.py
110+
111+
# Environments
112+
.env
113+
.venv
114+
env/
115+
venv/
116+
ENV/
117+
env.bak/
118+
venv.bak/
119+
120+
# Spyder project settings
121+
.spyderproject
122+
.spyproject
123+
124+
# Rope project settings
125+
.ropeproject
126+
127+
# mkdocs documentation
128+
/site
129+
130+
# mypy
131+
.mypy_cache/
132+
.dmypy.json
133+
dmypy.json
134+
135+
# Pyre type checker
136+
.pyre/
137+
138+
# pytype static type analyzer
139+
.pytype/
140+
141+
# Cython debug symbols
142+
cython_debug/

README.rst

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
ogdf-python: Automagic Python Bindings for the Open Graph Drawing Framework
2+
===========================================================================
3+
4+
`Original repository <https://github.com/N-Coder/ogdf-python>`_ (GitHub) -
5+
`Bugtracker and issues <https://github.com/N-Coder/ogdf-python>`_ (GitHub) -
6+
`PyPi package <https://pypi.python.org/pypi/ogdf-python>`_ (PyPi ``ogdf-python``) -
7+
`Documentation <https://ogdf-python.readthedocs.io>`_ (Read The Docs).
8+
9+
`Official OGDF website <https://ogdf.net>`_ (ogdf.net) -
10+
`Public OGDF repository <https://github.com/ogdf/ogdf>`_ (GitHub) -
11+
`Internal OGDF repository <https://git.tcs.uos.de/ogdf-devs/OGDF>`_ (GitLab) -
12+
`OGDF Documentation <https://ogdf.github.io/docs/ogdf/>`_ (GitHub / Doxygen) -
13+
`cppyy Documentation <https://cppyy.readthedocs.io>`_ (Read The Docs).
14+
15+
.. |(TM)| unicode:: U+2122
16+
17+
``ogdf-python`` uses the `black magic <http://www.camillescott.org/2019/04/11/cmake-cppyy/>`_
18+
of the awesome `cppyy <https://bitbucket.org/wlav/cppyy/src/master/>`_ library to automagically generate python bindings
19+
for the C++ Open Graph Drawing Framework (OGDF).
20+
It is available for Python>=3.6 and is Apache2 licensed.
21+
There are no binding definitions files, no stuff that needs extra compiling, it just works\ |(TM)|, believe me.
22+
Templates, namespaces, cross-language callbacks and inheritance, pythonic iterators and generators, it's all there.
23+
If you want to learn more about the magic behind the curtains, read `this article <http://www.camillescott.org/2019/04/11/cmake-cppyy/>`_.
24+
25+
26+
Quickstart
27+
----------
28+
29+
First, install the package ``ogdf-python`` package.
30+
Please note that building ``cppyy`` from sources may take a while.
31+
If you didn't install OGDF globally on your system,
32+
either set the ``OGDF_INSTALL_DIR`` to the prefix you configured in ``cmake``,
33+
or set ``OGDF_BUILD_DIR`` to the subdirectory of your copy of the OGDF repo where your
34+
`out-of-source build <https://ogdf.github.io/docs/ogdf/md_doc_build.html#autotoc_md4>`_ lives.
35+
36+
.. code-block:: bash
37+
38+
$ pip install ogdf-python
39+
$ OGDF_BUILD_DIR=~/ogdf/build-debug python3
40+
41+
Alternatively, ``ogdf-python`` works very well with Jupyter:
42+
43+
.. code-block:: python
44+
45+
%env OGDF_BUILD_DIR=~/ogdf/build-debug
46+
47+
from ogdf_python import ogdf, cppinclude
48+
cppinclude("ogdf/basic/graph_generators/randomized.h")
49+
cppinclude("ogdf/layered/SugiyamaLayout.h")
50+
51+
G = ogdf.Graph()
52+
ogdf.setSeed(1)
53+
ogdf.randomPlanarTriconnectedGraph(G, 20, 40)
54+
GA = ogdf.GraphAttributes(G, ogdf.GraphAttributes.all)
55+
56+
for n in G.nodes:
57+
GA.label[n] = "N%s" % n.index()
58+
59+
SL = ogdf.SugiyamaLayout()
60+
SL.call(GA)
61+
GA
62+
63+
.. image:: docs/examples/sugiyama-simple.svg
64+
:target: docs/examples/sugiyama-simple.ipynb
65+
:alt: SugiyamaLayouted Graph
66+
:height: 300 px
67+
68+
Read the pitfalls section and check out `docs/examples/pitfalls.ipynb <docs/examples/pitfalls.ipynb>`_
69+
for the more advanced Sugiyama example from the OGDF docs.
70+
There is also a bigger example in `docs/examples/ogdf-includes.ipynb <docs/examples/ogdf-includes.ipynb>`_.
71+
If anything is unclear, check out the python help ``help(ogdf.Graph)`` and read the corresponding OGDF documentation.
72+
73+
..
74+
Documentation
75+
-------------
76+
TODO use ``help(ogdf.Graph)`` and sphinx autodoc
77+
78+
..
79+
Load Custom Code
80+
----------------
81+
TODO
82+
83+
Pitfalls
84+
--------
85+
86+
See also `docs/examples/pitfalls.ipynb <docs/examples/pitfalls.ipynb>`_ for full examples.
87+
88+
OGDF sometimes takes ownership of objects (usually when they are passed as modules),
89+
which may conflict with the automatic cppyy garbage collection.
90+
Set ``__python_owns__ = False`` on those objects to tell cppyy that those objects
91+
don't need to be garbage collected, but will be cleaned up from the C++ side.
92+
93+
.. code-block:: python
94+
95+
SL = ogdf.SugiyamaLayout()
96+
ohl = ogdf.OptimalHierarchyLayout()
97+
ohl.__python_owns__ = False
98+
SL.setLayout(ohl)
99+
100+
When you overwrite a python variable pointing to a C++ object (and it is the only
101+
python variable pointing to that object), the C++ will usually be immediately deleted.
102+
This might be a problem if another C++ objects depends ob that old object, e.g.
103+
a ``GraphAttributes`` instance depending on a ``Graph`` instance.
104+
Now the other C++ object has a pointer to a delted and now invalid location,
105+
which will usually cause issues down the road (e.g. when the dependant object is
106+
deleted and wants to deregister from its no longer alive parent).
107+
This overwriting might easily happen if you run a Jupyter cell multiple times.
108+
Please ensure that you always overwrite or delete C++ dependent variables in
109+
the reverse order of their initialization.
110+
111+
.. code-block:: python
112+
113+
CGA = CG = G = None
114+
G = ogdf.Graph()
115+
CG = ogdf.ClusterGraph(G)
116+
CGA = ogdf.ClusterGraphAttributes(CG, ogdf.ClusterGraphAttributes.all)
117+

0 commit comments

Comments
 (0)