Skip to content

Commit

Permalink
pybatfish: attempt to add source release (#117)
Browse files Browse the repository at this point in the history
Following batfish/pybatfish#864

- Fixup wheel name
- Fixup querying for releases to page

commit-id:97ab2f16
  • Loading branch information
dhalperi authored Dec 6, 2022
1 parent 7522b77 commit a77786a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 21 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/reusable-precommit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ jobs:
- name: Build wheel
run: |
cd pybatfish
pip install wheel 'setuptools==45.2.0'
python setup.py bdist_wheel
pip install --upgrade setuptools wheel build
python -m build
- name: Tar tests and notebooks
run: |
tar -czf pybatfish-tests.tgz -C pybatfish tests
Expand All @@ -167,7 +167,7 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: pybf_whl
path: pybatfish/dist/pybatfish*.whl
path: pybatfish/dist/*
- name: Upload tests
uses: actions/upload-artifact@v3
with:
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/reusable-upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,7 @@ jobs:
uses: actions/download-artifact@v3
with:
name: pybf_whl
- name: Prep whl
run: |
mkdir dist
mv pybatfish*.whl dist/
path: dist
- name: Publish to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
Expand Down
33 changes: 21 additions & 12 deletions get_docker_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,28 @@ def get_relevant_releases(image: str, days: int, minimum: int, pattern: Optional
Tries to return at least `minimum` releases, including all releases younger than the specified number of `days` old. Only considers tags containing the specified pattern."""
name_filter = f"&name={pattern}" if pattern else ""
releases = requests.get(f'https://hub.docker.com/v2/repositories/{image}/tags/?page_size=100{name_filter}').json()['results']
# Dict of release version to release datetime
dates = {
r['name']: datetime.strptime(r['last_updated'], "%Y-%m-%dT%H:%M:%S.%fZ") for r in releases
if re.match('\d{4}\.\d{2}\.\d{2}\.\d+', r['name'])
}
versions = sorted(dates.keys(), key=lambda r: dates.get(r), reverse=True)
url = f'https://hub.docker.com/v2/repositories/{image}/tags/?page_size=100{name_filter}'
res = list()
threshold = datetime.now() - timedelta(days=days)
for v in versions:
recent = dates.get(v) > threshold
if recent or len(res) < minimum:
res.append(v)
while True:
resp_json = requests.get(url).json()
releases = resp_json['results']
# Dict of release version to release datetime
dates = {
r['name']: datetime.strptime(r['last_updated'], "%Y-%m-%dT%H:%M:%S.%fZ") for r in releases
if re.match('\d{4}\.\d{2}\.\d{2}\.\d+', r['name'])
}
versions = sorted(dates.keys(), key=lambda r: dates.get(r), reverse=True)
threshold = datetime.now() - timedelta(days=days)
for v in versions:
recent = dates.get(v) > threshold
if recent or len(res) < minimum:
res.append(v)
if len(res) >= minimum:
break
if not 'next' in resp_json:
break
url = resp_json['next']

return res

def parse(args: List[str]) -> argparse.Namespace:
Expand Down
2 changes: 1 addition & 1 deletion tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ apt-get install -y curl

pushd pybatfish
# Install test dependencies
pip3 install "$(ls dist/pybatfish-*-py2.py3-none-any.whl)[dev]"
pip3 install "$(ls dist/pybatfish-*-py3-none-any.whl)[dev]"

echo Waiting for batfish to start
# Poll until we can connect to the coordinator
Expand Down
2 changes: 1 addition & 1 deletion tests/test_batfish_container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ source activate conda_env
# Install specific version of Pybatfish if specified, otherwise use the available version/wheel artifacts
if [ "${PYBATFISH_VERSION-}" == "" ]; then
PYBF_VERSION=$(cat /assets/pybatfish-version.txt)
pip install /assets/pybatfish-${PYBF_VERSION}-py2.py3-none-any.whl[dev]
pip install /assets/pybatfish-${PYBF_VERSION}-py3-none-any.whl[dev]
else
# Install from test PyPI for now (until it is on real PyPI)
pip install ${PYBATFISH_VERSION}
Expand Down

0 comments on commit a77786a

Please sign in to comment.