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

Refactor module_function to reduce rbi need #15249

Merged
merged 4 commits into from Apr 17, 2023

Conversation

dduugg
Copy link
Sponsor Member

@dduugg dduugg commented Apr 17, 2023

  • 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?

module_function is hard to get right, as it creates methods in multiple namespaces (a private instance and a public class method), and the resulting code needs to make sure that references resolve in both places. Aliases and visibility modifiers are also hard to get right. (It's also confusing for end users, as it creates uncertainty around which is the right way to make use of the module.)

A lot of this was cleaned up when enabling typechecking, but i've ported a few more in this PR. This was primarily motivated by the desire to reduce the need for custom .rbi files, which have been cut by 30% (70 → 49).

# TODO: bump version when new Xcode macOS SDK is released
# NOTE: We only track the major version of the SDK.
::Version.new("13")
end
private :latest_sdk_version
Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

This was useless, since it only affected the instance method, which was already private. For example: https://github.com/Homebrew/brew/blob/e98bfdd/Library/Homebrew/os/mac/xcode.rb#L69

@MikeMcQuaid
Copy link
Member

Thanks again @dduugg!

@@ -32,7 +32,7 @@ def initialize(regex, max_length, replacement)
# rewrite_shebang detected_python_shebang, bin/"script.py"
#
# @api public
sig { params(rewrite_info: RewriteInfo, paths: T::Array[T.any(String, Pathname)]).void }
Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

It looks like sig validation is another victim of module_function (I had to revert this due to the instance use in Formula, but kept the type signature fix here).

@MikeMcQuaid MikeMcQuaid merged commit 8548ea1 into Homebrew:master Apr 17, 2023
30 checks passed
Utils::Shebang::RewriteInfo.new(
%r{^#! ?/usr/bin/(?:env )?python(?:[23](?:\.\d{1,2})?)?( |$)},
28, # the length of "#! /usr/bin/env pythonx.yyy "
"#{python_path}\\1",
)
end

def detected_python_shebang(formula = self, use_python_from_path: false)
def self.detected_python_shebang(formula = self, use_python_from_path: false)
Copy link
Member

Choose a reason for hiding this comment

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

This is a mixin module as documented above and this breaks it.

See formulae which invoke include Language::Python::Shebang and call detected_python_shebang.

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

Reverted in #15259, PTAL

module_function

def detected_perl_shebang(formula = self)
def self.detected_perl_shebang(formula = self)
Copy link
Member

Choose a reason for hiding this comment

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

Ditto

@dduugg dduugg deleted the module-function-cleanup branch April 19, 2023 01:50
@dduugg dduugg mentioned this pull request Apr 19, 2023
7 tasks
@github-actions github-actions bot added the outdated PR was locked due to age label May 20, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 20, 2023
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.

None yet

3 participants