Skip to content

language/python: add types #16799

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

Merged
merged 1 commit into from
Mar 4, 2024

Conversation

cho-m
Copy link
Member

@cho-m cho-m commented Mar 3, 2024

Also add Virtualenv getters to get Pathnames to the virtualenv's root and site_packages.

  • 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 typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

Also add `Virtualenv` getters to get `Pathname`s to
the virtualenv's `root` and `site_packages`.

Signed-off-by: Michael Cho <michael@michaelcho.dev>
@cho-m cho-m force-pushed the language-python-add-types branch from f0f430a to 383d774 Compare March 3, 2024 19:44
Copy link
Contributor

@apainintheneck apainintheneck left a comment

Choose a reason for hiding this comment

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

This looks good to me. I tried installing a Python package locally and it seems happy.

Comment on lines +261 to +264
sig { returns(Pathname) }
def root
@venv_root
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Where is this getting used?

Copy link
Member Author

Choose a reason for hiding this comment

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

I originally used it in this file before adding site_packages.

I was thinking it could be used in homebrew-core rather than hardcoding path again later on, e.g. uhdm: https://github.com/Homebrew/homebrew-core/blob/master/Formula/u/uhdm.rb#L49

-      "-DPython3_EXECUTABLE=#{buildpath}/venv/bin/python", *std_cmake_args
+      "-DPython3_EXECUTABLE=#{venv.root}/bin/python", *std_cmake_args

Though I can remove it if preferred as most cleanup is handled by using site_packages, e.g. qt

-    venv_root = buildpath/"venv"
-    venv = virtualenv_create(venv_root, python)
+    venv = virtualenv_create(buildpath/"venv", python)
     venv.pip_install resources
-    ENV.prepend_path "PYTHONPATH", venv_root/Language::Python.site_packages(python)
+    ENV.prepend_path "PYTHONPATH", venv.site_packages

Copy link
Contributor

Choose a reason for hiding this comment

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

No, it makes sense in that case. I was only thinking about it in the context of this file but if it can simplify the code in core then I'm all for it.

Comment on lines -291 to +332
if t.respond_to? :stage
if t.is_a?(Resource)
t.stage { do_install(Pathname.pwd, build_isolation: build_isolation) }
else
t = t.lines.map(&:strip) if t.respond_to?(:lines) && t.include?("\n")
t = t.lines.map(&:strip) if t.is_a?(String) && t.include?("\n")
Copy link
Contributor

Choose a reason for hiding this comment

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

This checks out.

brew(main):004:0> [String, Pathname, Resource].select { _1.instance_methods.include? :lines }
=> [String]
brew(main):005:0> [String, Pathname, Resource].select { _1.instance_methods.include? :stage }
=> [Resource]

@MikeMcQuaid MikeMcQuaid merged commit d7d4c82 into Homebrew:master Mar 4, 2024
@MikeMcQuaid
Copy link
Member

Thanks again*many @cho-m!

@cho-m cho-m deleted the language-python-add-types branch March 4, 2024 12:43
@github-actions github-actions bot added the outdated PR was locked due to age label Apr 3, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants