Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppressing warnings/errors in Python #5370

Open
mf2vec-dev opened this issue Feb 9, 2024 · 1 comment
Open

Suppressing warnings/errors in Python #5370

mf2vec-dev opened this issue Feb 9, 2024 · 1 comment

Comments

@mf2vec-dev
Copy link
Contributor

I'm trying to suppress FontForge's warnings and errors that can be caused e.g. by c.isClockwise().
They cannot currently be redirected (e.g. by setting Python's sys.stderr) or suppressed (e.g. by Python's warnings.filterwarnings) as they are not generated by the Python/C API.
When using FontForge to perform automated operations on a large number of fonts/glyphs, these warnings can easily mess up the terminal. It would be nice to be able to suppress warnings and errors in certain scenarios.

Versions

FontForge 20230101 and Ubuntu 22.04

Steps to reproduce

Run the following Python script to raise a warning:

import fontforge

c = fontforge.contour().moveTo(0,0).lineTo(0,0).lineTo(0,0)
c.closed = True
c.isClockwise()

Possible solution

I have implemented a preference that causes NOUI__LogError and _LogError to return without writing to stderr. I would like to get some feedback on whether a preference is the way to go. Also, I don't understand the following prefs_list aspects:

  • What is the difference between core_list and extras in noprefs.c? How do I decide where to put this new preference?
  • How do I choose the value of the mn (= mnemonic?) field of pref_list?

If a new preference is the preferred approach and I understand the currently unclear aspects of prefs_list, I can open a PR to discuss the details.

@iorsh
Copy link
Contributor

iorsh commented Feb 11, 2024

There is a static variable running_script which could be used to modify the behavior of *_LogError functions only when Python is running. The problem is that it marks both Python and native scripts. Try to see if there is a way to differentiate these two cases.

I think, preferences are difficult to discover, so if there is a way to do stuff without them, that would be better

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

No branches or pull requests

2 participants