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

Use explicit path in "recipe not found" exception #2249

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

mgorny
Copy link
Contributor

@mgorny mgorny commented Feb 25, 2025

Checklist

  • Added a news entry
  • Regenerated schema JSON if schema altered (python conda_smithy/schema.py)

Replace the "Feedstock has no ..." error message with a more clear "recipe not found" with explicit path, and a suggestion to pass the recipe subdirectory. This should help people like me, who keep forgetting that in top feedstock directory you need to run:

conda smithy lint recipe/

instead of just:

conda smithy lint

and get the message:

OSError: Feedstock has no recipe/meta.yaml

which is confusing since clearly there is a recipe/meta.yaml in the current directory. Unless you're using v1 recipes, then you get even more confused why it tries to use a v0 recipe file.

Replace the "Feedstock has no ..." error message with a more clear
"recipe not found" with explicit path, and a suggestion to pass
the `recipe` subdirectory.  This should help people like me, who keep
forgetting that in top feedstock directory you need to run:

    conda smithy lint recipe/

instead of just:

    conda smithy lint

and get the message:

    OSError: Feedstock has no recipe/meta.yaml

which is confusing since clearly there is a `recipe/meta.yaml`
in the current directory.  Unless you're using v1 recipes, then you get
even more confused why it tries to use a v0 recipe file.
@mgorny mgorny marked this pull request as ready for review February 25, 2025 16:38
@mgorny mgorny requested a review from a team as a code owner February 25, 2025 16:38
@@ -743,7 +743,7 @@ def main(

if not os.path.exists(recipe_file):
raise OSError(
f"Feedstock has no recipe/{os.path.basename(recipe_file)}"
f'Recipe not found: {recipe_file}; did you pass the "recipe" subdirectory?'
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 there's a setting for recipe, so this shouldn't be hardcoded.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, "kinda". If you aren't passing the correct directory, then we can't get the setting — and I dare say changing the name is rare enough that "recipe" will be a good hint most of the time. Perhaps it would work if I removed the quotes:

Suggested change
f'Recipe not found: {recipe_file}; did you pass the "recipe" subdirectory?'
f'Recipe not found: {recipe_file}; did you pass the recipe subdirectory?'

?

@jaimergp
Copy link
Member

Thanks! Added a comment, but I wonder if we could a good default so that CLI path is indeed not necessary though.

Co-authored-by: jaimergp <jaimergp@users.noreply.github.com>
@mgorny
Copy link
Contributor Author

mgorny commented Feb 25, 2025

I wonder if we could a good default so that CLI path is indeed not necessary though.

Make it work both with top feedstock directory and the subdirectory? I suppose that would make sense, and I can't see an obvious case where it would backfire.

@mgorny
Copy link
Contributor Author

mgorny commented Feb 25, 2025

So, how about this?

  1. Look for meta.yaml + recipe.yaml in the specified directory per the current logic.
  2. Otherwise, look for conda-forge.yml in the specified directory, and use its recipe path.
  3. Otherwise, look for recipe subdirectory with one of the two files.

mgorny added a commit to mgorny/conda-smithy that referenced this pull request Feb 25, 2025
Extend the default behavior of `conda-smithy lint` to detect
if a feedstock directory has been passed in place of the recipe
directory (e.g. by running it with no paths specified), and handle
the paths appropriately.

The new logic covers three possible scenarios:

1. If `--feedstock-directory` is passed, everything works as before.

2. If not, the specified directory is checked for `meta.yaml`
   and `recipe.yaml`, also as before.

3. If neither exists, the specified directory is checked for
   `conda-forge.yml`.  If it exists, it set to be the feedstock
   directory, and the file is parsed to determine the correct recipe
   subdirectory.

This is primarily meant to address my common mistake of running:

    conda smithy lint

in the feedstock directory, which can lead to pretty confusing error
messages, particularly if the feedstock is using v1 recipes, and smithy
says it can't find `recipe/meta.yaml` -- and you start wondering whether
you've made a typo in `conda-forge.yml` or what.

This is an alternative to conda-forge#2249.
@mgorny
Copy link
Contributor Author

mgorny commented Feb 26, 2025

The alternative approach was implemented in #2250.

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