Skip to content

Add a Python virtual environment setup#133

Closed
ChrisEPhifer wants to merge 2 commits intotesting-tutorialfrom
cep/python-venv
Closed

Add a Python virtual environment setup#133
ChrisEPhifer wants to merge 2 commits intotesting-tutorialfrom
cep/python-venv

Conversation

@ChrisEPhifer
Copy link
Copy Markdown
Collaborator

This is an attempt to make the CN tutorial build a bit more portable, utilizing Python's virtual environments.

TL;DR:

  • New scripts/setup_env.sh that will create a Python venv with the necessary mkdocs packages to build the tutorial
  • Additions to the README to clarify necessary Python version & how to use the virtual environment

This is an attempt to make the development of CN tutorials more straightforward,
as far as setting up the Python build is concerned.

scripts/setup_env.sh handles creating a Python virtual environment suitable for
building the tutorial (that is, with the necessary dependencies).
This script tries to be relatively smart about not doing extra work.

The README has been updated to reflect these changes.
@ChrisEPhifer ChrisEPhifer requested a review from bcpierce00 April 23, 2025 20:51
@ChrisEPhifer ChrisEPhifer self-assigned this Apr 23, 2025
@bcpierce00
Copy link
Copy Markdown
Collaborator

Some concerns:

(1) Is there no way to do the python magic in the Makefile? I'm a bit nervous about how heavy this is getting, and whether it's going to work in all circumstances -- e.g., if I run make from an emacs compile command, it won't work (I guess) unless I fire up a whole new emacs from a shell where I've done the right incantation.

(2) Is the reason we need all this because we have one line of Python that's not compatible with 3.9?

@ChrisEPhifer
Copy link
Copy Markdown
Collaborator Author

Some concerns:

(1) Is there no way to do the python magic in the Makefile? I'm a bit nervous about how heavy this is getting, and whether it's going to work in all circumstances -- e.g., if I run make from an emacs compile command, it won't work (I guess) unless I fire up a whole new emacs from a shell where I've done the right incantation.

We can include a rule to run this setup in the Makefile. That was an oversight on my part. And it's no problem to then add the incantations necessary to keep make working in all circumstances.

Putting that aside, I'm not sure what about this is 'heavy'; could you clarify what you mean by that? The script is (perhaps) overly defensive, but what it is doing does not require anything other than python3. Plus, it won't do unnecessary work or slow doing the build process in any way.

(2) Is the reason we need all this because we have one line of Python that's not compatible with 3.9?

No; it is considered a best practice in Python development to make use of the virtual environments made available in the standard library. Relying on your system Python installation, and especially messing around with the system-wide Python packages, can cause all sorts of problems (like those you were running into earlier). Virtual environments provide isolated, unique-to-your-needs Python environments that are easily reproducible.

@ChrisEPhifer ChrisEPhifer changed the base branch from testing-tutorial to main April 24, 2025 19:13
@ChrisEPhifer ChrisEPhifer changed the base branch from main to testing-tutorial April 24, 2025 19:13
This rule simply runs scripts/setup_env.sh; more importantly, it is also a
dependency of the tutorial build/serve commands -- and the virtual environment
it creates is now used in those rules to run mkdocs in an isolated/sandboxed
manner (as was the intent behind introducing a virtual environment in the first
place).
@ChrisEPhifer ChrisEPhifer deleted the cep/python-venv branch April 24, 2025 22:11
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.

3 participants