update defs script - #14
Merged
Merged
Conversation
ava-silver
force-pushed
the
as/update-defs-script
branch
from
August 1, 2026 03:42
1308064 to
6b78dac
Compare
ava-silver
commented
Aug 1, 2026
Comment on lines
+36
to
+59
| def get_by_external_id[ | ||
| T: HasExternalId | ||
| ](items: Collection[T], defs: list[T], save: Callable[[T], T]) -> dict[str, T]: | ||
| """gets a dict of items (groups/turfs) by their external id, | ||
| updating the db if the `defs` dont already exist in `items`""" | ||
| items_by_external_id = {i.external_id: i for i in items if i.external_id} | ||
| for item in defs: | ||
| if item.external_id not in items_by_external_id: | ||
| items_by_external_id[item.external_id] = save(item) | ||
| return items_by_external_id | ||
|
|
||
|
|
||
| def make_list_of_defs[ | ||
| T: Any | ||
| ](constructor: type[T], configs: list[dict[str, Any]]) -> list[T]: | ||
| "constructs a list of the actual type based on the yaml defs" | ||
| return [ | ||
| constructor( | ||
| external_id=config["name"], | ||
| created_by="system import", | ||
| **config.get("props", {}), | ||
| ) | ||
| for config in configs | ||
| ] |
Collaborator
Author
There was a problem hiding this comment.
made these to unify the processing of defs/updating the database so copy/paste errors dont mess things up in the future
an-empty-string
approved these changes
Aug 1, 2026
an-empty-string
left a comment
Owner
There was a problem hiding this comment.
lgtm (looks golfcart to me)
Comment on lines
+36
to
+59
| def get_by_external_id[ | ||
| T: HasExternalId | ||
| ](items: Collection[T], defs: list[T], save: Callable[[T], T]) -> dict[str, T]: | ||
| """gets a dict of items (groups/turfs) by their external id, | ||
| updating the db if the `defs` dont already exist in `items`""" | ||
| items_by_external_id = {i.external_id: i for i in items if i.external_id} | ||
| for item in defs: | ||
| if item.external_id not in items_by_external_id: | ||
| items_by_external_id[item.external_id] = save(item) | ||
| return items_by_external_id | ||
|
|
||
|
|
||
| def make_list_of_defs[ | ||
| T: Any | ||
| ](constructor: type[T], configs: list[dict[str, Any]]) -> list[T]: | ||
| "constructs a list of the actual type based on the yaml defs" | ||
| return [ | ||
| constructor( | ||
| external_id=config["name"], | ||
| created_by="system import", | ||
| **config.get("props", {}), | ||
| ) | ||
| for config in configs | ||
| ] |
| turfs_by_external_id[config["name"]] = database.save_turf( | ||
| Turf(external_id=config["name"], created_by="system import") | ||
| def get_by_external_id[ | ||
| T: HasExternalId |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cleans up the defs script, so now the file is
defs.yml, and adds to the format atypefield to each entry for either aturfor agroup: