Skip to content

Conversation

@rudolfix
Copy link
Collaborator

Description

fixes #1596 and indirectly #1629

allows to instantiate custom config provider with user supplied loading function which may process any file format from any location

@rudolfix rudolfix added the support This issue is monitored by Solution Engineer label Jul 27, 2024
@rudolfix rudolfix self-assigned this Jul 27, 2024
@netlify
Copy link

netlify bot commented Jul 27, 2024

Deploy Preview for dlt-hub-docs ready!

Name Link
🔨 Latest commit 6698c51
🔍 Latest deploy log https://app.netlify.com/sites/dlt-hub-docs/deploys/66a79533d7f3600008e00827
😎 Deploy Preview https://deploy-preview-1642--dlt-hub-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@rudolfix rudolfix marked this pull request as ready for review July 28, 2024 16:08
@rudolfix
Copy link
Collaborator Author

@rudolfix rudolfix requested review from VioletM and sh-rp July 28, 2024 16:29
Implement and use your own config provider by just providing loader function. See [example](../../examples/custom_config_provider) for `yaml` based config that
supports switchable profiles.
:::

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize that the latter is already covered by the example, I'd still add two super simple examples of the BaseDocProvider and the CustomLoaderDocProvider here, but this could be done in a followup PR.

provider = CustomLoaderDocProvider("profiles", functools.partial(loader, profile_name))
# register provider, it will be added as the last one in chain
dlt.config.register_provider(provider)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add a comment here that this is the place to run the pipeline (imho examples should always be thought of in the context of a pipeline execution)

"""
self._name = name
self._supports_secrets = supports_secrets
super().__init__(loader())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the use of this CustomLoaderProvider if it is not lazily evaluated on first access of the dict?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heh you are right. in this implementation it does not make sense. BUT maybe we want to change it to lazy evaluation ie. on first use. may be necessary ie. on Airflow. so let's keep it like that!


# instantiate custom provider using `prod` profile
# NOTE: all placeholders (ie. GITHUB_API_KEY) will be evaluated in next line!
provider = CustomLoaderDocProvider("profiles", functools.partial(loader, profile_name))
Copy link
Collaborator

@sh-rp sh-rp Jul 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not use stuff like partials in examples if it is not absolutely necessary. While I agree the code looks nicer this way, my intuition says this makes it harder to understand what is going on for less experienced devs. It's up to you what you think :)

Copy link
Collaborator

@sh-rp sh-rp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super useful PR imho. I have a few comments, none of which are super important for this release, but the docs could be better / more helpful.

VioletM
VioletM previously approved these changes Jul 29, 2024
Copy link
Contributor

@VioletM VioletM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good!

I'd say we should add more docs and examples for CustomLoaderDocProvider. But it can be done in the separate PR later after we'll get the first feedback :)

# instantiate custom provider using `prod` profile
# NOTE: all placeholders (ie. GITHUB_API_KEY) will be evaluated in next line!
provider = CustomLoaderDocProvider("profiles", functools.partial(loader, profile_name))
# register provider, it will be added as the last one in chain
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last one in the chain means, that if they have secrets.toml or env variable with the same key it will override the explicitly registered CustomLoaderDocProvider provider, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just seems more intuitive for me that the custom provider I wrote to be the first in chain. But I guess it's OK, as long as it's stated in the docs

@sh-rp sh-rp merged commit 9823773 into devel Jul 29, 2024
@sh-rp sh-rp deleted the feat/1596-adds-custom-docs-config-provider branch July 29, 2024 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

support This issue is monitored by Solution Engineer

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

allow yaml as alternative to toml in config/secrets

4 participants