conda / conda-build

Commands and tools for building conda packages
https://docs.conda.io/projects/conda-build/
Other
383 stars 423 forks source link

Missing Jinja variables in lists in meta.yaml result in "'NoneType' is not iterable" exception #3251

Open kuepe-sl opened 6 years ago

kuepe-sl commented 6 years ago

I have a few Jinja variables in my meta.yaml, usually set via environment variables.
However when I once forgot to set one of the variables, conda-build just threw a TypeError exception instead of telling me about an undefined Jinja variable.

Actual Behavior

$ conda-build recipe/ --croot ./builds --no-test
No numpy version specified in conda_build_config.yaml.  Falling back to default numpy value of 1.11
WARNING:conda_build.metadata:No numpy version specified in conda_build_config.yaml.  Falling back to default numpy value of 1.11
Traceback (most recent call last):
  File "/home/kuepe/miniconda3/bin/conda-build", line 11, in <module>
    sys.exit(main())
  File "/home/kuepe/miniconda3/lib/python3.6/site-packages/conda_build/cli/main_build.py", line 439, in main
    execute(sys.argv[1:])
  File "/home/kuepe/miniconda3/lib/python3.6/site-packages/conda_build/cli/main_build.py", line 430, in execute
    verify=args.verify, variants=args.variants)
  File "/home/kuepe/miniconda3/lib/python3.6/site-packages/conda_build/api.py", line 201, in build
    notest=notest, need_source_download=need_source_download, variants=variants)
  File "/home/kuepe/miniconda3/lib/python3.6/site-packages/conda_build/build.py", line 2253, in build_tree
    bypass_env_check=True)
  File "/home/kuepe/miniconda3/lib/python3.6/site-packages/conda_build/render.py", line 737, in render_recipe
    m = MetaData(recipe_dir, config=config)
  File "/home/kuepe/miniconda3/lib/python3.6/site-packages/conda_build/metadata.py", line 853, in __init__
    self.parse_again(permit_undefined_jinja=True, allow_no_other_outputs=True)
  File "/home/kuepe/miniconda3/lib/python3.6/site-packages/conda_build/metadata.py", line 950, in parse_again
    self.validate_features()
  File "/home/kuepe/miniconda3/lib/python3.6/site-packages/conda_build/metadata.py", line 1704, in validate_features
    if any('-' in feature for feature in ensure_list(self.get_value('build/features'))):
  File "/home/kuepe/miniconda3/lib/python3.6/site-packages/conda_build/metadata.py", line 1704, in <genexpr>
    if any('-' in feature for feature in ensure_list(self.get_value('build/features'))):
TypeError: argument of type 'NoneType' is not iterable

Expected Behavior

It should throw an error (or at least a warning) that there is an undefined Jinja variable.

Steps to Reproduce

  1. Create a meta.yaml like this
    package:
    name: test-jinja
    version: 1
    build:
    features:
        - {{ ENV_VAR }}
  2. run conda-build on the recipe folder with the meta.yaml above.
Output of conda info
     active environment : None
       user config file : /home/kuepe/.condarc
 populated config files : /home/kuepe/.condarc
          conda version : 4.5.11
    conda-build version : 3.16.2
         python version : 3.6.6.final.0
       base environment : /home/kuepe/miniconda3  (writable)
           channel URLs : https://conda.anaconda.org/conda-forge/linux-64
                          https://conda.anaconda.org/conda-forge/noarch
                          https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/free/linux-64
                          https://repo.anaconda.com/pkgs/free/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
                          https://repo.anaconda.com/pkgs/pro/linux-64
                          https://repo.anaconda.com/pkgs/pro/noarch
          package cache : /home/kuepe/miniconda3/pkgs
                          /home/kuepe/.conda/pkgs
       envs directories : /home/kuepe/miniconda3/envs
                          /home/kuepe/.conda/envs
               platform : linux-64
             user-agent : conda/4.5.11 requests/2.20.0 CPython/3.6.6 Linux/4.4.0-101-generic ubuntu/16.04 glibc/2.23
                UID:GID : 1000:1000
             netrc file : None
           offline mode : False
github-actions[bot] commented 1 year ago

Hi there, thank you for your contribution!

This issue has been automatically marked as stale because it has not had recent activity. It will be closed automatically if no further activity occurs.

If you would like this issue to remain open please:

  1. Verify that you can still reproduce the issue at hand
  2. Comment that the issue is still reproducible and include:
    • What OS and version you reproduced the issue on
    • What steps you followed to reproduce the issue

NOTE: If this issue was closed prematurely, please leave a comment.

Thanks!

kuepe-sl commented 1 year ago

Stil happening with current Conda/Conda Build:

$ conda build recipe/
No numpy version specified in conda_build_config.yaml.  Falling back to default numpy value of 1.16
WARNING:conda_build.metadata:No numpy version specified in conda_build_config.yaml.  Falling back to default numpy value of 1.16
Traceback (most recent call last):
  File "/home/user/miniconda3/bin/conda-build", line 11, in <module>
    sys.exit(main())
  File "/home/user/miniconda3/lib/python3.8/site-packages/conda_build/cli/main_build.py", line 495, in main
    execute(sys.argv[1:])
  File "/home/user/miniconda3/lib/python3.8/site-packages/conda_build/cli/main_build.py", line 475, in execute
    outputs = api.build(
  File "/home/user/miniconda3/lib/python3.8/site-packages/conda_build/api.py", line 180, in build
    return build_tree(
  File "/home/user/miniconda3/lib/python3.8/site-packages/conda_build/build.py", line 3076, in build_tree
    metadata_tuples = render_recipe(recipe, config=cfg, variants=variants,
  File "/home/user/miniconda3/lib/python3.8/site-packages/conda_build/render.py", line 817, in render_recipe
    m = MetaData(recipe_dir, config=config)
  File "/home/user/miniconda3/lib/python3.8/site-packages/conda_build/metadata.py", line 1075, in __init__
    self.parse_again(permit_undefined_jinja=True, allow_no_other_outputs=True)
  File "/home/user/miniconda3/lib/python3.8/site-packages/conda_build/metadata.py", line 1207, in parse_again
    self.validate_features()
  File "/home/user/miniconda3/lib/python3.8/site-packages/conda_build/metadata.py", line 2138, in validate_features
    if any(
  File "/home/user/miniconda3/lib/python3.8/site-packages/conda_build/metadata.py", line 2139, in <genexpr>
    "-" in feature for feature in ensure_list(self.get_value("build/features"))
TypeError: argument of type 'NoneType' is not iterable
$ conda info

     active environment : base
    active env location : /home/user/miniconda3
            shell level : 1
       user config file : /home/user/.condarc
 populated config files : /home/user/.condarc
          conda version : 22.11.1
    conda-build version : 3.23.3
         python version : 3.8.13.final.0
       virtual packages : __archspec=1=x86_64
                          __glibc=2.31=0
                          __linux=5.15.0=0
                          __unix=0=0
       base environment : /home/user/miniconda3  (writable)
      conda av data dir : /home/user/miniconda3/etc/conda
  conda av metadata url : None
           channel URLs : https://conda.anaconda.org/conda-forge/linux-64
                          https://conda.anaconda.org/conda-forge/noarch
                          https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /home/user/miniconda3/pkgs
                          /home/user/.conda/pkgs
       envs directories : /home/user/miniconda3/envs
                          /home/user/.conda/envs
               platform : linux-64
             user-agent : conda/22.11.1 requests/2.28.1 CPython/3.8.13 Linux/5.15.0-52-generic ubuntu/20.04.5 glibc/2.31
                UID:GID : 1000:1000
             netrc file : /home/user/.netrc
           offline mode : False