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

[module-loaders] Simplify module asset loader code path #26484

Conversation

dpeng817
Copy link
Contributor

@dpeng817 dpeng817 commented Dec 13, 2024

Summary & Motivation

This code path was highly crufty - code smell here is "iterating through big list and doing a ton of things at once". Solution is to create a lookup table of cacheable properties and imperatively call properties as you need them (stole this pattern from @schrockn when we were working on airlift stuff) I think the code is a lot clearer now.

I also got rid of an error message we were devoting a lot of lines to that felt very outdated; nobody is using with_resources, and repository_def is misleading.

I think we also end up catching a few hidden error states; for example, we weren't checking assetsdefs against sourceassets with the same key, sourceasset collision checking felt more like a side effect.

How I Tested These Changes

Existing tests

Copy link
Contributor Author

dpeng817 commented Dec 13, 2024

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

Comment on lines 170 to 159
assets_list = LoadedAssetsList.from_modules(modules)
return assets_list.assets_defs, assets_list.sources, assets_list.cacheables
Copy link

Choose a reason for hiding this comment

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

The extra_source_assets parameter is being dropped in this refactor. To maintain the existing functionality, the source assets should be combined like this:

return assets_list.assets_defs, list(check.opt_sequence_param(extra_source_assets, 'extra_source_assets', of_type=SourceAsset)) + assets_list.sources, assets_list.cacheables

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.

@dpeng817 dpeng817 marked this pull request as ready for review December 13, 2024 20:29
@dpeng817 dpeng817 force-pushed the dpeng817/dpeng817/simplify_module_asset_loader branch from d52130a to ea633af Compare December 13, 2024 22:39
@dpeng817 dpeng817 changed the base branch from master to dpeng817/delete_extra_source_assets December 13, 2024 22:39
Copy link
Contributor

@OwenKephart OwenKephart left a comment

Choose a reason for hiding this comment

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

soooo much better

@@ -63,48 +149,12 @@ def assets_from_modules(
A tuple containing a list of assets, a list of source assets, and a list of
Copy link
Contributor

Choose a reason for hiding this comment

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

[Re: line +144]

lol i guess remove that

See this comment inline on Graphite.

Copy link
Member

@schrockn schrockn left a comment

Choose a reason for hiding this comment

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

I think we can do better here and simplify it further having assets_from_modules returning to a List[AssetsDefinitions] which will simplify all of this even more.

@OwenKephart
Copy link
Contributor

I think we can do better here and simplify it further having assets_from_modules returning to a List[AssetsDefinitions] which will simplify all of this even more.

@schrockn this function is (somewhat tragically) part of the public API so we can't change the type signature

@schrockn
Copy link
Member

Ah yeah you are right. I was thinking that in our code it would be likely be backwards compatible change to go from

Sequence[Union[AssetsDefinition, SourceAsset, CacheableAssetsDefinition]] to Sequence[AssetsDefinition] but that is only true if you don't do much processing in getting all those definitions and passing them to Definitions.

The only way out is through components.

@dpeng817 dpeng817 force-pushed the dpeng817/delete_extra_source_assets branch 2 times, most recently from 2219a42 to 2853ef1 Compare December 18, 2024 18:36
@dpeng817 dpeng817 force-pushed the dpeng817/dpeng817/simplify_module_asset_loader branch from c63cd60 to 9beb0c3 Compare December 18, 2024 18:36
@dpeng817 dpeng817 merged commit 22860d7 into dpeng817/delete_extra_source_assets Dec 18, 2024
1 check was pending
@dpeng817 dpeng817 deleted the dpeng817/dpeng817/simplify_module_asset_loader branch December 18, 2024 18:38
dpeng817 added a commit that referenced this pull request Dec 19, 2024
## Summary & Motivation
This code path was highly crufty - code smell here is "iterating through
big list and doing a ton of things at once". Solution is to create a
lookup table of cacheable properties and imperatively call properties as
you need them (stole this pattern from @schrockn when we were working on
airlift stuff) I think the code is a lot clearer now.

I also got rid of an error message we were devoting a lot of lines to
that felt very outdated; nobody is using with_resources, and
repository_def is misleading.

I think we also end up catching a few hidden error states; for example,
we weren't checking assetsdefs against sourceassets with the same key,
sourceasset collision checking felt more like a side effect.

## How I Tested These Changes
Existing tests
dpeng817 added a commit that referenced this pull request Dec 19, 2024
## Summary & Motivation
This code path was highly crufty - code smell here is "iterating through
big list and doing a ton of things at once". Solution is to create a
lookup table of cacheable properties and imperatively call properties as
you need them (stole this pattern from @schrockn when we were working on
airlift stuff) I think the code is a lot clearer now.

I also got rid of an error message we were devoting a lot of lines to
that felt very outdated; nobody is using with_resources, and
repository_def is misleading.

I think we also end up catching a few hidden error states; for example,
we weren't checking assetsdefs against sourceassets with the same key,
sourceasset collision checking felt more like a side effect.

## How I Tested These Changes
Existing tests
dpeng817 added a commit that referenced this pull request Dec 19, 2024
## Summary & Motivation
This code path was highly crufty - code smell here is "iterating through
big list and doing a ton of things at once". Solution is to create a
lookup table of cacheable properties and imperatively call properties as
you need them (stole this pattern from @schrockn when we were working on
airlift stuff) I think the code is a lot clearer now.

I also got rid of an error message we were devoting a lot of lines to
that felt very outdated; nobody is using with_resources, and
repository_def is misleading.

I think we also end up catching a few hidden error states; for example,
we weren't checking assetsdefs against sourceassets with the same key,
sourceasset collision checking felt more like a side effect.

## How I Tested These Changes
Existing tests
dpeng817 added a commit that referenced this pull request Dec 19, 2024
## Summary & Motivation
This code path was highly crufty - code smell here is "iterating through
big list and doing a ton of things at once". Solution is to create a
lookup table of cacheable properties and imperatively call properties as
you need them (stole this pattern from @schrockn when we were working on
airlift stuff) I think the code is a lot clearer now.

I also got rid of an error message we were devoting a lot of lines to
that felt very outdated; nobody is using with_resources, and
repository_def is misleading.

I think we also end up catching a few hidden error states; for example,
we weren't checking assetsdefs against sourceassets with the same key,
sourceasset collision checking felt more like a side effect.

## How I Tested These Changes
Existing tests
dpeng817 added a commit that referenced this pull request Dec 19, 2024
## Summary & Motivation
This code path was highly crufty - code smell here is "iterating through
big list and doing a ton of things at once". Solution is to create a
lookup table of cacheable properties and imperatively call properties as
you need them (stole this pattern from @schrockn when we were working on
airlift stuff) I think the code is a lot clearer now.

I also got rid of an error message we were devoting a lot of lines to
that felt very outdated; nobody is using with_resources, and
repository_def is misleading.

I think we also end up catching a few hidden error states; for example,
we weren't checking assetsdefs against sourceassets with the same key,
sourceasset collision checking felt more like a side effect.

## How I Tested These Changes
Existing tests
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.

3 participants