0

On passing -e pipeline.yaml

Traceback (most recent call last):
  File "/Users/Edu/dev/ploomber/src/ploomber/cli/io.py", line 34, in wrapper
    fn(**kwargs)
  File "/Users/Edu/dev/ploomber/src/ploomber/cli/status.py", line 15, in main
    dag, args = parser.load_from_entry_point_arg()
  File "/Users/Edu/dev/ploomber/src/ploomber/cli/parsers.py", line 213, in load_from_entry_point_arg
    entry_point = EntryPoint(self.parse_entry_point_value())
  File "/Users/Edu/dev/ploomber/src/ploomber/entrypoint.py", line 19, in __init__
    self.type = find_entry_point_type(value)
  File "/Users/Edu/dev/ploomber/src/ploomber/entrypoint.py", line 65, in find_entry_point_type
    raise ValueError(
ValueError: Could not determine the entry point type from value: 'pipeline.yaml'. Expected an existing file with extension .yaml or .yml, existing directory, glob-like pattern (i.e., *.py) or dotted path (i.e., module.sub_module.factory_function). Verify your input.

How to check if the argument "looks like" a path to a yaml file, and if so, say that the path doesn't exist. If it doesn't look like a path to a yaml, print the default error message.

My code:-

if type_:
        return type_
    else:
        raise ValueError(
            'Could not determine the entry point type from value: '
            f'{entry_point!r}. Expected '
            'an existing file with extension .yaml or .yml, '
            'existing directory, glob-like pattern '
            '(i.e., *.py) or dotted path '
            '(i.e., module.sub_module.factory_function). Verify your input.')


def try_to_find_entry_point_type(entry_point):
    if entry_point is None:
        return None
    elif '*' in entry_point:
        return EntryPoint.Pattern
    elif '::' in entry_point:
        return EntryPoint.ModulePath
    elif Path(entry_point).exists():
        if Path(entry_point).is_dir():
            return EntryPoint.Directory
        else:
            return EntryPoint.File
    elif '.' in entry_point and Path(entry_point).suffix not in {
            '.yaml', '.yml'
    }:
        return EntryPoint.DottedPath
  • Please make a [mre] that includes several example inputs, both strings that are paths and ones that aren't (and which are similar to the actual cases your code is going to encounter). – Random Davis Jan 31 '22 at 16:27
  • Does this answer your question? [Check whether a path is valid in Python without creating a file at the path's target](https://stackoverflow.com/questions/9532499/check-whether-a-path-is-valid-in-python-without-creating-a-file-at-the-paths-ta) – jfaccioni Jan 31 '22 at 16:27
  • This might be relevant: https://stackoverflow.com/q/3262569/1388292 – Jacques Gaudin Jan 31 '22 at 16:29

1 Answers1

0

I think this should work.

from pathlib import Path
Path('my_file.yaml').suffix == '.yaml'