From df3848dd98d51c8aabbdad6adfcb6bfba75c1ea7 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Fri, 18 Oct 2024 13:01:03 -0500 Subject: [PATCH] allow conda_env_name to be None, remove spaces in requirements, remove issue page link --- .../_rapids_dependency_file_generator.py | 23 ++++++++++--------- .../overlapping-deps/dependencies.yaml | 4 ++-- .../test_rapids_dependency_file_generator.py | 7 ++---- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/rapids_dependency_file_generator/_rapids_dependency_file_generator.py b/src/rapids_dependency_file_generator/_rapids_dependency_file_generator.py index 2d19224..a54cf9b 100644 --- a/src/rapids_dependency_file_generator/_rapids_dependency_file_generator.py +++ b/src/rapids_dependency_file_generator/_rapids_dependency_file_generator.py @@ -96,7 +96,7 @@ def grid(gridspec: dict[str, list[str]]) -> Generator[dict[str, str], None, None def make_dependency_file( *, file_type: _config.Output, - conda_env_name: str, + conda_env_name: typing.Union[str, None], file_name: str, config_file: os.PathLike, output_dir: os.PathLike, @@ -110,8 +110,9 @@ def make_dependency_file( ---------- file_type : Output An Output value used to determine the file type. - conda_env_name : str + conda_env_name : str | None Name to put in the 'name: ' field when generating conda environment YAML files. + If ``None``, the generated cond environment file will not have a 'name:' entry. Only used when ``file_type`` is CONDA. file_name : str Name of a file in ``output_dir`` to read in. @@ -141,13 +142,13 @@ def make_dependency_file( """ ) if file_type == _config.Output.CONDA: - file_contents += yaml.dump( - { - "name": conda_env_name, - "channels": conda_channels, - "dependencies": dependencies, - } - ) + env_dict = { + "channels": conda_channels, + "dependencies": dependencies, + } + if conda_env_name is not None: + env_dict["name"] = conda_env_name + file_contents += yaml.dump(env_dict) elif file_type == _config.Output.REQUIREMENTS: for dep in dependencies: if isinstance(dep, dict): @@ -515,13 +516,13 @@ def make_dependency_files( # err_msg = ( "Exactly 1 output type should be provided when asking rapids-dependency-file-generator to write to stdout. " - "If you see this, you've found a bug. Please report it at https://github.com/rapidsai/dependency-file-generator/issues." + "If you see this, you've found a bug. Please report it." ) assert output is not None, err_msg contents = make_dependency_file( file_type=output.pop(), - conda_env_name="rapids-dfg-combined", + conda_env_name=None, file_name="ignored-because-multiple-pyproject-files-are-not-supported", config_file=parsed_config.path, output_dir=parsed_config.path, diff --git a/tests/examples/overlapping-deps/dependencies.yaml b/tests/examples/overlapping-deps/dependencies.yaml index 0b25c02..2d8928c 100644 --- a/tests/examples/overlapping-deps/dependencies.yaml +++ b/tests/examples/overlapping-deps/dependencies.yaml @@ -44,7 +44,7 @@ dependencies: packages: - pip - pip: - - numpy >=2.0 + - numpy>=2.0 depends_on_pandas: common: - output_types: [conda, requirements, pyproject] @@ -67,7 +67,7 @@ dependencies: # test that pip dependencies don't have duplicates - pip: # intentionally not in alphabetical order - - numpy >=2.0 + - numpy>=2.0 - folium rapids_build_skbuild: common: diff --git a/tests/test_rapids_dependency_file_generator.py b/tests/test_rapids_dependency_file_generator.py index f9bcbb4..9bb693e 100644 --- a/tests/test_rapids_dependency_file_generator.py +++ b/tests/test_rapids_dependency_file_generator.py @@ -179,14 +179,11 @@ def test_make_dependency_files_conda_to_stdout_with_multiple_file_keys_works(cap env_dict = yaml.safe_load(captured_stdout) # should only have the expected keys - assert sorted(env_dict.keys()) == ["channels", "dependencies", "name"] + assert sorted(env_dict.keys()) == ["channels", "dependencies"] # should use preserve the channels from dependencies.yaml, in the order they were supplied assert env_dict["channels"] == ["rapidsai", "conda-forge"] - # should use the hard-coded env name - assert env_dict["name"] == "rapids-dfg-combined" - # dependencies list should: # # * be sorted alphabetically (other than "pip:" list at the end) @@ -201,7 +198,7 @@ def test_make_dependency_files_conda_to_stdout_with_multiple_file_keys_works(cap "scikit-learn>=1.5", {"pip": [ "folium", - "numpy >=2.0", + "numpy>=2.0", ]} ]