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

Add --python-dx flag to truss init #1367

Merged
merged 2 commits into from
Feb 5, 2025
Merged

Conversation

nnarayen
Copy link
Contributor

@nnarayen nnarayen commented Feb 4, 2025

🚀 What

This PR introduces an optional --python-dx flag to truss init which we believe will help streamline potential adoption of the new functionality.

💻 How

🔬 Testing

  • New unit tests
  • Explicitly running truss init --no-python-dx and truss init --python dx

@nnarayen nnarayen force-pushed the nikhil/python-dx-truss-init branch from 69fe726 to 0864e67 Compare February 4, 2025 23:17

return target_directory_path_typed


def init_directory(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As always a little refactor crept into my PR 😄 . Currently, the init method below is used in exactly one non-test location, and it doesn't have the data_files, requirements_file, or bundled_packages arguments. I believe we should eventually deprecate that method, as long as we find a good way to preserve the same test coverage for all functionality that's actually used. However, I think it's cleaner to do in a separate PR.

The main reason I needed to change this is the existing init method returns a TrussHandle, which would complain with the new generated code since it doesn't have a config.yaml. The cli entrypoint actually ignores the return value (only used in tests), so I refactored into an init_directory which doesn't wrap in a TrussHandle.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can this fucntion be merged with _populate_target_directory?

Copy link
Contributor

Choose a reason for hiding this comment

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

Or a better structuring would be to put the two if/else blocks in _populate_target_directory each into a dedicated helper function and conditionally call these in init. Also can init be module-private?

Copy link
Contributor Author

@nnarayen nnarayen Feb 5, 2025

Choose a reason for hiding this comment

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

Moved to dedicated helpers! init will go away once I port the tests to use init_directory with the same coverage, but the new entrypoint cannot be package private since cli depends on it

target_directory_path: Optional[str] = None,
template: str = "custom",
populate_dirs: bool = True,
config: TrussConfig, target_directory: str, python_dx: bool = False
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Similar to a comment below, this function is used in exactly one location and never has alternative parameters for template or populate_dirs. I removed those arguments, and instead passed in python_dx which will be derived from the CLI.

else:
target_directory_path_typed = Path(target_directory_path)
target_directory_path_typed.mkdir(parents=True, exist_ok=True)
target_directory_path = Path(target_directory)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

target_directory will always exist, so we no longer need this branch

# Write config
with (target_directory_path_typed / CONFIG_FILE).open("w") as config_file:
yaml.dump(config.to_dict(verbose=False), config_file)
# Hack: We want to place the user provided model name into generated code. Until
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I really don't love this, but didn't want to overengineer a way to get the user provided model name into the generated file


class Model(baseten.ModelBase):
# Configure resources for your model here.
remote_config: baseten.RemoteConfig = baseten.RemoteConfig(name="{{ MODEL_NAME }}")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This template string is replaced at init time, very open to other suggestions here

See https://truss.baseten.co/quickstart for more.
"""

import truss_chains as baseten
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this warrants a bigger discussion: how to consolidate (brand/name-wise) chains, truss and baseten.

Without having a clear vision and general buy-in, it seems better to just stick to the established pattern of as chains for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From this discussion, are you ok if we move forward with baseten for now? It's not a one way door, and I do agree that there's value in branding this differently than chains (even if that specific branding changes over time)


return target_directory_path_typed


def init_directory(
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this fucntion be merged with _populate_target_directory?

)

scaf = TrussHandle(target_directory_path)
scaf = TrussHandle(target_path)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think in other places this is called th (a bit short, but it seems a widespread convention and ok in that case) - mind adjusting it?


return target_directory_path_typed


def init_directory(
Copy link
Contributor

Choose a reason for hiding this comment

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

Or a better structuring would be to put the two if/else blocks in _populate_target_directory each into a dedicated helper function and conditionally call these in init. Also can init be module-private?

@squidarth
Copy link
Collaborator

are there other places we call this "python dx"? I know we're using that phrase internally but I think it's a little confusing externally. The current DX we're using is still Python-based.

What about something like --python-configuration

@nnarayen
Copy link
Contributor Author

nnarayen commented Feb 5, 2025

What about something like --python-configuration

Don't feel too strongly here, happy to move to --python-configuration if we think that'll be more clear! I just wanted to avoid something like --v2-configuration since that doesn't really convey much

@nnarayen nnarayen merged commit f7be3e0 into main Feb 5, 2025
5 checks passed
@nnarayen nnarayen deleted the nikhil/python-dx-truss-init branch February 5, 2025 16:55
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