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

Improved recipe initialization UX #9158

Merged
merged 8 commits into from
Apr 10, 2023
Merged

Improved recipe initialization UX #9158

merged 8 commits into from
Apr 10, 2023

Conversation

cicdw
Copy link
Member

@cicdw cicdw commented Apr 8, 2023

This PR introduces a new interactive experience for recipes - all recipes now ship with required_inputs that, if not provided, are prompted for whenever initializing that recipe. These interactive prompts can be avoided by passing the required fields with the new --field flag on project init. Documentation has also been updated to reflect this.

Example

image

produces:
# File for configuring project / deployment build, push and pull steps

# Generic metadata about this project
name: hello-projects
prefect-version: 2.10.2+20.gd7df0187c

# build section allows you to manage and build docker images
build:
- prefect_docker.projects.steps.build_docker_image:
    requires: prefect-docker>0.1.0
    image_name: my-image
    tag: my-tag
    dockerfile: auto

# push section allows you to manage if and how this project is uploaded to remote locations
push: null

# pull section allows you to provide instructions for cloning this project in remote locations
pull:
- prefect.projects.steps.set_working_directory:
    directory: /opt/prefect/hello-projects

Checklist

  • This pull request references any related issue by including "closes <link to issue>"
    • If no issue exists and your change is not a small fix, please create an issue first.
  • This pull request includes tests or only affects documentation.
  • This pull request includes a label categorizing the change e.g. fix, feature, enhancement, docs.

@cicdw cicdw requested a review from desertaxle April 8, 2023 00:13
@cicdw cicdw requested review from a team as code owners April 8, 2023 00:13
@netlify
Copy link

netlify bot commented Apr 8, 2023

Deploy Preview for prefect-docs-preview ready!

Name Link
🔨 Latest commit 2e54cce
🔍 Latest deploy log https://app.netlify.com/sites/prefect-docs-preview/deploys/64343554cfface0008f6ec47
😎 Deploy Preview https://deploy-preview-9158--prefect-docs-preview.netlify.app/concepts/projects
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@@ -230,6 +233,7 @@ def initialize_project(name: str = None, recipe: str = None) -> List[str]:
elif recipe is None:
recipe = "local"

formatting_kwargs.update(inputs or {})
Copy link
Contributor

Choose a reason for hiding this comment

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

probably a dumb python q - why not set inputs: dict = {} as a default arg?

Copy link
Member Author

Choose a reason for hiding this comment

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

@parkedwards not a dumb question at all, it's a common python gotcha actually; because function definitions are run only once per-import, all default values are set and bound once and only once. This means that if a default is a mutable object, it can begin to leak state between calls of the function. Easy to inspect example:

def f(item, x: list = []):
    x.append(item)
    return x
    
f(1) # returns [1]
f(2) # returns [1, 2]

So to get around that, the best practice is to use None as the default for mutable inputs, and initialize an empty version of the object once per-call (you'll often see things like inputs = inputs or {} at the top of functions for this reason).

Copy link
Contributor

Choose a reason for hiding this comment

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

iiiinteresting, good to know. thanks chris

Copy link
Contributor

@parkedwards parkedwards left a comment

Choose a reason for hiding this comment

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

nice one

Copy link
Contributor

@billpalombi billpalombi left a comment

Choose a reason for hiding this comment

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

Awesome! Again, minor nits.

Co-authored-by: Bill Palombi <bill@prefect.io>
Copy link
Member

@desertaxle desertaxle left a comment

Choose a reason for hiding this comment

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

LGTM!

@cicdw cicdw merged commit e069bd9 into main Apr 10, 2023
@cicdw cicdw deleted the improved-recipe-ux branch April 10, 2023 22:04
asmundo pushed a commit to asmundo/prefect that referenced this pull request May 11, 2023
Co-authored-by: Bill Palombi <bill@prefect.io>
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.

4 participants