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

make conda recipe data-loading stricter #1349

Merged
merged 5 commits into from
Jun 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions conda/recipes/dask-cuda/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ build:
script:
- {{ PYTHON }} -m pip install . -vv
entry_points:
{% for e in data.get("project", {}).get("scripts", {}).items() %}
- {{ e|join(" = ") }}
{% for entrypoint in data["project"]["scripts"] %}
- {{ entrypoint ~ ' = ' ~ data["project"]["scripts"][entrypoint] }}
Copy link
Member Author

Choose a reason for hiding this comment

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

I know this one looks a little weird. I can explain.

Switching from this

{% for e in data.get("project", {}).get("scripts", {}).items() %}

to this

{% for e in data["project"]["scripts"].items() %}

results in an error like this:

  File "/__w/dask-cuda/dask-cuda/conda/recipes/dask-cuda/meta.yaml", line 24, in top-level template code
    {% for e in data["project"]["scripts"].items() %}
TypeError: 'NoneType' object is not callable

(build link)

It seems that calling dictionary methods like .items() or .iteritems() isn't supported... maybe conda-build overrides .get() or __getattr__ or getattr(), or maybe that's something Jinja2 is doing.

BUT... this pattern where you for-iterate over keys, and then use those to subset the list, totally works 😁

And it does come with a bit more safety. I tried removing the [project.scripts] table in pyproject.toml completely. On branch-24.08, that results in the recipe silently building "successfully" without those entrypoints defined.

On this branch, it results in an informative error.

Error: Failed to render jinja template in /Users/jlamb/repos/dask-cuda/conda/recipes/dask-cuda/meta.yaml:
'dict object' has no attribute 'scripts'

See "How I tested this" in the PR description for details on how I tested this.

Copy link
Contributor

Choose a reason for hiding this comment

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

"I can explain, I promise!" is always a good thing to write on a diff. 😉 I think this is totally fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

haha yeah, thanks 😂

{% endfor %}

requirements:
Expand All @@ -32,7 +32,7 @@ requirements:
- rapids-build-backend>=0.3.0,<0.4.0.dev0
run:
- python
{% for r in data.get("project", {}).get("dependencies", []) %}
{% for r in data["project"]["dependencies"] %}
- {{ r }}
{% endfor %}

Expand All @@ -41,18 +41,18 @@ test:
- dask_cuda
commands:
- dask cuda --help
{% for e in data.get("project", {}).get("scripts", {}).keys() %}
- {{ e }} --help
- {{ e|replace("-", " ") }} --help
{% for entrypoint in data["project"]["scripts"] %}
- {{ entrypoint }} --help
- {{ entrypoint|replace("-", " ") }} --help
{% endfor %}

about:
home: {{ data.get("project", {}).get("urls", {}).get("Homepage", "") }}
license: {{ data.get("project", {}).get("license", {}).get("text", "") }}
home: {{ data["project"]["urls"]["Homepage"] }}
license: {{ data["project"]["license"]["text"] }}
license_file:
{% for e in data.get("tool", {}).get("setuptools", {}).get("license-files", []) %}
{% for e in data["tool"]["setuptools"]["license-files"] %}
- ../../../{{ e }}
{% endfor %}
summary: {{ data.get("project", {}).get("description", "") }}
dev_url: {{ data.get("project", {}).get("urls", {}).get("Source", "") }}
doc_url: {{ data.get("project", {}).get("urls", {}).get("Documentation", "") }}
summary: {{ data["project"]["description"] }}
dev_url: {{ data["project"]["urls"]["Source"] }}
doc_url: {{ data["project"]["urls"]["Documentation"] }}
Loading