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

Feat: Add environments command to list environments #3770

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lafirm
Copy link
Contributor

@lafirm lafirm commented Feb 1, 2025

Fixes #3732

I came across this feature request and found it interesting. I made some assumptions and created this PR. Please review and share your feedback. thanks :)

@cli_analytics
def environments(obj: Context, expiry_ds: bool) -> None:
"""Prints the list of SQLMesh environments with its expiration datetime."""
environments = {e.name: e.expiration_ts for e in obj.state_sync.get_environments()}
Copy link
Member

Choose a reason for hiding this comment

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

Just a heads up that environment objects are pretty large and loading and parsing them all at once can be a pretty long and memory-intensive operation for big projects with a lot of environments.

A better approach could be having a specialized method in the the state_sync.py that only fetches limited fields like names.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, I'll do this. Thanks :)

environment_names = list(environments.keys())
if expiry_ds:
max_width = len(max(environment_names, key=len))
print(
Copy link
Member

Choose a reason for hiding this comment

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

I think we should be using the console instance here as well.

)
@line_magic
@pass_sqlmesh_context
def environments(self, context: Context, line: str) -> None:
Copy link
Member

@izeigerman izeigerman Feb 2, 2025

Choose a reason for hiding this comment

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

This looks like the exact copy-paste of the code above. It might be worse considering having a method as part of Context that prints this.

Copy link
Contributor Author

@lafirm lafirm Feb 3, 2025

Choose a reason for hiding this comment

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

I followed the pattern used by table_name method in magics.py.

If you not mind could you please elaborate on whats expected here?

@izeigerman
Copy link
Member

Thanks a lot for your contribution! Left some comments

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.

Add command to list environments
2 participants