Skip to content

Commit ebc5a4a

Browse files
authored
fixed download models on windows (#47)
* minor refactory of github actions * moved os to matrix * test on windows * try using `python` to create venv * moved make argument * attempt to detect os * run pip via python * don't use os.path.join for download url * test model urls * remove slash from default storage url * don't use os.path.join for s3 url * linting * enable test on macos
1 parent c513036 commit ebc5a4a

File tree

6 files changed

+48
-12
lines changed

6 files changed

+48
-12
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,18 @@ on:
1111
jobs:
1212
build:
1313

14-
runs-on: ubuntu-latest
14+
runs-on: ${{ matrix.os }}
1515
strategy:
1616
matrix:
17+
os: [ubuntu-latest]
1718
python-version: [3.6, 3.7, 3.8]
19+
include:
20+
- python-version: 3.8
21+
push-package: true
22+
- os: windows-latest
23+
python-version: 3.8
24+
- os: macos-latest
25+
python-version: 3.8
1826

1927
steps:
2028
- uses: actions/checkout@v2
@@ -24,25 +32,25 @@ jobs:
2432
python-version: ${{ matrix.python-version }}
2533
- name: Install dependencies
2634
run: |
27-
make dev-venv
35+
make dev-venv SYSTEM_PYTHON=python
2836
- name: Lint
2937
run: |
3038
make dev-lint
3139
- name: Test with pytest
3240
run: |
3341
make dev-pytest
3442
- name: Build dist
35-
if: matrix.python-version == '3.8'
43+
if: matrix.push-package == true
3644
run: |
3745
make dev-remove-dist dev-build-dist dev-list-dist-contents dev-test-install-dist
3846
- name: Publish distribution to Test PyPI
39-
if: matrix.python-version == '3.8'
47+
if: matrix.push-package == true
4048
uses: pypa/gh-action-pypi-publish@master
4149
with:
4250
password: ${{ secrets.test_pypi_password }}
4351
repository_url: https://test.pypi.org/legacy/
4452
- name: Publish distribution to PyPI
45-
if: matrix.python-version == '3.8' && startsWith(github.ref, 'refs/tags')
53+
if: matrix.push-package == true && startsWith(github.ref, 'refs/tags')
4654
uses: pypa/gh-action-pypi-publish@master
4755
with:
4856
password: ${{ secrets.pypi_password }}

Makefile

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
VENV = venv
2-
PIP = $(VENV)/bin/pip
3-
PYTHON = $(VENV)/bin/python
2+
3+
ifeq ($(OS),Windows_NT)
4+
VENV_BIN = $(VENV)/Scripts
5+
else
6+
VENV_BIN = $(VENV)/bin
7+
endif
8+
9+
PYTHON = $(VENV_BIN)/python
10+
PIP = $(VENV_BIN)/python -m pip
11+
12+
SYSTEM_PYTHON = python3
413

514
VENV_TEMP = venv_temp
615

@@ -30,7 +39,7 @@ venv-clean:
3039

3140

3241
venv-create:
33-
python3 -m venv $(VENV)
42+
$(SYSTEM_PYTHON) -m venv $(VENV)
3443

3544

3645
dev-install:

tests/cli_test.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
import logging
12
from pathlib import Path
23

4+
from tf_bodypix.download import BodyPixModelPaths
35
from tf_bodypix.cli import main
46

57

8+
LOGGER = logging.getLogger(__name__)
9+
10+
611
EXAMPLE_IMAGE_URL = (
712
r'https://upload.wikimedia.org/wikipedia/commons/thumb/5/5e/'
813
r'Person_Of_Interest_-_Panel_%289353656298%29.jpg/'
@@ -69,3 +74,16 @@ def test_should_not_fail_to_replace_background(self, temp_dir: Path):
6974
'--background=%s' % EXAMPLE_IMAGE_URL,
7075
'--output=%s' % output_image_path
7176
])
77+
78+
def test_should_list_all_default_model_urls(self, capsys):
79+
expected_urls = [
80+
value
81+
for key, value in BodyPixModelPaths.__dict__.items()
82+
if not key.startswith('_')
83+
]
84+
main(['list-models'])
85+
captured = capsys.readouterr()
86+
output_urls = captured.out.splitlines()
87+
LOGGER.debug('output_urls: %s', output_urls)
88+
missing_urls = set(expected_urls) - set(output_urls)
89+
assert not missing_urls

tf_bodypix/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def add_arguments(self, parser: argparse.ArgumentParser):
253253
add_common_arguments(parser)
254254
parser.add_argument(
255255
"--storage-url",
256-
default="https://storage.googleapis.com/tfjs-models/",
256+
default="https://storage.googleapis.com/tfjs-models",
257257
help="The base URL for the storage containing the models"
258258
)
259259

tf_bodypix/download.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def download_model(model_path: str) -> str:
7878
for weights_manifest_path in weights_manifest_paths:
7979
local_model_json_path = tf.keras.utils.get_file(
8080
os.path.basename(weights_manifest_path),
81-
os.path.join(model_base_path, weights_manifest_path),
81+
model_base_path + '/' + weights_manifest_path,
8282
cache_subdir=cache_subdir,
8383
)
8484
return local_model_path

tf_bodypix/utils/s3.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import logging
22

3-
import os
43
import urllib.request
54
from xml.etree import ElementTree
65
from typing import Iterable
@@ -17,6 +16,8 @@
1716

1817

1918
def iter_s3_file_urls(base_url: str) -> Iterable[str]:
19+
if not base_url.endswith('/'):
20+
base_url += '/'
2021
marker = None
2122
while True:
2223
current_url = base_url
@@ -29,7 +30,7 @@ def iter_s3_file_urls(base_url: str) -> Iterable[str]:
2930
for item in root.findall(S3_CONTENTS):
3031
key = item.findtext(S3_KEY)
3132
LOGGER.debug('key: %s', key)
32-
yield os.path.join(base_url, key)
33+
yield base_url + key
3334
next_marker = root.findtext(S3_NEXT_MARKER)
3435
if not next_marker or next_marker == marker:
3536
break

0 commit comments

Comments
 (0)