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
patch #639
base: create-system_builtin-once
Are you sure you want to change the base?
patch #639
Conversation
Right now I am using The other thing that could be going wrong is some sort of delayed initialization that gets kicked off by importing the |
I added a comment in that direction. |
This moves builtin-creation out of mathics.builtin and core.definitions and into a new module. I thing this is the last step before we actually move builtin creation of the Definitions initialization and into some one-time code.
and add run pytest setting MATHICS_CHARACTER_ENCODING
b4ceab7
to
d8eeb84
Compare
This isn't working but this is the idea. Another PR will contain some of the independent bugs found in this process
d8eeb84
to
6436065
Compare
This moves builtin-creation out of mathics.builtin and core.definitions and into a new module. I thing this is the last step before we actually move builtin creation of the Definitions initialization and into some one-time code.
This isn't working but this is the idea. Another PR will contain some of the independent bugs found in this process
* adding comments * moving _initialize_system_definitions to a better place, and hide it. * fixing contribute in order to make work the pymathics loading mechanism without overwrite builtins
231b06f
to
53300f5
Compare
@rocky, |
Also, following #642, some imports in |
Thanks for isolating what's wrong and working around/fixing this. I'd like to understand why when a pymathics module gets loaded, system_definitons.builtin is overwritten. That seems wrong, no? All that code with a |
The problem comes with MakeBoxes rules. When a pymathics module "contributes" with a MakeBoxes rule, before this patch, a rule is added to With the workaround, if a pymathics module wants to add a rule to MakeBoxes, now it adds it to a definition in
The
But let's say that this is something "exceptional" (it happens at most once in the life of a |
Ok - so let see if we can get deepcopy to work or narrow the copy so something like this doesn't happen. |
The question is, do we want wo modify Definitions.builtin? If not, even the copy is not necessary. On the other hand if what bothers you is the try block, it can be easily replaced with a conditional structure. |
What bothers me is the layer upon layer of workaround, code and complexity because we aren't understanding the problem at the root cause or at a logical conceptual level. Let me look at this over the weekend so I understand what's going on at a higher level. You've given a lot of details as to what's up at an operational level, and that he helpful for understanding what is wrong at that level. |
At the higher level, what is wrong is how we process and store MakeBoxes rules. Notice also that to copy (or even deep copy) an object that should be immutable, to have several immutable copies of the same thing is already a workaround. Here there is an experimental branch where I show this: https://github.com/Mathics3/mathics-core/tree/create-system_builtin-once-mm-ro I have a couple of ideas about how to fix the way in which we handle MakeBoxes, but that would imply a lot of other changes that would make this harder to review. For this reason, the strategy that I am trying to propose since some time ago is to try to replace unlocalized workarounds (the ones that imply changing something in one module to fix something in another module) with workarounds localized inside a module, or even better, inside the function that should be fixed, which would be easier to document and correct
Sure.
I give many details because I think they are needed to understand what is actually going on. |
# both, which are not going to be in the cached version that | ||
# Definitions.get_definition provides. To make the new rules | ||
# accesible, we need to clear the definitions cache. | ||
definitions.clear_cache("System`MakeBoxes") |
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.
If this is only needed when pymathics modules are loaded, then why isn't this only in the branch of the if is_pymathics_module
branch?
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.
But then, I should duplicate lines 414 and 415 in both branches.
@@ -191,7 +192,12 @@ def __new__(cls, *args, **kwargs): | |||
# mathics.builtin.inout | |||
|
|||
if kwargs.get("expression", None) is not False: | |||
return to_expression(cls.get_name(), *args) | |||
try: |
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 my bad - should be removed.
6436065
to
7fee71c
Compare
Move system initialization module out of mathics.builtin. (Similar to PR #639) This also removes the need for Python to "partially initialize" mathics.builtin since it doesn't import one of its children
Move system initialization module out of mathics.builtin. (Similar to PR #639) This also removes the need for Python to "partially initialize" mathics.builtin since it doesn't import one of its children
Move system initialization module out of mathics.builtin. (Similar to PR #639) This also removes the need for Python to "partially initialize" mathics.builtin since it doesn't import one of its children
Move system initialization module out of mathics.builtin. (Similar to PR #639) This also removes the need for Python to "partially initialize" mathics.builtin since it doesn't import one of its children Merge mess
This is a patch that makes that the test passes. However, I think in means that the scheme proposed is not working as it should.