-
-
Notifications
You must be signed in to change notification settings - Fork 389
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
Conversation
@@ -0,0 +1,3 @@ | |||
[*.json] |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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!
pyinfra/operations/brew.py
Outdated
taps.remove(src) | ||
else: | ||
host.noop("tap {0} does not exist".format(src)) | ||
cmd = "brew tap {0}".format(src) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much appreciated, good improvement 👍
pyinfra/operations/brew.py
Outdated
@@ -159,12 +159,13 @@ def casks( | |||
|
|||
|
|||
@operation | |||
def tap(src, present=True): | |||
def tap(src, present=True, url=None): |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:
pyinfra/pyinfra/operations/apt.py
Lines 75 to 80 in a280e17
# 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!
There was a problem hiding this comment.
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
brew tap user/projectname https://github.com/user/projectname
(the behavior we'd support by parsingsrc
as a URL and looking at the last two path components)
orbrew 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.
There was a problem hiding this comment.
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\")
There was a problem hiding this comment.
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\")
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
There was a problem hiding this 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] |
There was a problem hiding this comment.
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!
pyinfra/operations/brew.py
Outdated
@@ -159,12 +159,13 @@ def casks( | |||
|
|||
|
|||
@operation | |||
def tap(src, present=True): | |||
def tap(src, present=True, url=None): |
There was a problem hiding this comment.
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:
pyinfra/pyinfra/operations/apt.py
Lines 75 to 80 in a280e17
# 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!
pyinfra/operations/brew.py
Outdated
taps.remove(src) | ||
else: | ||
host.noop("tap {0} does not exist".format(src)) | ||
cmd = "brew tap {0}".format(src) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much appreciated, good improvement 👍
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. |
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 |
There was a problem hiding this 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 🙏
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 theFormula
metadata in the main project repo.Currently, such projects can't be
brew tap
ed 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