singer-io / singer-python

Writes the Singer format from Python
https://singer.io
Apache License 2.0
538 stars 128 forks source link

Use `importlib.resources` to load default logging config file #164

Open edgarrmondragon opened 8 months ago

edgarrmondragon commented 8 months ago

Description of change

This allows packaging Singer taps and targets as zipapps, which can be executed directly by a Python interpreter without needing to install any dependencies:

$ python3 tap-surveymonkey.pyz --config config.json --discover > catalog.json

Otherwise errors like this are raised:

$ python3 target-jsonl.pyz --help
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/projects/target-jsonl/target-jsonl.pyz/__main__.py", line 2, in <module>
  File "/projects/target-jsonl/target-jsonl.pyz/target_jsonl.py", line 12, in <module>
  File "/projects/target-jsonl/target-jsonl.pyz/singer/__init__.py", line 1, in <module>
  File "/projects/target-jsonl/target-jsonl.pyz/singer/utils.py", line 13, in <module>
  File "/projects/target-jsonl/target-jsonl.pyz/singer/catalog.py", line 10, in <module>
  File "/projects/target-jsonl/target-jsonl.pyz/singer/logger.py", line 16, in get_logger
  File "/Users/personal/.pyenv/versions/3.11.7/lib/python3.11/logging/config.py", line 65, in fileConfig
    raise FileNotFoundError(f"{fname} doesn't exist")
FileNotFoundError: /projects/target-jsonl/target-jsonl.pyz/singer/logging.conf doesn't exist

With this change:

$ python3 target-jsonl.pyz --help
usage: target-jsonl.pyz [-h] [-c CONFIG]

options:
  -h, --help            show this help message and exit
  -c CONFIG, --config CONFIG
                        Config file

Manual QA steps

Risks

Rollback steps

edgarrmondragon commented 1 month ago

Ping. IMO this is a small but useful change for distributing singer taps built with the singer-python library :)