-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Improve Invoke task handling on Windows #8
Conversation
Allows tasks to work on Windows https://github.com/getpelican/pelican/blob/master/tasks.py @ 27762d2cf70fd76f0f3f76ea02b7cf8bfa4e1236
c.f. #5 |
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.
The way that virtual environments were intended to be handled is (1) use the active virtual environment if present, and if not, (2) create and manage the virtual environment automatically via Poetry. I think allowing Poetry to transparently create and manage virtual environments provides a more seamless solution for folks who don't want/need to manually manage environments, so I'm not sure what benefits would accrue from duplicating that effort in the setup()
Invoke task.
@MinchinWeb: Thanks for the enhancements. I raised a question about how virtual environments are created & managed, along with a few other suggestions. ✨
I think having the extra pair of eyes can only benefit the project, so if you don't mind, perhaps we can merge PRs after review & consensus that they are ready? |
@MinchinWeb: Did you see my review comment above? In short, I'm not sure it makes sense to manually create virtual environments when Poetry can probably handle that part much more effectively. What do you think? |
I'm actually working on it right now :)
The problem is that's not what the code currently does. The first thing current code tries to upgrade pip in the virtual environment, and when it can't, it fails with the cryptic "The system cannot find the path specified." (Path for what??) I feel like since this is probably the very first thing a new contributor (or me, after being away for a few months) will encounter when trying to contribute to the project, it should at least give a more useful error message. I haven't used poetry a ton...I know it manages dependencies within a virtual environment, but can it set them up from scratch too? |
(cherry picked from commit 744fe28)
@justinmayer Poetry seems to be able to create virtual environments. See https://python-poetry.org/docs/basic-usage/#using-your-virtual-environment You can get the path to your current poetry virtual environment from the command line: |
I guess what I'm trying to say is I like the idea of poetry managing the virtual environments, but the current
|
I agree that making things easy for contributors, new and old alike, is a primary goal. That's precisely why I created the
Yes — that's what I was alluding to but apparently never said outright. Poetry will automatically create, activate, and manage virtual environments transparently. Many times users don't even need to interact with the environments at all.
I'm sure there are potential enhancements to be made, but understand that we assume that would-be contributors will read the documentation thoroughly and follow the provided How to Set Up Your Development Environment instructions. For example, in this case, the documentation suggests that Poetry be installed via:
Plus, in those same docs, we encourage folks who understand how virtual environments work to manually create and activate them. But folks are free to allow Poetry to handle that chore, since Poetry is quite good at creating and activating environments.
If Poetry isn't installed via the command mentioned above, then we have a bootstrapping Catch-22, and we assume the user will follow our documentation to create their own virtual environment manually, and thus we assume Poetry will be installed into and available from that virtual environment.
These steps should not be necessary. If Poetry is installed via the above canonical install command, Poetry should automatically create and manage the virtual environment. I just ran through some tests and believe the problem you experienced can be rectified by changing one line in the @task
def setup(c):
tools(c)
c.run(f"{POETRY} run pip install -U pip")
c.run(f"{POETRY} install")
precommit(c) Bootstrapping is hard. If the user (1) doesn't have Poetry or Invoke globally-available and (2) has not created and activated a virtual environment, it's an indication that the instructions have not done the job somehow (or haven't been followed). That said, I think we could add some checks to |
Regarding the latter, this might do the trick: def setup(c):
if which("poetry") or ACTIVE_VENV:
tools(c)
c.run(f"{POETRY} run pip install -U pip")
c.run(f"{POETRY} install")
precommit(c)
else:
sys.exit(
"""Poetry is not installed, and there is no active virtual environment
available. You can either manually create and activate a virtual
environment, or you can install Poetry via:
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
Once you have taken one of the above two steps, run `invoke setup` again.
"""
) |
@justinmayer I used the code you suggested, and changed some other paths to lean more heavily on poetry. One issue I run into locally is the poetry-created venv has a name nothing like what the script assumes: it was created at |
Trying to do so, often will render you without any *pip* at all!
Since Poetry's environment handling is meant to be transparent, you have the right idea in not even attempting to retrieve and use its environment path. If someone is using Poetry to manage virtual environments, we should let Poetry handle them altogether if we can. I took slightly different approach to this question of whether there is an active virtual environment, or whether Poetry is handling that: https://github.com/getpelican/cookiecutter-pelican-plugin/compare/tasks-enhanced?expand=1 In short, I added a dynamic prefix to the various tools, which changes to What do you think? |
@justinmayer I like the approach you took. The one change I made was the call the variable |
One question: should we update the default VENV location? Here, it's |
I thought about that, but it felt strange to use that name in the case that the prefix ends up being
Ultimately this is a matter of personal preference, since there isn't a super-common convention. While I personally keep mine in |
Ok, both are updated! I am working on a couple new filters to support my theme, so in terms of releases, it may make sense to wait for those (before pushing out a new release). I'll create a pull request with them as soon as I've confirmed they're working. |
Looks good. Do you want to squash any of the irrelevant commits here (e.g,. via interactive rebase) before merge? Not strictly necessary, of course. Up to you. |
...I'm working to figure out how to do that... |
No worries. I have taken the liberty of squashing most of the commits together, as there was a bit of fix-up churn, and they were quite related to one another. It took me a while to figure out how to use Git's interactive rebase feature. This guide from a few years ago shows the basics: https://thoughtbot.com/blog/git-interactive-rebase-squash-amend-rewriting-history As an aside, if I were you, the following is probably how I would have handled this:
By the way, one should only do this when feeling confident that nobody else has cloned the branch and collaborated on it. In this case, I might have cloned the By the way, rather than cherry-pick my commit from Hopefully the above is somewhat helpful. Looking forward to the next collaboration! 😁 |
also upgrade the pre-commit hooks so Python 3.7 is no longer required c.f. pelican-plugins/jinja-filters#8
also upgrade the pre-commit hooks so Python 3.7 is no longer required c.f. pelican-plugins/jinja-filters#8
Some code clean-up to the 'tasks.py' file (for invoke) to allow the project to run cleaner on Windows. Most (all?) of these fixes are already in place in the main pelican code.
Also includes some code to create the virtual environment if it doesn't already exist.
@justinmayer : I'm not sure what you want to do for reviewing my PR's... Do you want to review and merge them yourself, or are you ok with me taking the lead on these?