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

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

edgarrmondragon
Copy link

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

  • revert this branch

This allows packaging Singer taps and targets as [_zipapps_](https://docs.python.org/3/library/zipapp.html), which can be executed directly by a Python interpreter without needing to install any dependencies:

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

Otherwise errors like this are raised:

```console
$ 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:

```console
$ 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
```
@edgarrmondragon edgarrmondragon changed the title Use importlib.resources default config file Use importlib.resources default logging config file Dec 13, 2023
@edgarrmondragon edgarrmondragon changed the title Use importlib.resources default logging config file Use importlib.resources to load default logging config file Jan 14, 2024
@edgarrmondragon edgarrmondragon marked this pull request as ready for review January 14, 2024 17:27
@edgarrmondragon
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant