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

Add url option to brew.tap #1022

Merged
merged 7 commits into from
Jan 12, 2024
Merged

Conversation

znd4
Copy link
Contributor

@znd4 znd4 commented Oct 26, 2023

The brew tap command defaults to a (somewhat weird) behavior of looking in a separate homebrew-{repo} repo under the same owner. For understandable reasons, some projects (like the included kpt example), just put the Formula metadata in the main project repo.

Currently, such projects can't be brew taped with pyinfra.

I also took a bit of liberty to refactor the brew tap command to use guard clauses, but I wouldn't mind undoing that.

I'm not sure where the coverage drop is coming from; trying to nail that down

@@ -0,0 +1,3 @@
[*.json]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't mind removing this, or filling it out more (e.g. with *.py or *.toml configuration)

Copy link
Member

Choose a reason for hiding this comment

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

Let's leave it as-is, editorconfig is neat!

taps.remove(src)
else:
host.noop("tap {0} does not exist".format(src))
cmd = "brew tap {0}".format(src)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

let me know if this guard clause refactoring isn't appreciated -- no hard feelings about reverting to just the url change

Copy link
Member

Choose a reason for hiding this comment

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

Much appreciated, good improvement 👍

@znd4 znd4 marked this pull request as ready for review October 26, 2023 23:43
@@ -159,12 +159,13 @@ def casks(


@operation
def tap(src, present=True):
def tap(src, present=True, url=None):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We might be able to make src optional if url is present?

Copy link
Member

Choose a reason for hiding this comment

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

Alternative: src could accept an URL? apt.key does this:

# If URL, wget the key to stdout and pipe into apt-key, because the "adv"
# apt-key passes to gpg which doesn't always support https!
if urlparse(src).scheme:
yield "(wget -O - {0} || curl -sSLf {0}) | apt-key add -".format(src)
else:
yield "apt-key add {0}".format(src)

I'm actually not 100% this is the best route (too magic?), would like your opinion!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

xD I have gotten a bit disillusioned with excess magic since spending time in Golang-land, but the bigger issue with that is that it wouldn't be able to support the full scope of brew tap [user/repo] [URL].

Based on this search, it seems like the URL argument is usually either

  1. brew tap user/projectname https://github.com/user/projectname (the behavior we'd support by parsing src as a URL and looking at the last two path components)
    or
  2. brew tap user/projectname https://github.com/user/homebrew-projectname (In this case, I'm pretty sure the url is redundant)

However, sometimes people add .git at the end of the URL. We could add a special case for that, but there's a less tractable issue:

A (small) percentage of documented uses of brew tap don't end with owner/repo at all, for example:

brew tap team23/b5 https://git.team23.de/build/homebrew-b5.git

Since our implementation would calculate the tap name as build/homebrew-b5 (or build/b5), it seems like a painful failure mode.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I suppose we could "do both" --

# valid
brew.tap(\"user/project\")
brew.tap(\"https://github.com/user/project\")
brew.tap(\"owner/project\", \"https://git.owner.com/foo/bar.git\")

# throw errors?
brew.tap(\"https://git.owner.com/foo\") # path is too short
brew.tap(\"https://git.owner.com/foo/bar.git\") 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I suppose we could "do both" --

# valid
brew.tap(\"user/project\")
brew.tap(\"https://github.com/user/project\")
brew.tap(\"owner/project\", \"https://git.owner.com/foo/bar.git\")

# throw errors?
brew.tap(\"https://git.owner.com/foo\") # path is too short
brew.tap(\"https://git.owner.com/foo/bar.git\") 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I suppose we could "do both":

valid

brew.tap(\"user/project\")
brew.tap(\"https://github.com/user/project\") # this feels really nice
brew.tap(\"owner/project\", url=\"https://git.owner.com/foo/bar.git\")

unsure

could be brew tap owner/project https://github.com/owner/project.git

brew.tap(\"https://github.com/owner/project.git\")
# or \"brew tap owner/project.git https://github.com/owner/project.git\"

brew.tap(\"https://git.owner.com/foo/bar\")

invalid

brew.tap(\"https://git.owner.com/foo\") # path is too short

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I suppose we could "do both":

valid

brew.tap(\"user/project\")
brew.tap(\"https://github.com/user/project\") # this feels really nice
brew.tap(\"owner/project\", url=\"https://git.owner.com/foo/bar.git\")

unsure

brew.tap(\"https://github.com/owner/project.git\")

could be brew tap owner/project https://github.com/owner/project.git

# or \"brew tap owner/project.git https://github.com/owner/project.git\"

brew.tap(\"https://git.owner.com/foo/bar\")

invalid

brew.tap(\"https://git.owner.com/foo\") # path is too short

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I suppose we could "do both":

valid

brew.tap(\"user/project\")
brew.tap(\"https://github.com/user/project\") # this feels really nice
brew.tap(\"owner/project\", url=\"https://git.owner.com/foo/bar.git\")

unsure

brew.tap(\"https://github.com/owner/project.git\")

could be brew tap owner/project https://github.com/owner/project.git
or "brew tap owner/project.git https://github.com/owner/project.git\"

brew.tap(\"https://git.owner.com/foo/bar\")

should we assume foo is the owner for non-github / bitbucket / ... URLs? It seems clunky to have an allowlist of known git hosts, but otherwise this is still a bit of a footgun

invalid

brew.tap(\"https://git.owner.com/foo\") # path is too short

Copy link
Member

Choose a reason for hiding this comment

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

I think github went wild with some edits there by the looks of it!

I totally agree with the magic thing (funny - also Go that has altered my perspective on such things), let's keep the explicit URL and avoid the magic/complexity.

Copy link
Member

Choose a reason for hiding this comment

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

SO I think the only change here is to make the src optional!

Copy link
Member

@Fizzadar Fizzadar left a comment

Choose a reason for hiding this comment

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

@znd4 firstly - apologies for taking way too long to review this, it has been a crazy few months and I have fallen way behind. I very much appreciate the PR and it looks great! Couple of comments to discuss but this looks good to go.

@@ -0,0 +1,3 @@
[*.json]
Copy link
Member

Choose a reason for hiding this comment

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

Let's leave it as-is, editorconfig is neat!

@@ -159,12 +159,13 @@ def casks(


@operation
def tap(src, present=True):
def tap(src, present=True, url=None):
Copy link
Member

Choose a reason for hiding this comment

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

Alternative: src could accept an URL? apt.key does this:

# If URL, wget the key to stdout and pipe into apt-key, because the "adv"
# apt-key passes to gpg which doesn't always support https!
if urlparse(src).scheme:
yield "(wget -O - {0} || curl -sSLf {0}) | apt-key add -".format(src)
else:
yield "apt-key add {0}".format(src)

I'm actually not 100% this is the best route (too magic?), would like your opinion!

taps.remove(src)
else:
host.noop("tap {0} does not exist".format(src))
cmd = "brew tap {0}".format(src)
Copy link
Member

Choose a reason for hiding this comment

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

Much appreciated, good improvement 👍

@znd4
Copy link
Contributor Author

znd4 commented Nov 29, 2023

apologies for taking way too long to review this

no worries! Fixing one issue on an ~8 star repo of mine took up most of a weekend, so I can only imagine how much is required to maintain a project this lively.

@znd4
Copy link
Contributor Author

znd4 commented Dec 19, 2023

sors, I was slammed at work recently.

Decided to remove the pre-commit config as soon as I put it in, because it should include changes to CONTRIBUTING.md, and potentially some CI changes, so it should be a standalone PR (assuming you even want to add it)

Copy link
Member

@Fizzadar Fizzadar left a comment

Choose a reason for hiding this comment

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

Awesome stuff, thank you for putting this together @znd4!

Yes please for a pre-commit PR if you have time 🙏

@Fizzadar Fizzadar merged commit a773e32 into pyinfra-dev:2.x Jan 12, 2024
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants