Skip to content

Add CLI command pyodide clean recipes#254

Merged
ryanking13 merged 6 commits intopyodide:mainfrom
teddygood:clean-recipes-cli
Nov 12, 2025
Merged

Add CLI command pyodide clean recipes#254
ryanking13 merged 6 commits intopyodide:mainfrom
teddygood:clean-recipes-cli

Conversation

@teddygood
Copy link
Copy Markdown
Contributor

@teddygood teddygood commented Nov 4, 2025

Related to #218. Follow-up to #223.

This PR adds a new CLI command pyodide clean recipes, which makes the clean_recipes helper from the previous PR available through the main Pyodide CLI.

  • Added a new Typer module pyodide clean, and defined the subcommand pyodide clean recipes.
  • When executed, it automatically locates the Pyodide project root from the current working directory.
  • Uses default directories for recipes, build, and install, while respecting user-provided paths and flags.
  • Passes --include-dist and --include-always-tag flags directly to clean_recipes.
  • Registered the command in pyproject.toml so it’s accessible via pyodide clean recipes.
  • Added Typer-based CLI tests to verify:
    • Full cleanup with --include-dist
    • Selective cleanup for specific packages

Next Steps (planned follow-ups)

These will be handled in separate PRs.
Please let me know if there’s anything I could add or improve in this PR.

  • Extend the top-level pyodide clean command to support additional subcommands (e.g., pyodide clean build, pyodide clean cache).
  • Refactor RecipeBuilder to handle cleanup internally, adjust flag names (--include-dist -> --all), and update related documentation.

Copy link
Copy Markdown
Member

@ryanking13 ryanking13 left a comment

Choose a reason for hiding this comment

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

Thanks for working on this @teddygood! I left some comments



@app.command("recipes")
def clean_recipes( # noqa: D401 - Typer generates help text.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is D401 ignored? What does it complain about?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was debating whether to include it in the PR before submitting, but after reading the pyproject.toml just now, I found that the docstring style check isn’t enabled... I'll remove it. Thanks for the review.


from pyodide_build import build_env
from pyodide_build.logger import logger
from pyodide_build.recipe.cleanup import clean_recipes as perform_cleanup
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How about importing recipe and calling recipe.clean_recipes()? This alias looks a bit redundant.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree, that looks better. I'll fix it.

return


def _resolve_paths(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(No action required for this PR)

We may improve this as the default values are hardcoded here and there, not organized. As you mentioned in the next steps, we can probably handle this under the recipe builder class.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I hadn't thought about that. Thanks for pointing it out. I'll make sure to address it in a future refactor.

Comment on lines +55 to +62
include_dist: bool = typer.Option(
False,
help="Remove per-package and global dist directories.",
),
include_always_tag: bool = typer.Option(
False,
help="Include packages tagged with 'always' when no explicit targets are provided.",
),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think providing these parameters to users might not be that useful (sorry that I didn't comment it in the previous PR)

  • I think people would not want to remove the dist directory mostly.
  • Also cleaning up the always packages when it is not specified as a target doesn't seem intuitive either.

So maybe let's remove these parameters for now (install_dir will not be needed either in that case), and set include_dist=False, include_always_tag=False.

Copy link
Copy Markdown
Contributor Author

@teddygood teddygood Nov 5, 2025

Choose a reason for hiding this comment

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

I’ll remove those options and keep the default values set to False.

Copy link
Copy Markdown
Member

@ryanking13 ryanking13 left a comment

Choose a reason for hiding this comment

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

Thanks!

Could you also update the CHANGLEOG?

"""
Remove build artifacts for recipe packages.
"""
recipe_path, build_path, install_path = _resolve_paths(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

install_path is not used anymore, so it can removed from _resolve_paths's return value (and also from the parameter).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for letting me know.

@teddygood
Copy link
Copy Markdown
Contributor Author

Could you also update the CHANGLEOG?

Ok, I’ll check the previous commits and update it.

@ryanking13 ryanking13 merged commit 5c01c9e into pyodide:main Nov 12, 2025
6 checks passed
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.

2 participants