How can I utilize arbitrary assets in my tool?
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
I'm following the steps listed on the FAQ page. I have a `data.json` file with some information that I want packaged with the plugin.
- The file's path in the project is `backend\assets\data.json`.
- `backend\setup.py` was modified to include `package_data={...}`.
if __name__ == "__main__":
setup(
name=PACKAGE_NAME,
version=VERSION,
description=SUMMARY,
long_description_content_type="text/markdown",
platforms=["Windows"],
author="Alteryx, Inc.",
author_email="support@alteryx.com",
packages=find_packages(
exclude=["examples", "*.tests", "*.tests.*", "tests.*", "tests"]
),
package_data={
PACKAGE_NAME: [
"assets/*"
]
}
)
- backend\ayx_plugins\my_plugin.py attempts to read `data.json` in the `__init__`.
from pathlib import Path
import json
import os
def __init__(self, provider: AMPProviderV2):
self.name = "My Plugin"
self.provider = provider
self.data = json.load(open(Path(os.path.realpath(__file__)).parent / "assets" / "data.json"))
- Build the plugin.
> echo y | ayx_plugin_cli designer-install --use-ui --install-type user
However this results in the error
Error: My Plugin (1): Could not init plugin FileNotFoundError(2, 'No such file or directory')
This is because the path it attempts to open is
C:\Users\username\.shiv\main_abcdefg123456789\site-packages\ayx_plugins\assets\data.json
but there is no \assets folder here.
Solved! Go to Solution.
- Labels:
-
Custom Tools
-
SDK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
https://setuptools.pypa.io/en/latest/userguide/datafiles.html - you might need to tinker with the setup.py a bit to get it to do what you want. My guess is that you might need to pass in the include_package_data argument to the setup script, or you'll need to specify the "assets/*.json", or "assets/data.json". When you create the YXI, you should also see a hidden cache folder in your workspace - under `.ayx_cli.cache/dist` you'll see exactly what goes into the shiv artifact. Try messing around with it until the data.json shows up where it should
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Seems I misinterpreted the FAQ, and the `assets` folder needs to be under `backend/ayx_plugins/assets` and not `backend/assets`. Then `package_data={PACKAGE_NAME: ["assets/*"]}` will pick it up.