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

Reinstate pymathics doc #778

Merged
merged 10 commits into from
Feb 7, 2023
Merged

Reinstate pymathics doc #778

merged 10 commits into from
Feb 7, 2023

Conversation

rocky
Copy link
Member

@rocky rocky commented Feb 5, 2023

This allows Mathics3 Modules loaded via -l or --load-module on the docpipetest.py command like to get loaded
using eval_LoadModule the underlying eval method for LoadModule[].

In other words, from Mathics3 core you can test Mathics3 Modules or select individual sections Mathics3 Module tests. But that also means, we are collecting XML-like documentation and test data which can then be put into the LaTeX-generated PDF.

I believe the information will go into the PCL (Python Pickle file), but I haven't tested that yet.

And I haven't looked at the piece that puts creates documentation.tex (mathics/doc/latex/doc2latex.py)

I think that will be another (small) PR. This is large enough as it is.

For expediency in being able to get this accomplished over the weekend in a limited time, there are/were several separable commits here. I am sure you know the pattern - you want to get X done but bug Y gets in the way. So you fix Y, and then bug Z pops up.

Over the week I will try to extract these so that they can be reviewed/discussed independently.

Here are two that I can think of though.

I would like to change the name Pymathics or Pymathics module to the simpler "Mathics3 Module" which has always been loaded via LoadModule.

The messages when a Mathics3 Module can't be loaded have been changed.

@rocky rocky marked this pull request as draft February 5, 2023 13:54
@rocky rocky force-pushed the reinstate-pymathics-doc branch from 6289259 to 3e3aba8 Compare February 5, 2023 13:56
@rocky rocky mentioned this pull request Feb 5, 2023
@rocky rocky force-pushed the reinstate-pymathics-doc branch from 3e3aba8 to e6f50d1 Compare February 5, 2023 20:26
rocky added a commit to Mathics3/mathics-django that referenced this pull request Feb 5, 2023
DRY code. docpipeline.py `-l` `--pymathics` probably works now

These changes cannot get merge before
Mathics3/mathics-core#778 is merged.
@rocky rocky force-pushed the reinstate-pymathics-doc branch 2 times, most recently from 46d7d20 to f86cfa9 Compare February 6, 2023 01:30
@rocky rocky force-pushed the reinstate-pymathics-doc branch from f86cfa9 to f885591 Compare February 6, 2023 01:47
self.title = "Overview"
files = listdir(self.doc_dir)
Copy link
Member Author

@rocky rocky Feb 6, 2023

Choose a reason for hiding this comment

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

A programmer who writes such a long piece of code like this without a single comment and in an __init__ method, should be graduated out of programming.

@rocky rocky force-pushed the reinstate-pymathics-doc branch from 4ab3e39 to 710339f Compare February 6, 2023 02:17
= $Failed
"""

name = "LoadModule"
messages = {
"notfound": "Python module `1` does not exist.",
"notmathicslib": "Python module `1` is not a pymathics module.",
"notfound": """Problem importing Python module: `1`.""",
Copy link
Contributor

Choose a reason for hiding this comment

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

If LoadModule produces the error notfound, it is because the module can not be found, not because there was a generic error in importing it. So, why the new message is better?

Copy link
Member Author

@rocky rocky Feb 6, 2023

Choose a reason for hiding this comment

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

There is a difference between something existing and something importing. In fact, another check could be made to see if the file or module exists and give that message. The file or module may exist, but there is invalid Python or it may import modules that are not importable or cause circular dependencies.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, but the error we handle in importing the python module is about the existence of the library.

Copy link
Member Author

Choose a reason for hiding this comment

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

"Exist" is a vague or misleading word. The library can exist in some sense but not work. When I see an error message or warning I generally want to know what was tried. What was tried is that we ran a Python kind of "import": and that did not work,.

Copy link
Contributor

Choose a reason for hiding this comment

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

In Python, what we are capturing is:

>>> import amadeupmodulename
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'amadeupmodulename'

So, maybe "Python module 1 was not found in the system"
could be a more accurate message, isn't it?

Copy link
Member Author

@rocky rocky Feb 6, 2023

Choose a reason for hiding this comment

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

There is a difference here. You issued the import from Python and not "not found" was given in response to that. So it is clear that Python import is where the problem lies. In Mathics3 though, the user a priori doesn't know that LoadModule runs a Python import underneath. It could have loaded the module using open() and done some magic there.

So using the words Python and import suggest what kind of thing is failing. In fact it suggests trying to run a Python "import".

Copy link
Contributor

Choose a reason for hiding this comment

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

What about Pymathics module `1` was not found in the system? Otherwise, it was just a suggestion. Please just keep it as you prefer.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have been thinking about this some more. I do listen to your suggestions...

I think we can get the best of both worlds by catching any Python exception and passing back the message in the exception. In those cases where Python reports "not found" the message has that (indicating this is from an import).

In fact, it was probably a mistake using except ImportError rather then except Exception.

@@ -689,251 +1017,32 @@ def __str__(self):
return self.test


# FIXME: think about - do we need this? Or can we use DjangoMathicsDocumentation and
# LatTeXMathicsDocumentation only?
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we using this? Maybe we could replace it with a function that produces the right class of object.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, we are using this. Merging the two is another mess that I don't want to deal with right now.

If you want to try to do it go head. I will note that there are still lots of opportunities for DRYing the code and improving it

The motivation here was simply that we had code in Django to handle Mathics3 Modules and I wanted that used on the LaTeX/PDF side. So moving this code to common code seemed like the way to do this which both accomplishes what I want to do while improving the code.

However in doing so there have been small breakages here and there precisely because there were two sets of code and an improvement or necessary change was made in one copy but not the other. And the one with the improvement did not make it to the common code.

Last weekend I had my fill of trying to find and fix these kinds of things. Doing more in order to DRY the code more is left for the future for me.

@mmatera
Copy link
Contributor

mmatera commented Feb 6, 2023

Apart from my comments, and the need of merging first #781 to avoid the hanging, LGTM.

@mmatera
Copy link
Contributor

mmatera commented Feb 6, 2023

There is another thing: for some reason, the pymathics module is not loaded when the module doctests are run

@rocky
Copy link
Member Author

rocky commented Feb 6, 2023

There is another thing: for some reason, the pymathics module is not loaded when the module doctests are run

Works for me:

pyston mathics/docpipeline.py -x -l pymathics.graph -s BinomialTree
Mathics3 Module pymathics.graph loaded
Testing section(s): BinomialTree
Testing section: Graphs - Vertices and Edges / BinomialTree
b'   1 ( 0): TEST BinomialTree[3]'

What do you get when you run pyston mathics/docpipeline.py -x -l pymathics.graph -s BinomialTree

@rocky rocky marked this pull request as ready for review February 7, 2023 14:28
mmatera added a commit that referenced this pull request Feb 7, 2023
This PR fixes another issue with precision. In particular, this issue
was the reason of the hangings in doctest in #778.
rocky added 9 commits February 7, 2023 12:39
Move code from django_doc and latex_doc .py to common_doc.py

In the process we should handle pymathics better.

Remove a number of unused functions and variables like ``is_private``
and pymathics_doc_loaded.
See if we can get by with out using the want_sorting parameter
Pull out flaky Unique[] doctests and start a more robust pytest for
these.

more work is needed.
Fix bug in InterpretedBox
Reinstate hard-coded XMLDoc where self.doc_fn() is not available
Reinstante want_sorting option
--pymathics -> --load-module. Note that one splits module names with a
  comma.

The name Pymathics is deprecated
This should make it a little more robust.
@rocky rocky force-pushed the reinstate-pymathics-doc branch from 3e1f91a to e62333f Compare February 7, 2023 17:39
@rocky rocky merged commit 9a7ed16 into master Feb 7, 2023
@rocky rocky deleted the reinstate-pymathics-doc branch February 7, 2023 19:07
rocky added a commit to Mathics3/mathics-django that referenced this pull request Feb 12, 2023
* DRY doc code

Much has been moved to mathics.doc.mathics.common now

* Simplify:

Remove bogus default_pymathics_modules
See if we can get by without want_sorting

* Reduce custom doc code...

DRY code. docpipeline.py `-l` `--pymathics` probably works now

These changes cannot get merge before
Mathics3/mathics-core#778 is merged.

* Reinstante guide section summaries

* Reinstate want_sorting option

* Remove "remake" for now

* want sorting parameter adjustment
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.

2 participants