Skip to content

Commit

Permalink
Enable the device tests and update utils (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyfowers authored Aug 28, 2024
1 parent 37f5e8d commit 4c51521
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 32 deletions.
40 changes: 20 additions & 20 deletions .github/workflows/test_devices_plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@

name: Lint and Test Devices Plugin

# on:
# push:
# branches: ["main"]
# paths:
# - plugins/devices/src/turnkeyml_plugin_devices/common/**
# - plugins/devices/src/turnkeyml_plugin_devices/onnxrt/**
# - plugins/devices/src/turnkeyml_plugin_devices/torchrt/**
# - plugins/devices/src/turnkeyml_plugin_devices/tensorrt/**
# - plugins/devices/setup.py
# - .github/workflows/test_devices_plugin.yml
# pull_request:
# branches: ["main"]
# paths:
# - plugins/devices/src/turnkeyml_plugin_devices/common/**
# - plugins/devices/src/turnkeyml_plugin_devices/onnxrt/**
# - plugins/devices/src/turnkeyml_plugin_devices/torchrt/**
# - plugins/devices/src/turnkeyml_plugin_devices/tensorrt/**
# - plugins/devices/setup.py
# - .github/workflows/test_devices_plugin.yml
on:
push:
branches: ["main"]
paths:
- plugins/devices/src/turnkeyml_plugin_devices/common/**
- plugins/devices/src/turnkeyml_plugin_devices/onnxrt/**
- plugins/devices/src/turnkeyml_plugin_devices/torchrt/**
- plugins/devices/src/turnkeyml_plugin_devices/tensorrt/**
- plugins/devices/setup.py
- .github/workflows/test_devices_plugin.yml
pull_request:
branches: ["main"]
paths:
- plugins/devices/src/turnkeyml_plugin_devices/common/**
- plugins/devices/src/turnkeyml_plugin_devices/onnxrt/**
- plugins/devices/src/turnkeyml_plugin_devices/torchrt/**
- plugins/devices/src/turnkeyml_plugin_devices/tensorrt/**
- plugins/devices/setup.py
- .github/workflows/test_devices_plugin.yml

permissions:
contents: read
Expand Down Expand Up @@ -55,7 +55,7 @@ jobs:
- name: Lint with PyLint
shell: bash -el {0}
run: |
pylint plugins/devices/src --rcfile .pylintrc --disable E0401,E0203
pylint plugins/devices/src --rcfile .pylintrc --disable E0401,E0203,C0411
- name: Test with unittest
shell: bash -el {0}
run: |
Expand Down
31 changes: 19 additions & 12 deletions plugins/devices/src/turnkeyml_plugin_devices/common/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,22 @@ def write_env_version(plugin_name: str, env_path: str):
shutil.copy(version_path(plugin_name), get_env_version_path(env_path))


def get_directory_size(directory):
total_size = 0
for dirpath, _, filenames in os.walk(directory):
for filename in filenames:
filepath = os.path.join(dirpath, filename)
total_size += os.path.getsize(filepath)
return total_size


def lfs_pull(plugin_name: str):
dependencies_dir = get_deps_dir(plugin_name)

# For developers in editable mode, fetch the deps folder from git lfs
# NOTE: for non-editable-mode (ie, `pip install` with the `-e`):
# `git lfs pull -I PLUGIN_PATH` needs to be manually called prior to `pip install`
deps_size_bytes = sum(
os.path.getsize(os.path.join(dependencies_dir, f))
for f in os.listdir(dependencies_dir)
if os.path.isfile(os.path.join(dependencies_dir, f))
)
deps_size_bytes = get_directory_size(dependencies_dir)

# LFS files have not been pulled if the deps folder is under 100KB
# because the folder will only have LFS pointers in it, which are about 100B each
Expand All @@ -114,7 +119,13 @@ def lfs_pull(plugin_name: str):
# like site-packages then this will be skipped
with open(os.devnull, "w", encoding="utf-8") as d:
is_git_repo = not bool(
subprocess.call("git rev-parse", shell=True, stdout=d, stderr=d)
subprocess.call(
"git rev-parse",
shell=True,
stdout=d,
stderr=d,
cwd=os.path.abspath(os.path.dirname(__file__)),
)
)

if is_git_repo and deps_size_bytes < deps_folder_too_small_size_bytes:
Expand All @@ -135,14 +146,10 @@ def lfs_pull(plugin_name: str):

# If the deps size didn't change after the pull, that means the pull
# silently failed. Raise a helpful exception.
deps_size_bytes_post_pull = sum(
os.path.getsize(os.path.join(dependencies_dir, f))
for f in os.listdir(dependencies_dir)
if os.path.isfile(os.path.join(dependencies_dir, f))
)
deps_size_bytes_post_pull = get_directory_size(dependencies_dir)
if deps_size_bytes_post_pull < deps_folder_too_small_size_bytes:
raise exp.EnvError(
"The vitisep dependencies have not been pulled from LFS "
"The plugin dependencies have not been pulled from LFS "
"If you are building from source you can try running this command: "
f"`{lfs_command}`"
)
Expand Down

0 comments on commit 4c51521

Please sign in to comment.