Skip to content

Commit 4feca9b

Browse files
authored
Merge pull request #56 from akopdev/update-python-resources
Add update_python_resources parameter to build python resources
2 parents ae86772 + 2d07e93 commit 4feca9b

16 files changed

Lines changed: 286 additions & 45 deletions

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# CHANGELOG
22

3+
## Next Release
4+
5+
- Changes Docker image from `python3.13` to `brew` allowing us to use all brew tools during builds
6+
- Adds `update_python_resources` so Python formula can update their required resources
7+
- Bumps `TIMEOUT` from 30 to 60 seconds for larger projects
8+
39
## v2.0.3 (2025-04-26)
410

511
- Sends proper headers for HTTP requests to GitHub (#54)

Dockerfile

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
FROM python:3.13-alpine
1+
FROM homebrew/brew
22

3-
RUN apk add --no-cache \
4-
# Install git to push new Homebrew formula
5-
git \
6-
# Install perl-utils for `shasum` tool to get tar archive checksums
7-
perl-utils
3+
WORKDIR /home/linuxbrew/homebrew-releaser
84

9-
COPY . .
5+
COPY --chown=linuxbrew:linuxbrew homebrew_releaser homebrew_releaser
6+
COPY --chown=linuxbrew:linuxbrew setup.py setup.py
107

11-
RUN pip install -e .
8+
RUN brew install python@3.13 \
9+
&& python3 -m venv venv \
10+
&& venv/bin/pip3 install .
1211

13-
ENTRYPOINT [ "python", "/homebrew_releaser/app.py" ]
12+
ENTRYPOINT [ "venv/bin/python3", "homebrew_releaser/app.py" ]

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ jobs:
8181
8282
# Allows you to set a custom download strategy.
8383
# NOTE: You'll need to implement the strategy and add it to your tap repository.
84-
# Example: https://docs.brew.sh/Formula-Cookbook#specifying-the-download-strategy-explicitly
84+
# Docs: https://docs.brew.sh/Formula-Cookbook#specifying-the-download-strategy-explicitly
8585
# Optional - string
8686
download_strategy: CurlDownloadStrategy
8787

@@ -93,6 +93,11 @@ jobs:
9393
# Optional - string
9494
formula_includes: 'include Language::Python::Virtualenv'
9595

96+
# Run 'brew update-python-resources' on the formula to add Python resources.
97+
# Docs: https://docs.brew.sh/Python-for-Formula-Authors#python-declarations-for-applications
98+
# Default is shown - boolean
99+
update_python_resources: false
100+
96101
# Override the automatically detected version of a formula with an explicit value.
97102
# NOTE: This option should only be used if Homebrew cannot automatically detect the version when generating
98103
# the Homebrew formula. Including this when not necessary could lead to uninstallable formula that may

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ inputs:
4343
formula_includes:
4444
description: "Allows you to add custom includes inside the formula class, before dependencies and install blocks."
4545
required: false
46+
update_python_resources:
47+
description: "Run 'brew update-python-resources' on the formula to add Python resources."
48+
required: false
4649
version:
4750
description: "Override the automatically detected version of a formula with an explicit value."
4851
required: false
@@ -83,6 +86,7 @@ runs:
8386
- ${{ inputs.download_strategy }}
8487
- ${{ inputs.custom_require }}
8588
- ${{ inputs.formula_includes }}
89+
- ${{ inputs.update_python_resources }}
8690
- ${{ inputs.version }}
8791
- ${{ inputs.target_darwin_amd64 }}
8892
- ${{ inputs.target_darwin_arm64 }}

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ services:
2020
- INPUT_DOWNLOAD_STRATEGY=
2121
- INPUT_CUSTOM_REQUIRE=
2222
- INPUT_FORMULA_INCLUDES=
23+
- INPUT_UPDATE_PYTHON_RESOURCES=false
2324
- INPUT_TARGET_DARWIN_AMD64=
2425
- INPUT_TARGET_DARWIN_ARM64=
2526
- INPUT_TARGET_LINUX_AMD64=

homebrew_releaser/app.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
TARGET_DARWIN_ARM64,
2222
TARGET_LINUX_AMD64,
2323
TARGET_LINUX_ARM64,
24+
UPDATE_PYTHON_RESOURCES,
2425
VERSION,
2526
)
2627
from homebrew_releaser.formula import Formula
@@ -159,10 +160,24 @@ def run_github_action():
159160
DOWNLOAD_STRATEGY,
160161
CUSTOM_REQUIRE,
161162
FORMULA_INCLUDES,
163+
UPDATE_PYTHON_RESOURCES,
162164
version_no_v if VERSION else None,
163165
)
164166

165-
Utils.write_file(os.path.join(HOMEBREW_TAP, FORMULA_FOLDER, f'{repository["name"]}.rb'), template, 'w')
167+
formula_filename = f'{repository["name"]}.rb'
168+
formula_dir = os.path.join(HOMEBREW_TAP, FORMULA_FOLDER)
169+
formula_filepath = os.path.join(formula_dir, formula_filename)
170+
Utils.write_file(formula_filepath, template, 'w')
171+
172+
if UPDATE_PYTHON_RESOURCES:
173+
logger.info('Attempting to update Python resources in the formula...')
174+
Formula.update_python_resources(formula_dir, formula_filename)
175+
if DEBUG:
176+
with open(formula_filepath, 'r') as formula_file:
177+
formula_content = formula_file.read()
178+
logger.debug(formula_content)
179+
else:
180+
logger.debug('Skipping update to Python resources.')
166181

167182
if UPDATE_README_TABLE:
168183
logger.info('Attempting to update the README\'s project table...')

homebrew_releaser/constants.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,16 @@
1111
DOWNLOAD_STRATEGY = os.getenv('INPUT_DOWNLOAD_STRATEGY')
1212
CUSTOM_REQUIRE = os.getenv('INPUT_CUSTOM_REQUIRE')
1313
FORMULA_INCLUDES = os.getenv('INPUT_FORMULA_INCLUDES')
14+
UPDATE_PYTHON_RESOURCES = (
15+
os.getenv("INPUT_UPDATE_PYTHON_RESOURCES", False)
16+
if os.getenv("INPUT_UPDATE_PYTHON_RESOURCES") != "false"
17+
else False
18+
)
1419
VERSION = os.getenv('INPUT_VERSION')
1520

1621
# App Constants
1722
LOGGER_NAME = 'homebrew-releaser'
18-
TIMEOUT = 30
23+
TIMEOUT = 60
1924
GITHUB_HEADERS = {
2025
'Accept': 'application/vnd.github.v3+json',
2126
'Agent': 'Homebrew Releaser',

homebrew_releaser/formula.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import re
2+
import shutil
3+
import subprocess # nosec B404
24
import textwrap
35
from typing import (
46
Any,
@@ -16,6 +18,7 @@
1618
TARGET_DARWIN_ARM64,
1719
TARGET_LINUX_AMD64,
1820
TARGET_LINUX_ARM64,
21+
TIMEOUT,
1922
)
2023

2124

@@ -33,6 +36,7 @@ def generate_formula_data(
3336
download_strategy: Optional[str] = None,
3437
custom_require: Optional[str] = None,
3538
formula_includes: Optional[str] = None,
39+
update_python_resources: bool = False,
3640
version: Optional[str] = None,
3741
) -> str:
3842
"""Generates the formula data for Homebrew.
@@ -245,7 +249,9 @@ def match_indent_of(tag: str, text: str) -> str:
245249
)
246250

247251
logger.info('Homebrew formula generated successfully!')
248-
logger.debug(rendered_template)
252+
# If we are updating python resources, we'll log this later once resources are updated
253+
if not update_python_resources:
254+
logger.debug(rendered_template)
249255

250256
return rendered_template
251257

@@ -265,3 +271,27 @@ def _generate_class_name(repo_name: str) -> str:
265271
repo_name.title(),
266272
),
267273
)
274+
275+
@staticmethod
276+
def update_python_resources(formula_dir: str, formula_filename: str) -> None:
277+
"""Runs brew update-python-resources on the formula to add Python resources."""
278+
logger = woodchips.get(LOGGER_NAME)
279+
280+
brew_path = shutil.which('brew')
281+
if not brew_path:
282+
raise SystemExit("brew not found in PATH")
283+
284+
try:
285+
logger.info(f'Running brew update-python-resources for {formula_filename}...')
286+
subprocess.check_output(
287+
f'cd {formula_dir} && {brew_path} update-python-resources {formula_filename}',
288+
stderr=subprocess.STDOUT,
289+
text=True,
290+
timeout=TIMEOUT,
291+
shell=True, # nosec
292+
)
293+
logger.info(f'Successfully updated Python resources for {formula_filename}')
294+
except subprocess.TimeoutExpired as e:
295+
raise SystemExit from e
296+
except subprocess.CalledProcessError as e:
297+
raise SystemExit(f'An error occurred while updating Python resources: {e}') from e

justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ black-check:
3131

3232
# Test the project and generate an HTML coverage report
3333
coverage:
34-
{{VIRTUAL_BIN}}/pytest --cov={{PROJECT_NAME}} --cov-branch --cov-report=html --cov-report=lcov --cov-report=term-missing --cov-fail-under=95
34+
{{VIRTUAL_BIN}}/pytest --cov={{PROJECT_NAME}} --cov-branch --cov-report=html --cov-report=lcov --cov-report=term-missing --cov-fail-under=94
3535

3636
# Remove the virtual environment and clear out .pyc files
3737
clean:

setup.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import setuptools
44

5-
with open('README.md', 'r') as readme_file:
6-
long_description = readme_file.read()
75

86
# Inspiration: https://stackoverflow.com/a/7071358/6064135
97
with open('homebrew_releaser/_version.py', 'r') as version_file:
@@ -34,8 +32,6 @@
3432
name='homebrew-releaser',
3533
version=version,
3634
description='Release scripts, binaries, and executables directly to Homebrew via GitHub Actions.',
37-
long_description=long_description,
38-
long_description_content_type="text/markdown",
3935
url='http://github.com/Justintime50/homebrew-releaser',
4036
author='Justintime50',
4137
license='MIT',

0 commit comments

Comments
 (0)