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

Modify install_prereqs to create a venv #22477

Merged

Conversation

mwoehlke-kitware
Copy link
Contributor

@mwoehlke-kitware mwoehlke-kitware commented Jan 16, 2025

Modify the install_prereqs script used for Drake tarball installations to create a Python virtual environment in the location where Drake has been extracted. On macOS, also use this to install Drake's Python dependencies using PDM. Update user documentation accordingly.

The changes for Ubuntu are mainly to preserve consistency. For macOS, this change means we are now using the pinned versions of our dependencies and are no longer keeping a duplicate copy of this list solely for installations.

Towards #22040.


This change is Reviewable

@mwoehlke-kitware
Copy link
Contributor Author

@drake-jenkins-bot mac-arm-sonoma-unprovisioned-clang-cmake-experimental-packaging please.

@mwoehlke-kitware
Copy link
Contributor Author

BTW, I'm not sure if this should get release notes or not. That Drake now expects to create its own venv might be a "gotcha" for existing users.

@jwnimmer-tri jwnimmer-tri added the release notes: feature This pull request contains a new feature label Jan 17, 2025
@mwoehlke-kitware
Copy link
Contributor Author

@drake-jenkins-bot mac-arm-sonoma-unprovisioned-clang-cmake-experimental-packaging please.

@mwoehlke-kitware
Copy link
Contributor Author

@drake-jenkins-bot mac-arm-sonoma-unprovisioned-clang-cmake-experimental-packaging please.

@mwoehlke-kitware
Copy link
Contributor Author

+@jwnimmer-tri for feature review, please

Copy link
Collaborator

@jwnimmer-tri jwnimmer-tri left a comment

Choose a reason for hiding this comment

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

LGTM on paper -- just one question in a new top-level thread below ...

Reviewed 2 of 7 files at r1, 3 of 3 files at r2, 2 of 2 files at r3, all commit messages.
Reviewable status: 3 unresolved discussions, LGTM missing from assignee jwnimmer-tri(platform), needs at least two assigned reviewers


a discussion (no related file):
Has this been tested against DEE CI? I didn't see any.

It's probably worth opening a DEE PR that changes this line to point to the experimental tgz published from this pull request, and make sure everything is still happy.


setup/mac/binary_distribution/install_prereqs.sh line 64 at r3 (raw file):

brew bundle --file="${BASH_SOURCE%/*}/Brewfile" --no-lock

if ! command -v pip3.12 &>/dev/null; then

BTW Is this still the best condition to check for? Does PDM call pip3.12 under the hood, or just do its own thing?


setup/BUILD.bazel line 10 at r3 (raw file):

exports_files([
    "mac/binary_distribution/Brewfile",
    "mac/binary_distribution/requirements.txt",

nit This line seems stale now?

Copy link
Collaborator

@jwnimmer-tri jwnimmer-tri left a comment

Choose a reason for hiding this comment

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

Reviewable status: 4 unresolved discussions, LGTM missing from assignee jwnimmer-tri(platform), needs at least two assigned reviewers


a discussion (no related file):
Note that #22040 task (2) is still unfinished in this PR. I find it slightly suspicious to mix a PDM lockfile with a Homebrew version of numpy. I would imagine that their versions are not always strictly compatible? Or maybe the homebrew numpy is dead code now, if the venv sys.patch excludes it?

Copy link
Collaborator

@jwnimmer-tri jwnimmer-tri left a comment

Choose a reason for hiding this comment

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

Reviewable status: 5 unresolved discussions, LGTM missing from assignee jwnimmer-tri(platform), needs at least two assigned reviewers


a discussion (no related file):
I would like to land #22503 ahead of this PR. I don't trust our testing here when the PDM dependencies are unpinned but still installed into the same venv as Drake's dependencies.

Copy link
Contributor Author

@mwoehlke-kitware mwoehlke-kitware left a comment

Choose a reason for hiding this comment

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

Reviewable status: 4 unresolved discussions, LGTM missing from assignee jwnimmer-tri(platform), needs at least two assigned reviewers


setup/BUILD.bazel line 10 at r3 (raw file):

Previously, jwnimmer-tri (Jeremy Nimmer) wrote…

nit This line seems stale now?

Probably. Done.


setup/mac/binary_distribution/install_prereqs.sh line 64 at r3 (raw file):

Previously, jwnimmer-tri (Jeremy Nimmer) wrote…

BTW Is this still the best condition to check for? Does PDM call pip3.12 under the hood, or just do its own thing?

This is the check for "did brew correctly install Python?". I suppose we could just check for python3.12 instead, but since we need python3.12 -m venv to give us pip3, checking that pip already exists doesn't seem unreasonable. (But I'll entertain arguments either way.)

Checking for pdm at this point isn't right, because we haven't installed it yet! And, while I don't know if PDM uses pip under the hood, we do use pip to install pdm itself.

TL;DR: We're still about to call pip, we've just changed from <brew>/pip3.12 to <venv>/pip3.

Copy link
Collaborator

@jwnimmer-tri jwnimmer-tri left a comment

Choose a reason for hiding this comment

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

Reviewed 3 of 3 files at r4, all commit messages.
Reviewable status: 3 unresolved discussions, LGTM missing from assignee jwnimmer-tri(platform), needs at least two assigned reviewers


setup/mac/binary_distribution/install_prereqs.sh line 64 at r3 (raw file):

... we do use pip to install pdm itself.

Aha, this is definitely a good reason. I hadn't connected those dots, but I probably should have. No changes necessary.

Copy link
Collaborator

@jwnimmer-tri jwnimmer-tri left a comment

Choose a reason for hiding this comment

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

Reviewable status: 3 unresolved discussions, LGTM missing from assignee jwnimmer-tri(platform), needs at least two assigned reviewers


a discussion (no related file):

Previously, jwnimmer-tri (Jeremy Nimmer) wrote…

Note that #22040 task (2) is still unfinished in this PR. I find it slightly suspicious to mix a PDM lockfile with a Homebrew version of numpy. I would imagine that their versions are not always strictly compatible? Or maybe the homebrew numpy is dead code now, if the venv sys.patch excludes it?

(Oops, I meant to say "if the venv sys.path excludes it".)

Copy link
Contributor Author

@mwoehlke-kitware mwoehlke-kitware left a comment

Choose a reason for hiding this comment

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

Reviewable status: 3 unresolved discussions, LGTM missing from assignee jwnimmer-tri(platform), needs at least two assigned reviewers


a discussion (no related file):

Previously, jwnimmer-tri (Jeremy Nimmer) wrote…

(Oops, I meant to say "if the venv sys.path excludes it".)

That's an interesting question. pdm.lock pins numpy and it looks like it's being installed by the venv in practice. Do we still need numpy from Brew? Maybe we should PR its removal first?

I believe we've been installing it via the venv since pip-tools; at least, I see it was already in the pip-tools lock files. I didn't realize we were also installing it via brew.


a discussion (no related file):

Previously, jwnimmer-tri (Jeremy Nimmer) wrote…

I would like to land #22503 ahead of this PR. I don't trust our testing here when the PDM dependencies are unpinned but still installed into the same venv as Drake's dependencies.

WFM.

Copy link
Collaborator

@jwnimmer-tri jwnimmer-tri left a comment

Choose a reason for hiding this comment

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

Reviewable status: 3 unresolved discussions, LGTM missing from assignee jwnimmer-tri(platform), needs at least two assigned reviewers


a discussion (no related file):
We definitely need a usable numpy, the only question is where it comes from.

Maybe we should PR its removal first?

We can't do it first, because then otherwise it would be missing for tgz users. (We can't install it system-wide under --break-system-packages.)

It seems to me like it would be safest to remove it in this PR, instead of a future one?

Copy link
Collaborator

@jwnimmer-tri jwnimmer-tri left a comment

Choose a reason for hiding this comment

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

Reviewable status: 2 unresolved discussions, LGTM missing from assignee jwnimmer-tri(platform), needs at least two assigned reviewers


a discussion (no related file):

Previously, mwoehlke-kitware (Matthew Woehlke) wrote…

WFM.

Done.

Copy link
Contributor Author

@mwoehlke-kitware mwoehlke-kitware left a comment

Choose a reason for hiding this comment

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

Reviewable status: 2 unresolved discussions, LGTM missing from assignee jwnimmer-tri(platform), needs at least two assigned reviewers


a discussion (no related file):

Previously, jwnimmer-tri (Jeremy Nimmer) wrote…

We definitely need a usable numpy, the only question is where it comes from.

Maybe we should PR its removal first?

We can't do it first, because then otherwise it would be missing for tgz users. (We can't install it system-wide under --break-system-packages.)

It seems to me like it would be safest to remove it in this PR, instead of a future one?

Makes sense. Done.

@mwoehlke-kitware
Copy link
Contributor Author

@drake-jenkins-bot mac-arm-sonoma-unprovisioned-clang-cmake-experimental-packaging please.

Copy link
Collaborator

@jwnimmer-tri jwnimmer-tri left a comment

Choose a reason for hiding this comment

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

Reviewed 3 of 3 files at r5, all commit messages.
Reviewable status: 1 unresolved discussion, LGTM missing from assignee jwnimmer-tri(platform), needs at least two assigned reviewers

@mwoehlke-kitware
Copy link
Contributor Author

@drake-jenkins-bot mac-arm-sonoma-unprovisioned-clang-cmake-experimental-packaging please.

Copy link
Collaborator

@jwnimmer-tri jwnimmer-tri left a comment

Choose a reason for hiding this comment

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

Reviewed 3 of 3 files at r6, all commit messages.
Reviewable status: 1 unresolved discussion, LGTM missing from assignee jwnimmer-tri(platform), needs at least two assigned reviewers

@mwoehlke-kitware
Copy link
Contributor Author

@drake-jenkins-bot mac-arm-sonoma-unprovisioned-clang-cmake-experimental-packaging please.

1 similar comment
@BetsyMcPhail
Copy link
Contributor

@drake-jenkins-bot mac-arm-sonoma-unprovisioned-clang-cmake-experimental-packaging please.

mwoehlke-kitware added a commit to mwoehlke-kitware/drake-external-examples that referenced this pull request Jan 27, 2025
Copy link
Contributor Author

@mwoehlke-kitware mwoehlke-kitware left a comment

Choose a reason for hiding this comment

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

Reviewable status: 1 unresolved discussion, LGTM missing from assignee jwnimmer-tri(platform), needs at least two assigned reviewers


a discussion (no related file):

Previously, jwnimmer-tri (Jeremy Nimmer) wrote…

Has this been tested against DEE CI? I didn't see any.

It's probably worth opening a DEE PR that changes this line to point to the experimental tgz published from this pull request, and make sure everything is still happy.

See RobotLocomotion/drake-external-examples#365.

Copy link
Collaborator

@jwnimmer-tri jwnimmer-tri left a comment

Choose a reason for hiding this comment

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

:lgtm: feature.

+@sammy-tri for platform review per schedule, please.

Reviewable status: LGTM missing from assignee sammy-tri(platform)

@jwnimmer-tri
Copy link
Collaborator

FYI @mwoehlke-kitware needs a rebase (re-lock).

Copy link
Contributor

@sammy-tri sammy-tri left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 7 files at r1, 1 of 3 files at r2, 1 of 2 files at r3, 1 of 3 files at r4, 2 of 3 files at r5, 3 of 3 files at r6, all commit messages.
Reviewable status: 1 unresolved discussion, LGTM missing from assignee sammy-tri(platform)


doc/_pages/from_binary.md line 83 at r6 (raw file):

```bash
sudo env/share/drake/setup/install_prereqs

This didn't have a sudo before. What changed?

Modify the macOS install_prereqs script used for Drake tarball
installations to create a Python virtual environment in the location
where Drake has been extracted. Also use this to install Drake's Python
dependencies using PDM. Update user documentation accordingly.

This means we are now using the pinned versions of our dependencies and
are no longer keeping a duplicate copy of this list solely for
installations.

This also means that we are installing a pinned numpy in the venv for
installations. This was already the case for source builds, but means we
now no longer have any reason to install numpy from Homebrew, so remove
it from there.
Copy link
Contributor Author

@mwoehlke-kitware mwoehlke-kitware left a comment

Choose a reason for hiding this comment

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

Done. Note, there are no effective changes to the pyproject.toml, so the only change to pdm.lock is updating the input hash. (What changed, besides a comment, is that numpy is explicitly listed as a dependency. But it was already an indirect dependency, so nothing in the lock file changes.)

Reviewable status: 1 unresolved discussion, LGTM missing from assignee sammy-tri(platform)


doc/_pages/from_binary.md line 83 at r6 (raw file):
What changed is that this line:

(On Ubuntu, the script might ask to be run under sudo.)

...was removed. In practice, "might" is "will"; n.b. ubuntu/binary_distribution/install_prereqs.sh#L28-L31. Since Ubuntu and macOS now have separate instructions, there is no need to omit the sudo with a note that it "might" be necessary.

That said, there is active work happening with the install scripts and whether they want sudo or not, but AFAICT, as of writing sudo is needed.

@mwoehlke-kitware
Copy link
Contributor Author

doc/_pages/from_binary.md line 83 at r6 (raw file):

Previously, mwoehlke-kitware (Matthew Woehlke) wrote…

What changed is that this line:

(On Ubuntu, the script might ask to be run under sudo.)

...was removed. In practice, "might" is "will"; n.b. ubuntu/binary_distribution/install_prereqs.sh#L28-L31. Since Ubuntu and macOS now have separate instructions, there is no need to omit the sudo with a note that it "might" be necessary.

That said, there is active work happening with the install scripts and whether they want sudo or not, but AFAICT, as of writing sudo is needed.

Clarification (pedantic): sudo is required unless you are already root (e.g. in Docker). But since it should be harmless in that case¹, it seems simpler to just specify it.

(¹ There are cases where we disallow running via sudo when already root, but those seem to apply only to building from source, not to binary distributions.)

Copy link
Collaborator

@jwnimmer-tri jwnimmer-tri left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 2 files at r7, all commit messages.
Reviewable status: 1 unresolved discussion, LGTM missing from assignee sammy-tri(platform)

Copy link
Contributor

@sammy-tri sammy-tri left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: :shipit: complete! all discussions resolved, LGTM from assignees sammy-tri(platform),jwnimmer-tri(platform)


doc/_pages/from_binary.md line 83 at r6 (raw file):

Previously, mwoehlke-kitware (Matthew Woehlke) wrote…

Clarification (pedantic): sudo is required unless you are already root (e.g. in Docker). But since it should be harmless in that case¹, it seems simpler to just specify it.

(¹ There are cases where we disallow running via sudo when already root, but those seem to apply only to building from source, not to binary distributions.)

Ok, thanks for the explanation!

Copy link
Contributor

@sammy-tri sammy-tri left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 2 files at r7, all commit messages.
Reviewable status: :shipit: complete! all discussions resolved, LGTM from assignees sammy-tri(platform),jwnimmer-tri(platform)

@mwoehlke-kitware
Copy link
Contributor Author

@drake-jenkins-bot linux-jammy-gcc-bazel-experimental-debug please

@jwnimmer-tri jwnimmer-tri merged commit 55441db into RobotLocomotion:master Jan 27, 2025
8 of 10 checks passed
@mwoehlke-kitware mwoehlke-kitware deleted the macos-install-uses-venv branch January 27, 2025 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: high release notes: feature This pull request contains a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants