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

Use more reliable method to run homebrew-pypi-poet #9391

Closed
wants to merge 1 commit into from
Closed

Use more reliable method to run homebrew-pypi-poet #9391

wants to merge 1 commit into from

Conversation

claui
Copy link
Contributor

@claui claui commented Dec 2, 2020

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew tests with your changes locally?
  • Have you successfully run brew man locally and committed any changes?

Update: Replacing the old method instead of adding to it.


This replaces the virtualenvwrapper method in the documentation with one based on the pipenv formula, a dependency manager that doubles as a virtualenvwrapper alternative.

A non-brewed installation of virtualenvwrapper is not always reliable.

For me, it fails like this:

$ source /Users/claudia/Library/Python/3.9/bin/virtualenvwrapper.sh
/usr/bin/python: No module named virtualenvwrapper
virtualenvwrapper.sh: There was a problem running the initialization hooks.
If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python and that PATH is
set properly.

It’s therefore useful to document a working alternative based on the pipenv formula, which is actually a dependency manager but doubles as a virtualenvwrapper alternative.

This also adds documentation on how to use poet on software that is not on PyPI.

Thanks again to @Rylan12 for technical help!

@BrewTestBot
Copy link
Member

Review period will end on 2020-12-03 at 20:32:43 UTC.

@BrewTestBot BrewTestBot added the waiting for feedback Merging is blocked until sufficient time has passed for review label Dec 2, 2020
@claui claui added documentation Documentation changes and removed waiting for feedback Merging is blocked until sufficient time has passed for review labels Dec 2, 2020
@BrewTestBot BrewTestBot added the waiting for feedback Merging is blocked until sufficient time has passed for review label Dec 2, 2020
Copy link
Member

@Rylan12 Rylan12 left a comment

Choose a reason for hiding this comment

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

Looks good assuming this worked as expected for you (it sounds like it did). I don't actually use pipenv so I can't really judge that part of it.

Just one question, is pipenv needed or can this be accomplished using a standard virtual environment (i.e. without the need to install pipenv).

Here's what seems to work for me:

# Use a temporary directory for the virtual environment
cd "$(mktemp -d)"

# Create and source a new virtual environment in the venv/ directory
python3 -m venv venv
source venv/bin/activate

# Install the package of interest as well as homebrew-pypi-poet
pip install some_package homebrew-pypi-poet
poet some_package

# Destroy the virtual environment
deactivate
rm -rf venv

And similarly (once in the virtual environment):

pip install homebrew-pypi-poet
poet -s requirements.in

Edit: I noticed this and commented in Slack, but figured I'd relay it here:

I don't know how common requirements.in files are, but the one that I saw did not contain any version info. This leads to poet always retrieving the latest version of the package which could, potentially, ignore version pinning/rules that exist in requirements.txt. For example, requirements.in may contain:

boltons

While requirements.txt may contain:

boltons==17.2.0

Using method number two, poet will retrieve the latest boltons version (20.2.1 as I'm writing this) instead of version 17.2.0. Because of this, we may not want to encourage people to use this method as it may lead to resource updates that are incorrect.

@claui
Copy link
Contributor Author

claui commented Dec 3, 2020

Just one question, is pipenv needed or can this be accomplished using a standard virtual environment (i.e. without the need to install pipenv).

I tried your suggestion and it fails for me:

$ python3 -m venv venv
$ source venv/bin/activate
$ pip install simple-rom-manager homebrew-pypi-poet
ERROR: Can not perform a '--user' install. User site-packages are not visible in this virtualenv.
WARNING: You are using pip version 20.2.3; however, version 20.3 is available.
You should consider upgrading via the '/private/var/folders/9k/72bcsqxd55q00scw81pt2f6h0000gp/T/tmp.ZtpH1gAB/venv/bin/python3 -m pip install --upgrade pip' command.

Using method number two, poet will retrieve the latest boltons version (20.2.1 as I'm writing this) instead of version 17.2.0. Because of this, we may not want to encourage people to use this method as it may lead to resource updates that are incorrect.

You’re right. I have removed that section. Thanks for the pointer!

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

I'd rather we figure out how to fix the original instructions rather than add an "alternatively" that may diverge over time and we're not really sure will work any more consistently.

@claui
Copy link
Contributor Author

claui commented Dec 3, 2020

we're not really sure will work any more consistently.

My tests on two different devices and OS versions have established that it does work more consistently than the other two alternatives (i.e. the original one and the one @Rylan12 has suggested).

I’m not sure we’re not overthinking this. Are we supposed to be risk averse with regards to the core software and core formulae? Yes, absolutely. Shall we be risk averse at updating out-of date documentation? I don’t know.

We can always revert later if my variant turns out to be wrong.

that may diverge over time

I wouldn’t mind just replacing the original instructions.

Replace the `virtualenvwrapper` method with one based on the `pipenv`
formula, a dependency manager but doubles as a `virtualenvwrapper`
alternative.

A non-brewed installation of virtualenvwrapper is not always reliable.

For me, it fails like this:

```
$ source /Users/claudia/Library/Python/3.9/bin/virtualenvwrapper.sh
/usr/bin/python: No module named virtualenvwrapper
virtualenvwrapper.sh: There was a problem running the initialization hooks.
If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python and that PATH is
set properly.
```
@claui claui changed the title Add more ways to run homebrew-pypi-poet Add more reliable way to run homebrew-pypi-poet Dec 3, 2020
@claui claui changed the title Add more reliable way to run homebrew-pypi-poet Use more reliable method to run homebrew-pypi-poet Dec 3, 2020
@claui
Copy link
Contributor Author

claui commented Dec 3, 2020

I'd rather we figure out how to fix the original instructions

@MikeMcQuaid Done; I replaced the original instructions.
Would appreciate someone other than myself to test this.

@MikeMcQuaid MikeMcQuaid dismissed their stale review December 3, 2020 15:36

Changes addressed.

@MikeMcQuaid
Copy link
Member

I’m not sure we’re not overthinking this. Are we supposed to be risk averse with regards to the core software and core formulae? Yes, absolutely. Shall we be risk averse at updating out-of date documentation? I don’t know.

I'm risk averse in adding an "alternatively" instead of either fixing whatever is broken originally.

I wouldn’t mind just replacing the original instructions.

Yup, this seems like a good idea if someone else can verify this. I've removed my objections to this PR being merged but I don't have enough context to comment on the changes here.

@claui
Copy link
Contributor Author

claui commented Dec 3, 2020

Yup, this seems like a good idea if someone else can verify this. I've removed my objections to this PR being merged but I don't have enough context to comment on the changes here.

Fair enough. Thanks for your thoughts and for the update @MikeMcQuaid 👍

@Rylan12
Copy link
Member

Rylan12 commented Dec 3, 2020

Would appreciate someone other than myself to test this.

I will take a look at this later today. It's worth noting, though, that my testing is not done from a clean install and so my environment may influence the results. Already, it seems that Claudia and I have had different results when trying an alternative solution. See #9391 (review) and #9391 (comment)

@BrewTestBot
Copy link
Member

Review period ended.

@BrewTestBot BrewTestBot removed the waiting for feedback Merging is blocked until sufficient time has passed for review label Dec 3, 2020
@Rylan12
Copy link
Member

Rylan12 commented Dec 3, 2020

Okay, here are my results. I will test three things:

  1. The existing method documented here
  2. @claui's method documented in this PR
  3. My method documented in Use more reliable method to run homebrew-pypi-poet #9391 (review)

Before each trial, I will reset my environment by running brew reinstall python and ensuring that python3 -m pip list returns the following: (which, according to the python@3.9 formula, is the expected baseline set of packages)

$ python3 -m pip list
Package    Version
---------- -------
pip        20.3
setuptools 50.3.2
wheel      0.35.1

The package that I will be testing with is snakemake. According to the snakemake formula there are several dependencies that should become resource blocks.

Note: I've included shortened versions of the outputs of each command. You can view the entire output here.

1. The existing method from the docs

$ python3 -m pip install virtualenvwrapper
<installs successfully>

$ source $(brew --prefix)/bin/virtualenvwrapper.sh
<runs successfully>

$ mktmpenv
<runs successfully>

$ pip3 install snakemake homebrew-pypi-poet
<installs successfully>

$ poet snakemake
<outputs packages as expected>

$ deactivate
<removed virtual environment as expected>

Verdict: Success

2. @claui's method documented in this PR

$ brew reinstall pipenv
<installs successfully>

$ cd "$(mktemp -d)"
<runs successfully>

$ pipenv install snakemake homebrew-pypi-poet
<installs successfully>

$ pipenv run poet snakemake
<outputs packages as expected>

$ pipenv --rm
<runs successfully>

Verdict: Success

3. My method documented in #9391 (review)

$ cd "$(mktemp -d)"
<runs successfully>

$ python3 -m venv venv
<runs successfully>

$ source venv/bin/activate
<runs successfully>

$ pip3 install snakemake homebrew-pypi-poet
<installs successfully>

$ poet snakemake
<outputs packages as expected>

$ deactivate
<runs successfully>

Verdict: Success

Conclusion

These all seem to be fine with me. However, the pipenv method did not work. The error I got is a known python@3.9 issue, though, that FX is currently working on.

@BrewTestBot
Copy link
Member

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@BrewTestBot BrewTestBot added stale No recent activity and removed stale No recent activity labels Dec 25, 2020
@claui
Copy link
Contributor Author

claui commented Dec 28, 2020

@Rylan12 Does the python@3.9 issue still persist?

@claui
Copy link
Contributor Author

claui commented Dec 28, 2020

@MikeMcQuaid This PR isn’t stale.
According to what @Rylan12 wrote, it’s blocked by, and waiting on, a Python 3.9 issue for which a fix is in progress.

@MikeMcQuaid
Copy link
Member

@claui The existing method works for @Rylan12, the documented method requires fixes before it will work and @Rylan12 suggested another method. I don't think it's worth progressing with this as a result.

There's been no activity for 25 days beyond it being marked as stale and no activity since then hence my closing.

@claui
Copy link
Contributor Author

claui commented Dec 28, 2020

There's been no activity for 25 days beyond it being marked as stale

@MikeMcQuaid What tag should I have used, other than do not merge, to indicate that this is blocked by an unrelated issue?

and no activity since then

I was away from my computer for the holidays.

The existing method works for @Rylan12,

and fails for me.

the documented method requires fixes before it will work

which @fxcoudert has been addressing in the (unrelated) Python 3.9 issue.

and @Rylan12 suggested another method

which fails for me.

I’d like to confirm that the method this PR proposes is the only one that works reliably.

@Rylan12
Copy link
Member

Rylan12 commented Dec 28, 2020

Since the last time I looked at this, the Python issue mentioned has been fixed. I went back and re-attempted @claui's proposed fix and it worked fine with the fixed Python 3.9.

I've updated my comment above to reflect this.

@claui
Copy link
Contributor Author

claui commented Dec 28, 2020

Thanks @Rylan12 for the update and for re-trying.

And apologies @MikeMcQuaid for my lack of responsiveness.

@claui
Copy link
Contributor Author

claui commented Dec 28, 2020

@MikeMcQuaid With the proposed method now confirmed to work for both Rylan and myself, please consider re-opening. Thank you.

@MikeMcQuaid MikeMcQuaid reopened this Dec 29, 2020
@MikeMcQuaid
Copy link
Member

@MikeMcQuaid What tag should I have used, other than do not merge, to indicate that this is blocked by an unrelated issue?

I'd have expected a comment from the PR author noting that.

I’d like to confirm that the method this PR proposes is the only one that works reliably.

I'm fine with this being merged as-is.

@claui
Copy link
Contributor Author

claui commented Dec 30, 2020

Pinging @dtrodrigues for a third opinion (I just saw #10039.)

@dtrodrigues
Copy link
Member

From the existing documentation, the first method of brew update-python-resources <formula> should remain the preferred way, since it will use pipgrip to resolve dependencies, which is what brew bump-formula-pr also uses. If we do need to provide a manual way to get resources, I think what @Rylan12 suggested would be my preferred method since it doesn't require installing another package like pipenv or virtualenvwrapper: #9391 (review). The error from @claui of ERROR: Can not perform a '--user' install. User site-packages are not visible in this virtualenv. implies that the user's global pip conf includes a config option to always do --user installs, which don't work within a venv. This can be checked via pip config list.

It's worth noting that the dependency resolution of pipgrip (PubGrub) differs from the dependency resolution of pip, which is what all manual methods here use. pip does not and will not use PubGrub: pypa/pip#8203 and recently majorly changed their dependency resolution algorithm: https://blog.python.org/2020/11/pip-20-3-release-new-resolver.html

@Rylan12
Copy link
Member

Rylan12 commented Dec 31, 2020

Is changing the command to pip --isolated install <packages> a viable solution? Not familiar enough with pip to make that call.

Also, is there a reason to use python3 -m pip over pip or pip3?

In terms of the dependency resolver, is this going to cause issues? As in, should update-python-resources use the same resolver as pip? If we're consistent, it may not be a huge issue. I doubt there are differences that are significant enough to cause problems. That being said, this is the first time I've heard about PubGrub and that stuff, so I'm probably not qualified to say for sure.

@dtrodrigues
Copy link
Member

Just --no-user should be sufficient as a pip argument.

Longer-term, the divergence between pipgrip and pip dependency resolution may be an issue, but I'm not aware of any current differences in their output.

@dtrodrigues
Copy link
Member

Within a venv, there's no difference between python3 -m pip and pip and pip3 given how venv modifies your path when you activate it.

@Rylan12
Copy link
Member

Rylan12 commented Dec 31, 2020

@claui can you try the method I suggested in #9391 (review) again, this time adding --no-user to the pip install command?

@claui
Copy link
Contributor Author

claui commented Jan 7, 2021

@Rylan12 Yay – that works! 🎉

Also:

The error from @claui of ERROR: Can not perform a '--user' install. User site-packages are not visible in this virtualenv. implies that the user's global pip conf includes a config option to always do --user installs, which don't work within a venv. This can be checked via pip config list.

@dtrodrigues You’re absolutely right. pip config -v list revealed that I had a ~/Library/'Application Support'/pip/pip.conf lying around, which said:

global.user=1

Trashing the pip.conf fixed the issue for me.
I can still reproduce the problem by running pip3 config set global.user true before the pip install part.

@dtrodrigues @Rylan12 Is it worth including --no-user in the solution? Or is the situation exotic enough that we shouldn’t mind?

@claui
Copy link
Contributor Author

claui commented Jan 7, 2021

I think what @Rylan12 suggested would be my preferred method since it doesn't require installing another package like pipenv or virtualenvwrapper

Now that it works for everyone, I absolutely agree.

@claui claui closed this Jan 7, 2021
@claui
Copy link
Contributor Author

claui commented Jan 7, 2021

@Rylan12 Do you want to open a PR with your solution (and get proper credit) or would you prefer me to do it?

@Rylan12
Copy link
Member

Rylan12 commented Jan 7, 2021

@claui Happy to open a new PR (although I wouldn't have been upset at all if you went ahead and made the changes in here)!

My gut is that it's a pretty specific problem so unless more users report issues, I'm not sure we need to include it. I have no problem including it, though, if we think it's worth it.

@claui claui deleted the pipenv-poet branch January 7, 2021 18:32
@claui claui mentioned this pull request Jan 7, 2021
8 tasks
@BrewTestBot BrewTestBot added the outdated PR was locked due to age label Feb 7, 2021
@Homebrew Homebrew locked as resolved and limited conversation to collaborators Feb 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Documentation changes outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants