BruceSherwood / vpython-jupyter

This repository has been moved to https://github.com/vpython/vpython-jupyter
64 stars 33 forks source link

Change import structure to delay canvas render until necessary #59

Closed mwcraig closed 5 years ago

mwcraig commented 6 years ago

This pull request makes a number of changes to the way imports are done in vpython.

The intent is to not make any substantive changes to the names currently available to the user when they from vpython import *. Differences from current behavior are described below this overview.

Another significant change is moving RateKeeper2 and rate into rate_control.py.

All of the test programs (notebook and no-notebook) run with this with one exception: the notebook where you are supposed to be able to click on something and have it turn red doesn't work (it displays but clicking doesn't make it red).

The package still automatically decides whether to launch the notebook or no-notebook machinery.

These things need to be finished/decided before this is ready to merge:

I don't have strong feelings about the "decides", I just don't know enough about what they do to know if users should see them by default.

List of names the user no longer gets with from vpython import *

Note that there are almost all either

If there are any of these that should be available it is easy to make them available.

Names no longer available:

mwcraig commented 6 years ago

Turns out that in the no-notebook case I completely removed MISC and GSprint. Didn't mean to...but are they necessary? Doesn't seem to have stopped the demos from working.

BruceSherwood commented 6 years ago

MISC and GSprint should be restored. Though it's currently undocumented, and don't do the right thing in a notebook, they combine to make GSprint(.....) place text at the bottom of the web page instead of in the area to which print(....) is sent in such environments as spyder.

Matt, I now know more about Git than I did, but I don't know exactly what to do to test your work on my computer. Exactly what actions do I need to perform to get the contents of your pull request into a non-master branch to test?

Bruce

On Sat, Sep 1, 2018 at 9:49 PM Matt Craig notifications@github.com wrote:

Turns out that in the no-notebook case I completely removed MISC and GSprint. Didn't mean to...but are they necessary? Doesn't seem to have stopped the demos from working.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/BruceSherwood/vpython-jupyter/pull/59#issuecomment-417901025, or mute the thread https://github.com/notifications/unsubscribe-auth/ABE0L7O8W8AxHOCrlkq5GxtaMUhnN_73ks5uW0c_gaJpZM4WWcTx .

mwcraig commented 6 years ago

Bruce -- I'll be pushing a couple other little changes in the next 30 min, but the instructions for trying out the branch are below. They the command line arguments you would use; some of it is almost certainly possible is SmartGit instead.

If you use Python environments you might want to make a new one for testing this, but that isn't necessary.

The instructions below assume you want to see this changes in the git folder you already have for VPython. If you want to make a clean copy, you could clone my version from here https://github.com/mwcraig/vpython-jupyter.git and then check out the branch refactor-imports. You would want to do that cloning in an empty directory to avoid clobbering what you already have.

In any event, the all-in-one-repo version:

# Get into the directory where your git repo of vpython-jupyter lives, and then..

# Let git know about my fork of the repo on github. You can use any name you want in place
# of mwcraig. I tend to name it for the github username of whoever's fork it is.
git remote add mwcraig https://github.com/mwcraig/vpython-jupyter.git

# Check that the remote was added (you will have at least two remotes, the one you just added
# and one likely called "origin" which is the one from which you originally cloned. You may have more.
git remote -v

# That only added the name of the remote. The next line pulls information about the names
# of branches, etc, from all of the remotes.
git fetch --all

# Now you want to check out my branch. If you used something other than "mwcraig" for
# the name of the remote above you will need to change the mwcraig below too.
git checkout -b refactor-imports mwcraig/refactor-imports

# Do a git status to make sure you are where you mean to be
git status

# Note that your local copy of the git repo now has a branch called refactor-imports
# If you just want to try my changes then you are done. As I add new commits you can
# pull them in to your local copy with 
git pull mwcraig refactor-imports

# IMPORTANT NOTE: If you want to make changes to this branch I would make a new branch
# from mine first. Checkout the branch as above, then make a new branch (use whatever name 
# for it you want)
git checkout -b refactor-imports-bruce

# Then, as you make changes and commit them you don't have to worry about my changes 
# getting in your way.

# To switch between the branches use (no -b)
git checkout branch_you_want
mwcraig commented 6 years ago

Does MISC need to be exposed to the user too, or just GSprint?

BruceSherwood commented 6 years ago

The user doesn't need access to MISC; it's a helper class for GSprint; it makes possible connections to the JavaScript program. I'll mention that GSprint places text into html "body", below canvases and graphs. In the notebook case, this doesn't actually work; the text goes into the very end of the web page, not into the display area.

mwcraig commented 6 years ago

Almost ready to push one more set of changes (last for today I hope). Some of the demos use time from the standard library. Should I add that back to the things import with from vpython import * or add import time to the demos?

mwcraig commented 6 years ago

I am now done for the day if you want to test...

BruceSherwood commented 6 years ago

Concerning time, from the first page of the Help at glowscript.org:

As a convenience to novice programmers to provide everything that is needed to get started, VPython by default imports all of the VPython features and includes standard math functions such as sqrt. The documentation is written as though "from vpython import *" were present. Also provided are clock(), random(), and arange().

mwcraig commented 6 years ago

Thanks for the link -- I've made a note in the "to do" list at the top of this to make sure clock and random are both present (I know arange already is).

mwcraig commented 6 years ago

Oy. The travis stuff needs to be re-written a bit for the tests to run the way I want them to. Right now the tests always run in the latest version of python (3.7), which has a new function remainder in math, which surprises the tests. FIxing that on Thursday...

mwcraig commented 6 years ago

I think I've fixed the tests that were failing. I've opened #61 and #63 to keep track of some travis issues that need fixing.

mwcraig commented 5 years ago

:takes deep breath: -- merging this in!