Skip to content

Commit

Permalink
improved brew formula generation
Browse files Browse the repository at this point in the history
  • Loading branch information
gautamkrishnar committed Aug 4, 2020
1 parent 942cc53 commit fb3c1d5
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ venv
.eggs
socli/data.json
socli.rb
wait-till-publish.py
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ jobs:
distributions: sdist bdist_wheel
- stage: Deploy to Brew Tap
if: tag IS present
install: skip
python: 3.7
install:
- pip install socli # installs the latest version published
script: bash publish-brew-formula.sh
script: bash publish-brew-formula.sh # installs the latest published version and generates formula
49 changes: 48 additions & 1 deletion publish-brew-formula.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,52 @@
# Generate formula
pip install homebrew-pypi-poet==0.10.0
pip install homebrew-pypi-poet==0.10.0 requests==2.24.0

# Code to wait till the latest package is available in pypi
cat << EOF > wait-till-publish.py
import requests
import json
import os
import time
try:
from packaging.version import parse
except ImportError:
from pip._vendor.packaging.version import parse
URL_PATTERN = 'https://pypi.python.org/pypi/{package}/json'
def get_version(package, url_pattern=URL_PATTERN):
"""Return version of package on pypi.python.org using json."""
req = requests.get(url_pattern.format(package=package))
version = parse('0')
if req.status_code == requests.codes.ok:
j = json.loads(req.text.encode('utf-8'))
releases = j.get('releases', [])
for release in releases:
ver = parse(release)
if not ver.is_prerelease:
version = max(version, ver)
return version
if __name__ == '__main__':
tag = os.getenv('TRAVIS_TAG')
flag = True
while flag:
version = get_version('socli')
if version.base_version == tag:
print('Got latest version from pypi, version:' + version.base_version)
flag = False
else:
print('Cant get version ' + tag + ' from pypi, got: ' + version.base_version + ', Retrying in 5 secs...')
time.sleep(5)
EOF
python wait-till-publish.py

# When latest version of socli is available in pypi do install
pip install socli
# Generate formula
poet -f socli > socli.rb
patch socli.rb formula-changes.patch
echo "Generated formula:"
Expand Down

0 comments on commit fb3c1d5

Please sign in to comment.