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

How to run Python scripts in the code folder non-interactively #71

Open
Robinlovelace opened this issue Jul 2, 2022 · 12 comments
Open
Assignees
Labels
help wanted Extra attention is needed question Further information is requested

Comments

@Robinlovelace
Copy link
Contributor

For minimal dependency testing. Am thinking of a CI workflow that does not depend on Quarto which is a bit niche and which still has no dedicated quarto package on pypi.

@Robinlovelace
Copy link
Contributor Author

Two main options:

Plan to go with latter for now as more concise.

@Robinlovelace
Copy link
Contributor Author

This works fine but seems to get blocked when the plot below is generated.

image

Robinlovelace added a commit that referenced this issue Jul 2, 2022
github-actions bot pushed a commit that referenced this issue Jul 2, 2022
@Robinlovelace
Copy link
Contributor Author

This is really bugging me: simply running

python code/chapters/02-spatial-data.py

fails because matplotlib seems to block execution of the script until the plot popup has been manually closed. That seems weird, bad design, or I'm missing something. I have tried to debug this: https://www.google.com/search?channel=fs&client=ubuntu&q=run+python+code+non+interactive+plots+bash

Any ideas?

Robinlovelace added a commit that referenced this issue Jul 2, 2022
Also: convert .py and .ipynb files
github-actions bot pushed a commit that referenced this issue Jul 2, 2022
Also: convert .py and .ipynb files 4c93ffa
Robinlovelace added a commit that referenced this issue Jul 2, 2022
github-actions bot pushed a commit that referenced this issue Jul 2, 2022
@Robinlovelace Robinlovelace changed the title Add script to run all Python scripts in the code folder Run all Python scripts in the code folder non-interactively Jul 2, 2022
@Robinlovelace Robinlovelace added the bug Something isn't working label Jul 2, 2022
@michaeldorman
Copy link
Collaborator

This is really bugging me: simply running

python code/chapters/02-spatial-data.py

fails because matplotlib seems to block execution of the script until the plot popup has been manually closed. That seems weird, bad design, or I'm missing something. I have tried to debug this: https://www.google.com/search?channel=fs&client=ubuntu&q=run+python+code+non+interactive+plots+bash

Any ideas?

Perhaps we can test the .ipynb files, using jupyter nbconvert --execute --to html 02-spatial-data.ipynb? This should fail if there is an error in any code cell

@Robinlovelace
Copy link
Contributor Author

I tried this but it has the same problem: figures pop up and it seems execution is paused until they are manually closed. V. annoying feature, unless I have missed something.

@Robinlovelace
Copy link
Contributor Author

See here my attempt at getting in working. Interested to know if others can reproduce the issue: https://github.com/geocompr/py/blob/main/run-code.sh

@michaeldorman
Copy link
Collaborator

I tried this but it has the same problem: figures pop up and it seems execution is paused until they are manually closed. V. annoying feature, unless I have missed something.

I don't see figures popup with jupyter nbconvert locally. The command just executes, creating an HTML file if successful, or prints error otherwise
Screenshot from 2022-07-02 14-11-46

@Robinlovelace
Copy link
Contributor Author

Aha, yes that is a good solution. I was conflating ipython with jupyter convert 👍 will add a command that does that now...

@Robinlovelace
Copy link
Contributor Author

Can you reproduce the issue with python /code/chapters/02*.py etc? Keen to find a way to a solution to that issue but more due to curiosity than necessity: it should be possible!

Robinlovelace added a commit that referenced this issue Jul 2, 2022
@Robinlovelace
Copy link
Contributor Author

Good news, after the commit above this is fixed! Will leave this open for a bit in case anyone knows how to get the .py files running non interactively but basically this one is fixed.

@Robinlovelace Robinlovelace added help wanted Extra attention is needed question Further information is requested and removed bug Something isn't working labels Jul 2, 2022
@Robinlovelace Robinlovelace changed the title Run all Python scripts in the code folder non-interactively How to run Python scripts in the code folder non-interactively Jul 2, 2022
@anisotropi4
Copy link
Contributor

It's good if you have found a fix for this but there it is a known feature in which matplotlib blocks waiting for keyboard input when you generate a plot GUI. There are other things you can do, for example you can pause for a given period of time rather than block , but this is a matplotlib foible based on its use of another-application-to-render-image...

@Robinlovelace
Copy link
Contributor Author

Any ideas how to do this Will? I tried a number of suggested solutions I found online but none of them worked! Reproducible code examples welcome here. In the meantime I will open a new issue to run the code in an action to pick up on issues like that in #66

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants