rapidsai / dependency-file-generator

https://pypi.org/project/rapids-dependency-file-generator/
Apache License 2.0
15 stars 13 forks source link

fix: fix type hints for _parse_requirement() #92

Closed jameslamb closed 3 months ago

jameslamb commented 3 months ago

Contributes to #87.

Fixes this error from mypy:

src/rapids_dependency_file_generator/_config.py:185: error: Argument "pip" to "PipRequirements" has incompatible type "str"; expected "list[str]"  [arg-type]

_parse_requirement() should never see a dictionary like {"pip": "package"}, because the dependencies.yaml requires that pip dependencies be an array.

https://github.com/rapidsai/dependency-file-generator/blob/a8660f41117a2015daf9cf0ca2a64b7ad9b71042/src/rapids_dependency_file_generator/schema.json#L154-L161

https://github.com/rapidsai/dependency-file-generator/blob/a8660f41117a2015daf9cf0ca2a64b7ad9b71042/src/rapids_dependency_file_generator/schema.json#L146-L147

This fixes a type hint and a test case suggesting that possibility, and adds a new test case to ensure rapids-dependency-file-generator rejects lists like this:

dependencies:
  build:
    common:
      - output_types: [conda]
        packages:
          - beep-boop=1.2.3
          - pip
          - pip: pandas

How I tested this

Saw the new test case I added get picked up in the output of pytest -v.

Saw `rapids-dependency-file-generator raise exactly the expected error on it.

rapids-dependency-file-generator \
    --config ./tests/examples/invalid/pip-no-list/dependencies.yaml
The provided dependency file contains schema errors.

        'pandas' is not of type 'array'

        Failed validating 'type' in schema[1]['properties']['pip']:
            {'items': {'$ref': '#/$defs/requirement'},
             'minItems': 1,
             'type': 'array'}

        On instance['pip']:
            'pandas' 

...
RuntimeError: The provided dependencies data is invalid.
GPUtester commented 3 months ago

:tada: This PR is included in version 1.13.7 :tada:

The release is available on:

Your semantic-release bot :package::rocket: