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

BUG: 'PYTHON' is undefined for multi-output builds if some outputs are generic #5424

Open
2 tasks done
ytausch opened this issue Jul 25, 2024 · 0 comments
Open
2 tasks done
Labels
type::bug describes erroneous operation, use severity::* to classify the type

Comments

@ytausch
Copy link
Contributor

ytausch commented Jul 25, 2024

Checklist

  • I added a descriptive title
  • I searched open reports and couldn't find a duplicate

What happened?

Consider the following recipe:

{% set version = "0.14.0" %}
{% set min_python = "python >=3.9" %}

package:
  name: ariadne-codegen-split
  version: {{ version }}

source:
  - folder: dist
    url: https://pypi.io/packages/source/a/ariadne-codegen/ariadne_codegen-{{ version }}.tar.gz
    sha256: d5b15470195c3858b88a2bae855b5c04602ffae40228077b6cfb26a57d3f14f6
  - folder: src
    url: https://github.com/mirumee/ariadne-codegen/archive/refs/tags/{{ version }}.tar.gz
    sha256: 86d79970c8260fa8292e40ada695babcf47560d6ac599611d039daedaae8543c

build:
  noarch: python
  number: 0

requirements:
  host:
    - {{ min_python }}
  run:
    - {{ min_python }}

outputs:
  - name: ariadne-codegen
    build:
      noarch: python
      script: cd dist && {{ PYTHON }} -m pip install . -vv --no-deps --no-build-isolation
      entry_points:
        - ariadne-codegen = ariadne_codegen.main:main
    requirements:
      host:
        - {{ min_python }}
        - hatchling
        - pip
      run:
        - {{ min_python }}
        - autoflake
        - black
        - click >=8.1,<9.0
        - graphql-core >=3.2.0,<3.3
        - httpx >=0.23,<1.0
        - isort
        - pydantic >=2.0.0,<3.0.0
        - toml >=0.10,<1.0
      run_constrained:
        - websockets >=11.0,<12.0
    test:
      requires:
        - pip
      imports:
        - ariadne_codegen
      commands:
        - pip check
        - ariadne-codegen --help

  - name: ariadne-codegen-with-websockets
    build:
      noarch: generic
    requirements:
      run:
        - {{ pin_subpackage("ariadne-codegen", exact=True) }}
        - websockets

I don't see why this recipe should not be able to be built.

However, conda build fails with Error: Failed to render jinja template in /home/conda/recipe_root/meta.yaml: 'PYTHON' is undefined

Apparently, this happens because the entire jinja template is rendered for every output but PYTHON is only set if the currently-processed output has Python as a host dependency.

I think a better behavior would be to strip out details about other outputs including the variables they reference before rendering with patched metadata dependent on individual outputs.

Traceback (most recent call last):
  File "/Users/ytausch/autotickbot/conda-build/conda_build/metadata.py", line 2010, in _get_contents
    rendered = template.render(environment=env)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniforge/base/envs/cf-scripts/envs/cf-scripts/lib/python3.11/site-packages/jinja2/environment.py", line 1301, in render
    self.environment.handle_exception()
  File "/opt/homebrew/Caskroom/miniforge/base/envs/cf-scripts/envs/cf-scripts/lib/python3.11/site-packages/jinja2/environment.py", line 936, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 7, in top-level template code
jinja2.exceptions.UndefinedError: 'PYTHON' is undefined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/ytausch/autotickbot/conda-build/conda_build/build.py", line 3709, in build_tree
    packages_from_this = build(
                         ^^^^^^
  File "/Users/ytausch/autotickbot/conda-build/conda_build/build.py", line 2335, in build
    output_metas = expand_outputs([(m, need_source_download, need_reparse_in_env)])
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ytausch/autotickbot/conda-build/conda_build/render.py", line 916, in expand_outputs
    for output_dict, m in deepcopy(_m).get_output_metadata_set(
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ytausch/autotickbot/conda-build/conda_build/metadata.py", line 2658, in get_output_metadata_set
    conda_packages = finalize_outputs_pass(
                     ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ytausch/autotickbot/conda-build/conda_build/metadata.py", line 1025, in finalize_outputs_pass
    fm = finalize_metadata(
         ^^^^^^^^^^^^^^^^^^
  File "/Users/ytausch/autotickbot/conda-build/conda_build/render.py", line 649, in finalize_metadata
    m = parent_metadata.get_output_metadata(m.get_rendered_output(m.name()))
                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ytausch/autotickbot/conda-build/conda_build/metadata.py", line 2743, in get_rendered_output
    for output_ in self.get_rendered_outputs_section(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ytausch/autotickbot/conda-build/conda_build/metadata.py", line 2725, in get_rendered_outputs_section
    self._get_contents(
  File "/Users/ytausch/autotickbot/conda-build/conda_build/metadata.py", line 2020, in _get_contents
    raise CondaBuildUserError(
conda_build.exceptions.CondaBuildUserError: Failed to render jinja template in :
'PYTHON' is undefined

Conda Info

No response

Conda Config

No response

Conda list

No response

Additional Context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type::bug describes erroneous operation, use severity::* to classify the type
Projects
Status: 🆕 New
Development

No branches or pull requests

1 participant