Repository navigation
Conversation
06f5146 to
44b209a
Compare
7b95245 to
6a52c6e
Compare
d700dfe to
d614ea6
Compare
a2b3098 to
1f1e850
Compare
sipsma
left a comment
There was a problem hiding this comment.
One nit and looks like docs are pending; just want to make sure those are in by the release on Friday if we want this for v0.14.0 🙂
| func pythonSourceAt(modPath, contents string) dagger.WithContainerFunc { | ||
| return fileContents(path.Join(modPath, pythonSourcePath), contents) | ||
| return fileContents(path.Join(modPath, "src/test/__init__.py"), contents) |
There was a problem hiding this comment.
nit: could the name of the module become a parameter rather than hardcoding test? Just seems like a gotcha to have to name the module test in order for this to work as expected (IIUC).
Realize this might be a super tedious update, not a blocker
There was a problem hiding this comment.
I think this is fine considering the alternative. If I make it a parameter then it becomes pretty tedious whenever this is used in any language. So I figured a convention for a module named "test" is simpler. There's test cases that use a different module name, they just don't use this helper.
Yeah, those are coming tomorrow, I hope. I just need to prioritize |
1f1e850 to
bb36bd7
Compare
a9bac7a to
bb36bd7
Compare
|
Docs update in its own PR: |
Signed-off-by: Helder Correia <[email protected]>
Signed-off-by: Helder Correia <[email protected]>
Signed-off-by: Helder Correia <[email protected]>
Signed-off-by: Helder Correia <[email protected]>
Signed-off-by: Helder Correia <[email protected]>
Signed-off-by: Helder Correia <[email protected]>
bb36bd7 to
fb62b30
Compare
Fixes #8535
Note
This is a backwards compatible change. Only new modules get the new file structure. For existing modules, there's more freedom to change, but not enforced.
What?
This changes the layout for new modules. For example:
❯ dagger init --sdk=python my-moduleGenerates the name
my-modulefor the project:And puts sources under
src/my_module:With
__init__.pyusing this import:But users have now complete control to specify where the main object needs to be imported from. For example:
With the above, the
__init__.pycould be empty as it no longer needs to import the main object there because the entry point is specifically importing frommy_module.main, notmy_module.Refactors
Simpler loading of
dagger.mod.ModulePreviously, user code was imported by an hardcoded:
The SDK would look for instances of
dagger.mod.Module, which is what’s actually needed to execute. So you could use a custom subclass to customize some aspect of module handling. One early example of what I had in mind for this is to allow registering more hooks to teach dagger how to convert some custom types:To do this, I added the
dagger.mod.Moduleto the@object_typedecorated class. This way, the SDK only needs to import the main object itself, since it’s now able to get the correspondingdagger.mod.Moduleinstance from there. So even if you have different instances ofdagger.mod.Modulefor some reason, it doesn’t matter.This is more correct, and avoids the need for the extra “smartness” and validation.
Added customization on where to import the main object
I could just replace the hardcoded
main:<MainObject>by the normalized module name coming from an env variable (e.g.,my_module:<MainObject>), but I wanted to take advantage of the new file structure and module loading simplification, to give users more control by being able to specify explicitly where the main object should be imported from.This way users have even less restrictions on how to organize their files. For example, it’s now possible to even remove the import in
src/my_module/__init__.py:-from .main import MyModule as MyModuleSince you can now tell the SDK where the main object is located, with a Python entry point:
If this setting doesn’t exist, the SDK will try to load from
<package>:<MainObject>:And if that import fails, it will fallback to trying out
main(e.g., for currently existing modules):This ensures backwards compatibility, and less limitations on code organization. The only one remaining is that it still needs to be a distribution package (installable).
Todo