-
-
Notifications
You must be signed in to change notification settings - Fork 510
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
src/bin/sage-cython
: Repurpose as PEP 420 fixer
#37009
Open
mkoeppe
wants to merge
1
commit into
sagemath:develop
Choose a base branch
from
mkoeppe:sage-namespace-cython
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+21
−31
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,26 @@ | ||
#!/usr/bin/env sage-python | ||
#!/usr/bin/env python | ||
|
||
# This script is a deprecated wrapper around the "cython" program. | ||
# It is deprecated since Issue #27041 (Sage 8.7) because one should | ||
# This script is a wrapper around the "cython" program. | ||
# It was deprecated in Issue #27041 (Sage 8.7) because one should | ||
# simply use "cython" directly. We display deprecation messages whenever | ||
# "sage-cython" does something different from plain "cython". | ||
# | ||
# A stronger deprecation warning was added in #29923 (Sage 9.2). | ||
# | ||
# In Sage 10.3, the deprecated functionality is removed permanently. | ||
# However, the script is un-deprecated and re-purposed as a temporary workaround | ||
# for defects in Cython 3.0.x support for PEP 420 implicit namespace packages, | ||
# see https://github.com/sagemath/sage/pull/36228 | ||
# | ||
# This script can be used as a replacement for "cython". | ||
# For example, to have meson use it, set the environment variable | ||
# CYTHON to sage-cython./ | ||
# https://github.com/mesonbuild/meson/blob/e4bbc630b67ef97ad842badd00855e64cff12e13/mesonbuild/envconfig.py#L91 | ||
|
||
import os | ||
import sys | ||
args = sys.argv[1:] | ||
|
||
sys.stderr.write("WARNING: the script sage-cython is deprecated; use cython instead.\n") | ||
|
||
from sage.env import SAGE_SRC | ||
|
||
# args can have length 0, in case we're printing a usage message (see trac 12207) | ||
pyx_file = os.path.abspath(args[-1]) if len(args) else None | ||
include_sage_flags = False | ||
|
||
if pyx_file and pyx_file.startswith(SAGE_SRC): | ||
sys.stderr.write("WARNING: in the future, sage --cython will not add special flags for files in Sage sources.\n") | ||
include_sage_flags = True | ||
|
||
if '-sage' in args: | ||
sys.stderr.write("WARNING: sage --cython -sage is deprecated.\n") | ||
include_sage_flags = True | ||
args.remove('-sage') | ||
elif '-no-sage' in args: | ||
sys.stderr.write("WARNING: sage --cython -no-sage is deprecated, remove the -no-sage flag.\n") | ||
include_sage_flags = False | ||
args.remove('-no-sage') | ||
from sage.misc.package_dir import cython_namespace_package_support | ||
|
||
if include_sage_flags: | ||
args = ['--embed-positions', '-I%s' % SAGE_SRC] + args | ||
# console scripts declared in https://github.com/cython/cython/blob/master/setup.py#L68 | ||
from Cython.Compiler.Main import setuptools_main | ||
|
||
args.insert(0, 'sage-cython') | ||
os.execlp('cython', *args) | ||
with cython_namespace_package_support(): | ||
setuptools_main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't un-deprecate this. Instead it should be removed in favor of using an unpatched version of cython.
Right now, compiling cython files that use sage modules is broken because of namespace packages, and patching cython here and in sage_setup gives the misleading impression that it works.
This is the opposite of "fitting in the python/cython ecosystem".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that it is a "temporary workaround".
Anyone report the namespace problem to Cython upstream yet?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Temporary hack. And when/if cython fixes it we still have to ship the hack since distros are slow updating cython, etc.
Let's stick to stable features, not the bleeding edge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tornaria Kindly limit the use of fighting words such as "hack".
We have been successfully using Cython with namespace packages ever since 2021.
If anything, it is that our porting effort to Cython 3 is incomplete.