Skip to content

Commit

Permalink
allow conda_env_name to be None, remove spaces in requirements, remov…
Browse files Browse the repository at this point in the history
…e issue page link
  • Loading branch information
jameslamb committed Oct 18, 2024
1 parent cb00f33 commit df3848d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions tests/examples/overlapping-deps/dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ dependencies:
packages:
- pip
- pip:
- numpy >=2.0
- numpy>=2.0
depends_on_pandas:
common:
- output_types: [conda, requirements, pyproject]
Expand All @@ -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:
Expand Down
7 changes: 2 additions & 5 deletions tests/test_rapids_dependency_file_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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",
]}
]

Expand Down

0 comments on commit df3848d

Please sign in to comment.