You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The currently recommended way (as used in the cookiecutter templates) to ship JSON files for the stream schemas relies on __file__, which doesn't play well with modern tools for packaging a Python application (such as a Singer tap/target) as a standalone binary, such as PyOxidizer.
The solution is to use importlib.resources or the backport package importlib_resources on Python < 3.9.
This would also require changing the following:
drop support for raw string file path
discourage use of Path instances
change our type hints to use importlib.resources.abc.Traversable
add an __init__.py to the schemas/ directory shipped with the cookiecutter
For a example, see edgarrmondragon/tap-bitso#125. The PR is currently failing static type checks because type annotations are not compatible with the latest SDK.
Code
+ from my_tap import schemas # assumes a __init__.py exists in my_tap/schemas/++ if sys.version_info >= (3, 9):+ import importlib.resources as resources+ else:+ import importlib_resources as resources- SCHEMAS_DIR = Path(__file__).parent / "./schemas"+ SCHEMAS_DIR = resources.files(schemas)
The text was updated successfully, but these errors were encountered:
edgarrmondragon
changed the title
[Bug]: Recommended way of packaging stream should use importlib.resources
[Bug]: Recommended way of packaging stream schemas as JSON files should use importlib.resourcesAug 1, 2022
This has been marked as stale because it is unassigned, and has not had recent activity. It will be closed after 21 days if no further activity occurs. If this should never go stale, please add the evergreen label, or request that it be added.
Singer SDK Version
latest
Python Version
NA
Bug scope
Taps (catalog, state, stream maps, etc.)
Operating System
Any
Description
The currently recommended way (as used in the cookiecutter templates) to ship JSON files for the stream schemas relies on
__file__
, which doesn't play well with modern tools for packaging a Python application (such as a Singer tap/target) as a standalone binary, such as PyOxidizer.The solution is to use
importlib.resources
or the backport packageimportlib_resources
on Python < 3.9.This would also require changing the following:
Path
instancesimportlib.resources.abc.Traversable
__init__.py
to theschemas/
directory shipped with the cookiecutterFor a example, see edgarrmondragon/tap-bitso#125. The PR is currently failing static type checks because type annotations are not compatible with the latest SDK.
Code
The text was updated successfully, but these errors were encountered: