-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build: allow partial override of build steps (#11710)
I was replacing some of the config models with dataclasses, but I found myself re-implementing some helpers that pydantic provides, so I'm introducing that new dep, it has everything we need, we may be able to use it to simplify our validation once all models are migrated to pydantic. ### About incompatible options I decided to just not allow formats when `build.jobs.build` is used, seems just easier that way. But not sure if users may want to just override the html build step while still using the default build pdf step, if that's the case, we may need to support using formats... or have another way of saying "use the default". build.jobs.create_environment is kind of incompatible with python/conda. Since users will need to manually create the environment, but they may still want to use the defaults from build.jobs.install, or maybe they can't even use the defaults, as they are really tied to the default create_environment step. Which bring us to the next point, if build.jobs.create_environment is overridden, users will likely need to override build.jobs.install and build.jobs.build as well... Maybe just save the user some time and require them to override all of them? Or maybe just let them figure it out by themselves with the errors? We could gather more information once we see some real usage of this... ### Override them all I chose to make build.html required if users override that step, seems logical to do so. ~~Do we want to allow users to build all formats? I'm starting with html and pdf, that seem the most used. But shouldn't be a problem to support all of them. I guess my only question would be about naming, `htmlzip` has always been a weird name, maybe just zip?~~ I just went ahead and allowed all, with the same name as formats. ### Docs I didn't add docs yet because there is the question... should we just expose this to users? Or maybe just test it internally for now? Closes #11551
- Loading branch information
Showing
15 changed files
with
494 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Sentinel value to check if a default value was provided, | ||
# so we can differentiate when None is provided as a default value | ||
# and when it was not provided at all. | ||
_DEFAULT = object() | ||
|
||
|
||
def get_dotted_attribute(obj, attribute, default=_DEFAULT): | ||
""" | ||
Allow to get nested attributes from an object using a dot notation. | ||
This behaves similar to getattr, but allows to get nested attributes. | ||
Similar, if a default value is provided, it will be returned if the | ||
attribute is not found, otherwise it will raise an AttributeError. | ||
""" | ||
for attr in attribute.split("."): | ||
if hasattr(obj, attr): | ||
obj = getattr(obj, attr) | ||
elif default is not _DEFAULT: | ||
return default | ||
else: | ||
raise AttributeError(f"Object {obj} has no attribute {attr}") | ||
return obj |
Oops, something went wrong.