regro / cf-scripts

Flagship repo for cf-regro-autotick-bot
Other
53 stars 75 forks source link

parser fails on edge case with `-` in set statement #3211

Open beckermr opened 12 hours ago

beckermr commented 12 hours ago

This recipe has caused a parsing failure:

{% set version = "7.0.0" -%}
{% set python_min = python_min | default("3.11") -%}
{% set min_py = python_min | replace('.', '') | int -%}
{% set py = py | default(min_py) -%}

package:
  name: astropy-base
  version: {{ version }}

source:
  url: https://pypi.org/packages/source/a/astropy/astropy-{{ version }}.tar.gz
  sha256: e92d7c9fee86eb3df8714e5dd41bbf9f163d343e1a183d95bf6bd09e4313c940

build:
  number: 0
  {% if py < min_py %}
  skip: true
  {% endif %}
  entry_points:
    - fits2bitmap = astropy.visualization.scripts.fits2bitmap:main
    - fitscheck = astropy.io.fits.scripts.fitscheck:main
    - fitsdiff = astropy.io.fits.scripts.fitsdiff:main
    - fitsheader = astropy.io.fits.scripts.fitsheader:main
    - fitsinfo = astropy.io.fits.scripts.fitsinfo:main
    - samp_hub = astropy.samp.hub_script:hub_script
    - volint = astropy.io.votable.volint:main
    - wcslint = astropy.wcs.wcslint:main

requirements:
  build:
    - python                                 # [build_platform != target_platform]
    - cross-python_{{ target_platform }}     # [build_platform != target_platform]
    - cython >=3.0.0,<3.1.0                  # [build_platform != target_platform]
    - numpy                                  # [build_platform != target_platform]
    - {{ compiler('c') }}
    - {{ stdlib("c") }}
  host:
    - python
    - pip
    - setuptools
    - jinja2 >=3
    - cython >=3.0.0,<3.1.0
    - setuptools_scm >=6.2
    - extension-helpers =1
    - numpy
  run:
    - python
    - numpy >=1.23
    - pyerfa >=2.0.1.1
    - astropy-iers-data >=0.2024.10.28.0.34.7
    - importlib-metadata
    - pyyaml >=3.13
    - packaging >=19.0
    - scipy >=1.8
  run_constrained:
    # We must prevent installing old astropy and new astropy-base together
    - astropy >=7.0.0

test:
  requires:
    - pytest-astropy
  commands:
    - fits2bitmap --help
    - fitscheck --help
    - fitsdiff --help
    - fitsheader --help
    - fitsinfo --help
    - samp_hub --help
    - volint --help
    - wcslint --help
  imports:
    - astropy

outputs:
  - name: astropy-base
    build:
      script: {{ PYTHON }} -m pip install . -vv --no-deps --no-build-isolation

# build this exactly once, on the oldest supported python, to avoid migration issues
{% if py==min_py and linux64 %}
  - name: astropy
    build:
      noarch: python
    requirements:
      host:
        - python {{ python_min }}
      run:
        - python >={{ python_min }}
        - {{ pin_subpackage('astropy-base', max_pin="x.x.x") }}
        - matplotlib-base >=3.5.0,!=3.5.2
        - certifi
        # We also need numpy from dask[array] but we are already going to install that.
        - dask-core >=2022.8.1
        - h5py
        - pyarrow >=10.0.1
        - beautifulsoup4
        - html5lib
        - bleach
        - pandas >=2.0
        - sortedcontainers
        - pytz
        - jplephem
        - mpmath
        - bottleneck
        - fsspec >=2023.4.0
        # fsspec optional deps
        - aiohttp
        - s3fs
    test:
      requires:
        - python {{ python_min }}
        - pytest-astropy
      commands:
        - pip check
        - fits2bitmap --help
        - fitscheck --help
        - fitsdiff --help
        - fitsheader --help
        - fitsinfo --help
        - samp_hub --help
        - volint --help
        - wcslint --help
        - pytest --pyargs astropy
      imports:
        - astropy
{% endif %}

about:
  home: http://www.astropy.org/
  license: BSD-3-Clause
  license_file: LICENSE.rst
  summary: Community-developed Python Library for Astronomy
  description: |
    The Astropy Project is a community effort to develop a single package for
    Astronomy in Python. It contains core functionality and common tools
    needed for performing astronomy and astrophysics research with Python.
  doc_url: http://docs.astropy.org/en/stable/
  dev_url: https://github.com/astropy/astropy

extra:
  feedstock-name: astropy
  recipe-maintainers:
    - astrofrog
    - mwcraig
    - bsipocz
    - Cadair
astrofrog commented 12 hours ago

The issue is the - in the first line. The following fails:

from conda_forge_tick.recipe_parser._parser import CondaMetaYAML

meta1 = """
{% set version = "7.0.0" -%}
{% set python_min = python_min | default("3.11") -%}
"""

CondaMetaYAML(meta1)

with:

Traceback (most recent call last):
  File "/home/tom/tmp/reproduce.py", line 8, in <module>
    CondaMetaYAML(meta1)
  File "/home/tom/tmp/cf-scripts/conda_forge_tick/recipe_parser/_parser.py", line 551, in __init__
    v, e = _parse_jinja2_variables(meta_yaml)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tom/tmp/cf-scripts/conda_forge_tick/recipe_parser/_parser.py", line 110, in _parse_jinja2_variables
    and _line_is_only_selector(all_nodes[i + 1].nodes[0].data.strip())
                               ^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Assign' object has no attribute 'nodes'. Did you mean: 'node'?

The following works:

from conda_forge_tick.recipe_parser._parser import CondaMetaYAML

meta1 = """
{% set version = "7.0.0" %}
{% set python_min = python_min | default("3.11") -%}
"""

CondaMetaYAML(meta1)
astrofrog commented 12 hours ago

Interestingly this works:

from conda_forge_tick.recipe_parser._parser import CondaMetaYAML

meta1 = """
{% set version = "7.0.0" -%}

package:
  name: astropy-base
  version: {{ version }}

{% set python_min = python_min | default("3.11") -%}
"""

CondaMetaYAML(meta1)

(including the -)

beckermr commented 12 hours ago

The - removes newlines and so I suspect shifting elements onto the same line is the issue. TBH there is no reason to include the dashes at all for a single line set statement and the fix to the parser here is probably just to remove those before parsing.