Skip to content

Add update_python_resources parameter to build python resources#56

Merged
Justintime50 merged 9 commits intoJustintime50:mainfrom
akopdev:update-python-resources
Jun 10, 2025
Merged

Add update_python_resources parameter to build python resources#56
Justintime50 merged 9 commits intoJustintime50:mainfrom
akopdev:update-python-resources

Conversation

@akopdev
Copy link
Copy Markdown
Contributor

@akopdev akopdev commented May 22, 2025

Hi @Justintime50,

Thanks for the great tool! I was recently using it to release my Python package and encountered an issue related to missing Python dependencies. According to Homebrew guidelines, all dependencies should be defined in the resource section and we shouldn't rely on pip to install them at runtime.

That's how I came across Homebrew's command for generating the resource blocks automatically. I decided to put together this small PR and would love to get your thoughts on it.

@akopdev akopdev force-pushed the update-python-resources branch 3 times, most recently from 464424e to c58f684 Compare May 22, 2025 20:56
@Justintime50
Copy link
Copy Markdown
Owner

Awesome, thanks for the PR!

I have yet to release my own Python packages via Homebrew but this is probably a great reason to get me to do it! After reading the docs, I'm still a bit unclear, does this just automatically populate the depends_on block for us? I would expect a formula test here that asserts the output looks like what we want (there are various examples you can copy/paste/tweak.

Also, I'm a bit worried about this section from the docs, thoughts on how to ensure we can handle this edge case?

You can use brew update-python-resources to help you write resource stanzas. To use it, simply run brew update-python-resources <formula>. Sometimes, brew update-python-resources won’t be able to automatically update the resources. If this happens, try running brew update-python-resources --print-only <formula> to print the resource stanzas instead of applying the changes directly to the file. You can then copy and paste resources as needed.

I'll approve the workflow to see if your lint/tests pass, but I think we'll want to address the above and some clarity on my question would be great. Thanks!

@akopdev akopdev force-pushed the update-python-resources branch from c58f684 to e8fa5f5 Compare May 23, 2025 10:33
@akopdev
Copy link
Copy Markdown
Contributor Author

akopdev commented May 23, 2025

@Justintime50 I just pushed some lint and test fixes to this branch. Could you please re-approve the GitHub action?

As for brew update-python-resources, here's what it actually does (at least my understanding):

  • It pulls dependencies using pip.
  • It verifies the hash sum and the path to the file on PyPI.
  • It injects the appropriate resource entries into the Formula.

What I'm currently doing manually is:

  1. I release my package.
  2. I run homebrew-releaser, which regenerates the formula and pushes the new version to homebrew repository.
  3. I manually pull the updated formula, run brew update-python-resources Formula/*.rb on my machine, and then commit the result back. No additional interventions to formula code.

Here’s an example of what a properly structured formula should look like for a Python package. Pay attention to the resource section, as depends_on related to other brew formulas.

class Foo < Formula
  include Language::Python::Virtualenv

  desc "Description"
  homepage "https://example.com"
  url "..."

  resource "six" do
    url "https://files.pythonhosted.org/packages/71/39/171f1c67cd00715f190ba0b100d606d440a28c93c7714febeca8b79af85e/six-1.16.0.tar.gz"
    sha256 "1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"
  end

  resource "parsedatetime" do
    url "https://files.pythonhosted.org/packages/a8/20/cb587f6672dbe585d101f590c3871d16e7aec5a576a1694997a3777312ac/parsedatetime-2.6.tar.gz"
    sha256 "4cb368fbb18a0b7231f4d76119165451c8d2e35951455dfee97c62a87b04d455"
  end

  def install
    virtualenv_install_with_resources
  end
end

Copy link
Copy Markdown
Owner

@Justintime50 Justintime50 left a comment

Choose a reason for hiding this comment

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

Thanks for the response! I have a few thoughts now that I've been able to trace through it all.

I would also recommend not squashing and force pushing for open source - it hides the intermediary commits which can be super helpful during code review. Code owners can determine when merging if they'd like to squash or keep all the commits on master. Thanks!

Comment thread homebrew_releaser/_version.py Outdated
Comment thread action.yml Outdated
Comment thread README.md Outdated
Comment thread homebrew_releaser/formula.py Outdated
Comment thread homebrew_releaser/formula.py Outdated
Comment thread homebrew_releaser/formula.py Outdated
Comment thread test/unit/test_app.py
@akopdev akopdev force-pushed the update-python-resources branch from 2eddb4c to 1e8e38b Compare June 1, 2025 21:55
@Justintime50
Copy link
Copy Markdown
Owner

Ok, this PR is ready to go with the exception of getting brew into the docker image. We use an alpine image so it may provide challenging. I'll work on that since it may alter the base setup of this action.

@Justintime50
Copy link
Copy Markdown
Owner

@akopdev wanna take one last look at this PR now that I added that test and corrected the Docker setup? I ran end-to-end tests with Docker and it builds correctly as we need.

If you're good with these changes or I don't hear from ya in a day or so, I'll ship them and make a new release.

Thanks again for this PR! I'm excited to give it a whirl and release my own Python packages with it.

@akopdev
Copy link
Copy Markdown
Contributor Author

akopdev commented Jun 10, 2025

Thank you @Justintime50, I'm good to go.

@Justintime50 Justintime50 merged commit 4feca9b into Justintime50:main Jun 10, 2025
5 checks passed
@Justintime50
Copy link
Copy Markdown
Owner

Hey @akopdev, I dropped some details on #60 about additional findings after releasing. Apparently that build on Docker was super broken (worked great locally, once in GitHub Actions it didn't work) but I believe I was able to fix it; however, this feature doesn't seem to work for private repos. If you'd like, I wouldn't turn down some extra eyes on seeing if we can't get it working for both public and private repos. The extra details are on that issue. Thanks again for this PR!

@akopdev
Copy link
Copy Markdown
Contributor Author

akopdev commented Jun 14, 2025

@Justintime50 Thank you!

I have a few repos for experimentation and testing. I'll check as well.

Honestly, I didn’t like the solution from the beginning and thought it might be a good quick fix while working on the Python implementation of the feature for direct embedding.

If it turns out to be too painful, we can roll it back, and I’ll work on generating the resources in Python instead. What do you think?

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