Skip to content

Issue #47 - Allow Python application developers to disable quiet mode of graphLib#50

Merged
john-boyer-phd merged 8 commits into
masterfrom
Issue47-ExposeQuietMode
May 27, 2026
Merged

Issue #47 - Allow Python application developers to disable quiet mode of graphLib#50
john-boyer-phd merged 8 commits into
masterfrom
Issue47-ExposeQuietMode

Conversation

@wbkboyer
Copy link
Copy Markdown
Member

@wbkboyer wbkboyer commented May 20, 2026

Message() and ErrorMessage() from the C layer will be displayed after setting quietMode to 0 via gp_SetQuietModeFlag().

Resolves #47 (and #40 appears to have been fixed by changes to Manifest.in)

Type of change

Please check only relevant options:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Changes

Added

  • examples/full/test_quiet_mode.py - Helps demonstrate use of gp_GetQuietModeFlag() and gp_SetQuietModeFlag() exposed from graphLib module in planarity.full subpackage
  • planarity/full/graphLib.c - compiled using Python 3.14.2 on MacOS with Cython 3.2.5
  • planarity/full/graphLib.pxd - definition file that allows other cython modules to call wrapper functions made available in this module (i.e. graphLib.pyx). Also surfaces the graphP, G6ReadIteratorP, and G6WriteIteratorP types (defined in cgraphLib.pxd, corresponding to types in the C library) to other Cython modules.
    • N.B. Had to change the function signature of g6_InitReaderWithFileName() (g6_InitWriterWithFileName() only uses char * for outputFilename) to remove const qualifiers, since the syntax char const *const supported in C isn't supported by Cython)
  • planarity/full/graphLib.pyx - Cython module containing simple wrapper functions of EAPS graphLib, as well as exposing graphLib constants defined in cgraphLib.pxd.

Updated

  • MANIFEST.in - removed .pxd definition files that no longer exist, added graphLib module source file, definition file, and compiled file, as well as graph.pxd definition file (which might have been the cause of python -m build fails to build source distribution and wheel #40 , looking at the error messsage planarity/full/graph.pyx:41:41: Cannot convert 'graphP' to Python object)
  • setup.py - created new Extension for graphLib.pyx module, which is the extension whose sourcefiles include those in the c/graphLib/ (i.e. the compiled library corresponding to this module is how we gain access to the EAPS graphLib). So now, the planarity.full.graph and planarity.full.g6IterationUtils Extensions no longer need to include the planarity/c/graphLib/ in their sources, nor to require the headers via include_dirs.
  • planarity/full/cgraphLib.pxd - Added contents of cappconst.pxd and cG6IterationDefs.pxd, and moved some of the definitions of functions and constants up to the top of the cgraphLib.pxd file for ease of reference. Also fixed gp_GetNextEdge() and gp_GetNeighbor() parameter names to reflect the function signature in the planarity/c/graphLib/graph.h header.
  • planarity/full/g6IterationUtils.pyx - now cimports the graphLib module in order to access the functions defined in cgraphLib.pxd via the wrappers in graphLib. Also imports graphLib to get access to the constants from planarity/c/graphLib/ (e.g. OK)
  • planarity/full/graph.pyx - now cimports the graphLib module in order to access the functions defined in cgraphLib.pxd via the wrappers in graphLib. Also imports graphLib to get access to the constants from planarity/c/graphLib/ (e.g. OK). Removed gp_GetProjectVersionFull() and gp_GetLibPlanarityVersionFull() wrappers, which belong to the whole graphLib.
  • planarity/full/graph.pxd we cimport graphLib to gain access to the definition for graphP (i.e. via graphLib.pxd)
  • planarity/__init__.py - now, graphLib.pyx module is that which supplies gp_GetQuietModeFlag(), gp_SetQuietModeFlag(), gp_GetProjectVersionFull(), and gp_GetLibPlanarityVersionFull(), as well as all the constants (e.g. OK), so those are the only module members surfaced via planarity package's __init__.py
  • planarity/classic/planarity.c, planarity/full/g6IterationUtils.c, planarity/full/graph.c - recompiled using Python 3.14.2 on MacOS with Cython 3.2.5

Removed

  • planarity/full/cappconst.pxd, planarity/full/cg6IterationDefs.pxd, since these definitions were moved into cgraphLib.pxd and graphLib.pyx only cimports cgraphLib
Changenotes for previous iteration

Added

  • examples/full/quiet_mode_test.py - For this test to be meaningful, you must add a Message() and/or ErrorMessage() to the C graphLib layer in gp_New() so that when we initialize the Graph instances and __cinit__() calls gp_New(), we'll see that the messages are not displayed by default, but then once the global variable quietModeFlag
    is updated via gp_SetQuietModeFlag(), the messages are displayed.
  • planarity/full/capiutils.pxd - added definitions for gp_GetQuietModeFlag() and gp_SetQuietModeFlag() in planarity/c/graphLib/lowLevelUtils/apiutils.h

Updated

  • planarity/__init__.py - exposed gp_GetQuietModeFlag() and gp_SetQuietModeFlag() from planarity/full/graph.pyx
  • planarity/full/graph.pyx - added definitions for functions gp_GetQuietModeFlag() and gp_SetQuietModeFlag() which call down to the corresponding graphLib functions defined in planarity/full/capiutils.pxd
  • planarity/full/g6IterationUtils.c and planarity/full/graph.c - regenerated on MacOS Tahoe (26.3.1) using Python 3.14 with Cython==3.2.4 and setuptools==82.0.1

Removed

  • N/A

Testing

Running test_quiet_mode.py when an invalid filename is given to initialize the G6ReadIterator
wbkboyer@Wandas-MacBook-Pro planarity % python3.14 -m venv .testenv
wbkboyer@Wandas-MacBook-Pro planarity % source .testenv/bin/activate
(.testenv) wbkboyer@Wandas-MacBook-Pro planarity % pip install --upgrade pip
...
(.testenv) wbkboyer@Wandas-MacBook-Pro planarity % pip install matplotlib pytest networkx setuptools
...
(.testenv) wbkboyer@Wandas-MacBook-Pro planarity % python -m pip install --index-url https://test.pypi.org/simple/ --no-deps --no-build-isolation planarity
Looking in indexes: https://test.pypi.org/simple/
Collecting planarity
  Downloading planarity-0.7.15.tar.gz (555 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 555.7/555.7 kB 8.9 MB/s  0:00:00
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: planarity
  Building wheel for planarity (pyproject.toml) ... done
  Created wheel for planarity: filename=planarity-0.7.15-cp314-cp314-macosx_10_15_universal2.whl size=575363 sha256=f8a9d3f4e56fed959546365fe5444a30a8b8d1eb96eefa6d49616e0056ab8d13
  Stored in directory: /Users/wbkboyer/Library/Caches/pip/wheels/c5/29/11/de9b747702abf416a71ca882ec6b99f18dc666be1c01e786fe
Successfully built planarity
Installing collected packages: planarity
Successfully installed planarity-0.7.15
(.testenv) wbkboyer@Wandas-MacBook-Pro planarity % cd ~
(.testenv) wbkboyer@Wandas-MacBook-Pro planarity % python examples/full/test_quiet_mode.py 
(.venv) wbkboyer@Wandas-MacBook-Pro planarity % python examples/full/test_quiet_mode.py
Trying to init reader with nonexistent file 'DOES_NOT_EXIST.g6'.
	gp_ErroMessage() MUST NOT appear before stacktrace, as  quietModeFlag is TRUE:
-------------------------
-------------------------
Traceback (most recent call last):
  File "/Users/wbkboyer/git/planarity/examples/full/test_quiet_mode.py", line 52, in <module>
    reader.g6_InitReaderWithFileName(filename)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "planarity/full/g6IterationUtils.pyx", line 50, in planarity.full.g6IterationUtils.G6ReadIterator.g6_InitReaderWithFileName
    raise RuntimeError(
RuntimeError: Unable to initialize reader with filename, as g6_InitReaderWithFileName() in EAPS graphLib failed.

==================================================

Trying to init reader with nonexistent file 'DOES_NOT_EXIST.g6'.
	gp_ErroMessage() MUST appear before stacktrace, as quietModeFlag is FALSE:
-------------------------
Unable to initialize reader with filename, as we failed to allocate the inputContainer.
-------------------------
Traceback (most recent call last):
  File "/Users/wbkboyer/git/planarity/examples/full/test_quiet_mode.py", line 69, in <module>
    reader.g6_InitReaderWithFileName(filename)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "planarity/full/g6IterationUtils.pyx", line 50, in planarity.full.g6IterationUtils.G6ReadIterator.g6_InitReaderWithFileName
    raise RuntimeError(
RuntimeError: Unable to initialize reader with filename, as g6_InitReaderWithFileName() in EAPS graphLib failed.
(.venv) wbkboyer@Wandas-MacBook-Pro planarity % 

(.testenv) wbkboyer@Wandas-MacBook-Pro ~ % deactivate

@wbkboyer wbkboyer requested a review from john-boyer-phd May 20, 2026 22:52
…Lib.pyx Cython module, which directly wraps every function from the C graphLib via cimport of cgraphLib.pxd. I added the graphLib.pxd so that graph.pyx and g6IterationUtils.pyx modules are able to access the functions and constants surfaced from the cgraphLib via the graphLib. You can now think of graph.pyx and g6IterationUtils.pyx as being "views" of the graphLib rather than direct wrappers themselves.
@wbkboyer
Copy link
Copy Markdown
Member Author

Freakin' sweet. I think with the latest commit to update Manifest.in, we resolve #40 as well!! See this comment for testing done using planarity package installed on MacOS and Windows from TestPyPI.

Also ran test_all_graphs.py and test_table_generation_with_numInvalidOKs.py using the planarity package installed from TestPyPI, and the OK/NONEMBEDDABLE values haven't changed, so we have a higher degree of confidence in this refactor. 💪🏼

Copy link
Copy Markdown
Member

@john-boyer-phd john-boyer-phd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A fantastic advancement. I have only embarrassingly minor tweaks...

Comment thread examples/full/test_quiet_mode.py Outdated
Comment thread examples/full/test_quiet_mode.py
Comment thread examples/full/test_quiet_mode.py
Comment thread planarity/full/cgraphLib.pxd Outdated
Comment thread planarity/full/cgraphLib.pxd
Comment thread planarity/full/graphLib.pyx
Comment thread planarity/full/graphLib.pyx
Comment thread planarity/full/graphLib.pyx Outdated
Comment thread planarity/full/graphLib.pyx Outdated
Comment thread planarity/full/graphLib.pyx Outdated
@wbkboyer wbkboyer requested a review from john-boyer-phd May 27, 2026 22:19
Copy link
Copy Markdown
Member

@john-boyer-phd john-boyer-phd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking ALL GOOD!

@john-boyer-phd john-boyer-phd merged commit e175afc into master May 27, 2026
5 checks passed
john-boyer-phd pushed a commit that referenced this pull request May 28, 2026
…from [EAPS PR #217](graph-algorithms/edge-addition-planarity-suite#217) and [EAPS PR #221](graph-algorithms/edge-addition-planarity-suite#221), and made sure all functions/methods are declared and defined in the correct order in: (#53)

Closes #52

* `cgraphLib.pxd`,
* `cplanarity.pxd` (no changes to `planarity/classic/planarity.pyx` needed),
* `graphLib.pxd`,
* `graphLib.pyx`,
* `graph.pyx`

Added `gp_DynamicAddEdge()` to `cgraphLib.pxd`, surfaced in `graphLib.pxd` and wrapped in `graphLib.pyx`, then added to `Graph` in `graph.pyx`. NOTE that this is not called in the EAPS testing layer at this time, so direct validation has not yet been performed.

Changed order of `g6_EndReached()` in `g6ReadIterationUtils.pyx`, since this was left out of #50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Need to make gp_Get/SetQuietModeFlag methods available

2 participants