Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable the device tests and update utils #224

Merged
merged 3 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
jeremyfowers marked this conversation as resolved.
Show resolved Hide resolved
- 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
Loading