Skip to content

Commit

Permalink
Merge pull request #5 from ajschmidt8/rm-both
Browse files Browse the repository at this point in the history
Remove `both` value for `generate` key
  • Loading branch information
ajschmidt8 authored Sep 2, 2022
2 parents 40733fb + d2f89bc commit 54eb3c7
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Here is an example of what the `files` key might look like:
```yaml
files:
all: # used as the prefix for the generated dependency file names
generate: both # which dependency file types to generate. required, can be "both", "env", "requirements", or "none"
generate: [conda, requirements] # which dependency file types to generate. required, can be "conda", "requirements", "none" or a list of non-"none" values
conda_dir: conda/environments # where to put conda environment.yaml files. optional, defaults to "conda/environments"
requirements_dir: python/cudf # where to put requirements.txt files. optional, but recommended. defaults to "python"
matrix: # contains an arbitrary set of key/value pairs to determine which dependency files that should be generated. These values are included in the output filename.
Expand Down
1 change: 0 additions & 1 deletion src/rapids_dependency_file_generator/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class GeneratorTypes(Enum):
CONDA = "conda"
REQUIREMENTS = "requirements"
NONE = "none"
BOTH = "both"

def __str__(self):
return self.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def make_dependency_file(
):
relative_path_to_config_file = os.path.relpath(config_file, output_path)
file_contents = f"""\
# This file was automatically generated by `{cli_name}`. Changes should not be made directly to this file.
# Instead, edit {relative_path_to_config_file} and rerun `{cli_name}`.
# This file is generated by `{cli_name}`.
# To make changes, edit {relative_path_to_config_file} and run `{cli_name}`.
"""
if file_type == str(GeneratorTypes.CONDA):
file_contents += yaml.dump(
Expand All @@ -61,19 +61,27 @@ def make_dependency_file(


def get_file_types_to_generate(generate_value):
if generate_value == str(GeneratorTypes.BOTH):
return [str(GeneratorTypes.CONDA), str(GeneratorTypes.REQUIREMENTS)]
if generate_value == str(GeneratorTypes.NONE):
if not isinstance(generate_value, list):
generate_value = [generate_value]

if generate_value == [str(GeneratorTypes.NONE)]:
return []
if generate_value == str(GeneratorTypes.CONDA) or generate_value == str(
GeneratorTypes.REQUIREMENTS
):
return [generate_value]
raise ValueError(
"'generate' key can only be "
+ ", ".join([f"'{x}'" for x in GeneratorTypes])
+ "."
)

if len(generate_value) > 1 and str(GeneratorTypes.NONE) in generate_value:
raise ValueError("'generate: [none]' cannot be combined with any other values.")

enum_values = [str(x) for x in GeneratorTypes]
non_none_enum_values = [
str(x) for x in GeneratorTypes if not x == GeneratorTypes.NONE
]
for value in generate_value:
if value not in non_none_enum_values:
raise ValueError(
"'generate' key can only be "
+ ", ".join(f"'{x}'" for x in enum_values)
+ f" or a list of the non-'{GeneratorTypes.NONE}' values."
)
return generate_value


def get_filename(file_type, file_prefix, matrix_combo):
Expand Down
44 changes: 41 additions & 3 deletions tests/test_rapids_dependency_file_generator.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import pytest
from unittest import mock
from rapids_dependency_file_generator.rapids_dependency_file_generator import (
dedupe,
make_dependency_file,
should_use_specific_entry,
get_file_types_to_generate,
)
from rapids_dependency_file_generator.constants import cli_name
from rapids_dependency_file_generator.constants import cli_name, GeneratorTypes
import yaml


Expand Down Expand Up @@ -32,8 +34,8 @@ def test_make_dependency_file(mock_relpath):
relpath = "../../config_file.yaml"
mock_relpath.return_value = relpath
header = f"""\
# This file was automatically generated by `{cli_name}`. Changes should not be made directly to this file.
# Instead, edit {relpath} and rerun `{cli_name}`.
# This file is generated by `{cli_name}`.
# To make changes, edit {relpath} and run `{cli_name}`.
"""
env = make_dependency_file(
"conda",
Expand Down Expand Up @@ -80,3 +82,39 @@ def test_should_use_specific_entry():
specific_entry = {"cuda": "11.5", "arch": "x86_64"}
result = should_use_specific_entry(matrix_combo, specific_entry)
assert result == True


def test_get_file_types_to_generate():
result = get_file_types_to_generate(str(GeneratorTypes.NONE))
assert result == []

result = get_file_types_to_generate([str(GeneratorTypes.NONE)])
assert result == []

result = get_file_types_to_generate(str(GeneratorTypes.CONDA))
assert result == [str(GeneratorTypes.CONDA)]

result = get_file_types_to_generate([str(GeneratorTypes.CONDA)])
assert result == [str(GeneratorTypes.CONDA)]

result = get_file_types_to_generate(str(GeneratorTypes.REQUIREMENTS))
assert result == [str(GeneratorTypes.REQUIREMENTS)]

result = get_file_types_to_generate([str(GeneratorTypes.REQUIREMENTS)])
assert result == [str(GeneratorTypes.REQUIREMENTS)]

result = get_file_types_to_generate(
[str(GeneratorTypes.REQUIREMENTS), str(GeneratorTypes.CONDA)]
)
assert result == [str(GeneratorTypes.REQUIREMENTS), str(GeneratorTypes.CONDA)]

with pytest.raises(ValueError):
get_file_types_to_generate("invalid_value")

with pytest.raises(ValueError):
get_file_types_to_generate(["invalid_value"])

with pytest.raises(ValueError):
get_file_types_to_generate(
[str(GeneratorTypes.NONE), str(GeneratorTypes.CONDA)]
)

0 comments on commit 54eb3c7

Please sign in to comment.