Skip to content

Use PyConfig API on Python 3.8#5404

Merged
skef merged 3 commits intofontforge:masterfrom
vstinner:pyconfig
Oct 7, 2024
Merged

Use PyConfig API on Python 3.8#5404
skef merged 3 commits intofontforge:masterfrom
vstinner:pyconfig

Conversation

@vstinner
Copy link
Copy Markdown
Contributor

The Py_SetProgramName() function used by fontforge is deprecated and was removed in Python 3.13 alpha 1.

Replace the deprecated function with the PyConfig API on Python 3.8. If the Python initialization fails, log an error to stderr and call exit(1).

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Non-breaking change

@iorsh
Copy link
Copy Markdown
Contributor

iorsh commented Aug 3, 2024

PyConfig API was introduced in 3.8 (released in 2019), and we are currently requiring Python 3.6 (released in 2016).
Maybe we should just bump required Python3 version to 3.8?

For reference, Ubuntu 20 (the oldest supported LTS) uses 3.8.

@vstinner
Copy link
Copy Markdown
Contributor Author

vstinner commented Aug 5, 2024

Maybe we should just bump required Python3 version to 3.8?

That's up to you. My PR remains backward compatible with Python 3.6.

@myoresh
Copy link
Copy Markdown

myoresh commented Aug 5, 2024

PyConfig API was introduced in 3.8 (released in 2019), and we are currently requiring Python 3.6 (released in 2016). Maybe we should just bump required Python3 version to 3.8?

For reference, Ubuntu 20 (the oldest supported LTS) uses 3.8.

@skef ?

@skef
Copy link
Copy Markdown
Contributor

skef commented Aug 5, 2024

It's probably been long enough to bump to 3.8. (No guarantees that someone with more authority won't slap our wrists before it happens.)

@iorsh
Copy link
Copy Markdown
Contributor

iorsh commented Aug 5, 2024

Ok, so let's bump. @vstinner, could you please update the PR?
@skef, do you want to CC specific people who might want to weigh in here?

@vstinner
Copy link
Copy Markdown
Contributor Author

vstinner commented Aug 5, 2024

I rebased my PR to remove code for Python 3.7 and older: only keep PyConfig code for Python 3.8 and newer. I didn't test my change, I rely on the CI for that.

@vstinner
Copy link
Copy Markdown
Contributor Author

vstinner commented Aug 5, 2024

"linux (ubuntu-20.04, Release) Expected — Waiting for status to be reported" is the CI working? I don't see a link to the CI job.

@iorsh
Copy link
Copy Markdown
Contributor

iorsh commented Aug 5, 2024

Please update Python version in CMakeLists.txt
find_package_auto(ENABLE_PYTHON_SCRIPTING Python3 3.6 COMPONENTS Development Interpreter)

@skef
Copy link
Copy Markdown
Contributor

skef commented Aug 5, 2024

do you want to CC specific people who might want to weigh in here?

Nah. If they wanna look they can look.

@JoesCat
Copy link
Copy Markdown
Contributor

JoesCat commented Aug 5, 2024 via email

The Py_SetProgramName() function used by fontforge is deprecated and
was removed in Python 3.13 alpha 1.

Replace the deprecated function with the PyConfig API. If the Python
initialization fails, log an error to stderr and call exit(1).

CMakeLists.txt: change Python minimum version to 3.8.
@vstinner
Copy link
Copy Markdown
Contributor Author

vstinner commented Aug 5, 2024

Please update Python version in CMakeLists.txt

Done.

@vstinner
Copy link
Copy Markdown
Contributor Author

vstinner commented Sep 2, 2024

@iorsh: Would you mind to review the updated PR?

@iorsh
Copy link
Copy Markdown
Contributor

iorsh commented Sep 3, 2024

@skef, could you please approve CI workflows?

@iorsh
Copy link
Copy Markdown
Contributor

iorsh commented Sep 3, 2024

CI is broken, issue unrelated to this PR. I'll need to take a look.

@iorsh
Copy link
Copy Markdown
Contributor

iorsh commented Sep 3, 2024

@JoesCat , could you please downgrade autoconf requirement in libspiro to 2.69 (see https://github.com/fontforge/libspiro/blob/da2d627d4147e75bada0f3923c262ada81cbec76/configure.ac#L6)?
Ubuntu 20.04 only has autoconf 2.69, and now its CI action is broken.

JoesCat added a commit to fontforge/libspiro that referenced this pull request Sep 3, 2024
AC_PREREQ(2.70) downgraded to 2.69 for ELN distros, as explained here:
fontforge/fontforge#5404 (comment)
@JoesCat
Copy link
Copy Markdown
Contributor

JoesCat commented Sep 3, 2024

Wheels of progress are quick. Updated to 1.5 now with change added for 2.69.

Copy link
Copy Markdown
Contributor

@iorsh iorsh left a comment

Choose a reason for hiding this comment

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

Looks good to me now

@vstinner
Copy link
Copy Markdown
Contributor Author

CI is broken, issue unrelated to this PR. I'll need to take a look.

The Linux CI fails with:

/home/runner/work/fontforge/fontforge/repo/.github/workflows/scripts/setup_linux_deps.sh: line 37: pushd: libuninameslist: No such file or directory
/home/runner/work/fontforge/fontforge/repo/.github/workflows/scripts/setup_linux_deps.sh: line 38: pushd: woff2: No such file or directory

@iorsh
Copy link
Copy Markdown
Contributor

iorsh commented Sep 24, 2024

/home/runner/work/fontforge/fontforge/repo/.github/workflows/scripts/setup_linux_deps.sh: line 37: pushd: libuninameslist: No such file or directory
/home/runner/work/fontforge/fontforge/repo/.github/workflows/scripts/setup_linux_deps.sh: line 38: pushd: woff2: No such file or directory

That was libspiro, I think. Try to force push to trigger CI again, linux should be good now. Mac still broken though...

@vstinner vstinner closed this Sep 25, 2024
@vstinner vstinner reopened this Sep 25, 2024
@vstinner
Copy link
Copy Markdown
Contributor Author

The CIs were stuck. I close/reopen the PR to force new CI jobs.

@vstinner
Copy link
Copy Markdown
Contributor Author

@iorsh:

Try to force push to trigger CI again, linux should be good now.

I pushed an empty commit and then closed/reopened the PR, but CIs don't want to start. They are stuck at "Expected — Waiting for status to be reported" with no "Details" link.

Copy link
Copy Markdown
Contributor

@skef skef left a comment

Choose a reason for hiding this comment

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

LGTM

@skef
Copy link
Copy Markdown
Contributor

skef commented Oct 7, 2024

@iorsh for whatever reason the mac job is hanging before getting picked up by a server. Could the OS version be wrong/unavailable?

@vstinner
Copy link
Copy Markdown
Contributor Author

vstinner commented Oct 7, 2024

Oh, I forgot to call PyConfig_Clear(): it's now fixed.

@iorsh
Copy link
Copy Markdown
Contributor

iorsh commented Oct 7, 2024

This and all other PRs are still based on macos-11 runner, which is dead. Now, as #5423 is merged, they all need to be merged/rebased to the latest master for CI to pass.

@vstinner, could you please merge/rebase?

@skef
Copy link
Copy Markdown
Contributor

skef commented Oct 7, 2024

It's working now.

@skef skef merged commit 2f2ba54 into fontforge:master Oct 7, 2024
@vstinner vstinner deleted the pyconfig branch October 7, 2024 09:45
@vstinner
Copy link
Copy Markdown
Contributor Author

vstinner commented Oct 7, 2024

Thank you.

Comment thread fontforge/python.c
SetPythonProgramName("fontforge");
PyConfig config;
PyStatus status;
PyConfig_InitPythonConfig(&config);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since this is an embedded usecase, should this be PyConfig_InitIsolatedConfig instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It depends on the behavior that you want. Isolated mode ignores env vars for example. I used Python mode to avoid behavior changes, only to use the new API.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yes, not changing the behavior in a refactor makes a lot of sense.

I think there's an argument to changing from this current behavior, too, since it doesn't make too much sense to me to prioritize the current working directory to load (say) pkg_resources over what's in the system path, yet that's what's done today. (The first entry in sys.path is the empty string, which loads from the current directory.)

PyObject *pkgres = PyImport_ImportModule("pkg_resources");
if (pkgres == NULL || !PyObject_HasAttrString(pkgres, "iter_entry_points")) {
LogError(_("Core python package 'pkg_resources' not found: Cannot discover plugins\n"));

The current behavior has shades of DLL hijacking where running the application in the wrong directory causes unintentional code execution.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You may open a new issue since this PR is closed.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thank you for the encouragement. I have opened #5515.

spectral-smith97op added a commit to spectral-smith97op/libspiro that referenced this pull request Sep 28, 2025
AC_PREREQ(2.70) downgraded to 2.69 for ELN distros, as explained here:
fontforge/fontforge#5404 (comment)
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.

6 participants