-
-
Notifications
You must be signed in to change notification settings - Fork 503
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
Modularization fixes for fast_callable
interpreters
#35774
Merged
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b54a5c5
src/sage/ext/fast_callable.pyx: Fall back to more general interpreterβ¦
mkoeppe c5033e7
src/sage_setup/autogen/interpreters/__init__.py: Support building a sβ¦
mkoeppe 814e264
sage_setup.autogen.interpreters: Update imports in doctests
mkoeppe eb373b0
src/sage/ext/fast_callable.pyx: Fix doctest
mkoeppe 11c5372
src/sage/ext/fast_callable.pyx: Fill in doctest output
mkoeppe 15e8698
src/sage_setup/autogen/interpreters: Add missing imports to doctests
mkoeppe 210f27b
src/sage_setup/autogen/interpreters: Add another missing imports to dβ¦
mkoeppe 12c04b8
src/sage_setup/autogen/interpreters/__init__.py: Add doc and test
mkoeppe afd3be6
src/sage/ext/fast_callable.pyx: Add tests
mkoeppe d5812e4
src/sage_setup/autogen/interpreters/__init__.py: Fix doctest
mkoeppe 97135ad
src/sage_setup/autogen/interpreters/specs/rdf.py: Avoid gratuitous usβ¦
mkoeppe 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 |
---|---|---|
|
@@ -119,25 +119,10 @@ | |
from .instructions import * | ||
from .memory import * | ||
from .specs.base import * | ||
from .specs.cdf import * | ||
from .specs.element import * | ||
from .specs.python import * | ||
from .specs.rdf import * | ||
from .specs.rr import * | ||
from .specs.cc import * | ||
from .storage import * | ||
from .utils import * | ||
|
||
|
||
# Gather up a list of all interpreter classes imported into this module | ||
# A better way might be to recursively iterate InterpreterSpec.__subclasses__ | ||
# or to use a registry, but this is fine for now. | ||
_INTERPRETERS = sorted(filter(lambda c: (isinstance(c, type) and | ||
issubclass(c, InterpreterSpec) and | ||
c.name), | ||
globals().values()), | ||
key=lambda c: c.name) | ||
|
||
# Tuple of (filename_root, extension, method) where filename_root is the | ||
# root of the filename to be joined with "_<interpreter_name>".ext and | ||
# method is the name of a get_ method on InterpreterGenerator that returns | ||
|
@@ -157,6 +142,7 @@ def build_interp(interp_spec, dir): | |
EXAMPLES:: | ||
|
||
sage: from sage_setup.autogen.interpreters import * | ||
sage: from sage_setup.autogen.interpreters.specs.rdf import RDFInterpreter | ||
sage: testdir = tmp_dir() | ||
sage: rdf_interp = RDFInterpreter() | ||
sage: build_interp(rdf_interp, testdir) | ||
|
@@ -174,7 +160,7 @@ def build_interp(interp_spec, dir): | |
write_if_changed(path, method()) | ||
|
||
|
||
def rebuild(dirname, force=False): | ||
def rebuild(dirname, force=False, interpreters=None, distribution=None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you're adding arguments, can you add the missing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done in 12c04b8 |
||
r""" | ||
Check whether the interpreter and wrapper sources have been written | ||
since the last time this module was changed. If not, write them. | ||
|
@@ -194,6 +180,20 @@ def rebuild(dirname, force=False): | |
# you run it). | ||
print("Building interpreters for fast_callable") | ||
|
||
if interpreters is None: | ||
interpreters = ['CDF', 'Element', 'Python', 'RDF', 'RR', 'CC'] | ||
|
||
from importlib import import_module | ||
|
||
_INTERPRETERS = [getattr(import_module('sage_setup.autogen.interpreters.specs.' + interpreter.lower()), | ||
interpreter + 'Interpreter') | ||
for interpreter in interpreters] | ||
|
||
if distribution is None: | ||
all_py = 'all.py' | ||
else: | ||
all_py = f'all__{distribution.replace("-", "_")}.py' | ||
|
||
try: | ||
os.makedirs(dirname) | ||
except OSError: | ||
|
@@ -213,7 +213,7 @@ class NeedToRebuild(Exception): | |
try: | ||
if force: | ||
raise NeedToRebuild("-> Force rebuilding interpreters") | ||
gen_file = os.path.join(dirname, 'all.py') | ||
gen_file = os.path.join(dirname, all_py) | ||
if not os.path.isfile(gen_file): | ||
raise NeedToRebuild("-> First build of interpreters") | ||
|
||
|
@@ -235,5 +235,5 @@ class NeedToRebuild(Exception): | |
for interp in _INTERPRETERS: | ||
build_interp(interp(), dirname) | ||
|
||
with open(os.path.join(dirname, 'all.py'), 'w') as f: | ||
with open(os.path.join(dirname, all_py), 'w') as f: | ||
f.write("# " + AUTOGEN_WARN) |
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
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
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.
I can see what's going on from the diff, but if someone comes along a year from now, this docstring isn't really going to explain what the function is doing and why. Can you expand it a little?
Also, if possible, can you test the import-failure code path?
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.
This was just mechanical refactoring of code that was nested a bit too deep. Let me see if I remember what it is doing, after a mere 4 days, not a year...
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.
done in afd3be6