cp2k / cp2k-input-tools

Fully validating pure-python CP2K input file tools including preprocessing capabilities
MIT License
47 stars 10 forks source link

Bug: base-dir argument cannot be a bytes object. #60

Closed yakutovicha closed 2 years ago

yakutovicha commented 2 years ago

When I run:

$ fromcp2k  -f yaml aiida.inp --base-dir files/

I get the following error:

Traceback (most recent call last):
  File "/home/aiida/.local/bin/fromcp2k", line 8, in <module>
    sys.exit(fromcp2k())
  File "/opt/conda/lib/python3.7/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/opt/conda/lib/python3.7/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/opt/conda/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/conda/lib/python3.7/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/aiida/.local/lib/python3.7/site-packages/cp2k_input_tools/cli/fromcp2k.py", line 64, in fromcp2k
    tree = cp2k_parser.parse(fhandle, dict(var_values))
  File "/home/aiida/.local/lib/python3.7/site-packages/cp2k_input_tools/parser.py", line 205, in parse
    preprocessor = CP2KPreprocessor(fhandle, self._base_inc_dir, initial_variable_values)
  File "/home/aiida/.local/lib/python3.7/site-packages/cp2k_input_tools/preprocessor.py", line 38, in __init__
    self._inc_dirs = [Path(b) for b in base_dir]
  File "/home/aiida/.local/lib/python3.7/site-packages/cp2k_input_tools/preprocessor.py", line 38, in <listcomp>
    self._inc_dirs = [Path(b) for b in base_dir]
  File "/opt/conda/lib/python3.7/pathlib.py", line 1027, in __new__
    self = cls._from_parts(args, init=False)
  File "/opt/conda/lib/python3.7/pathlib.py", line 674, in _from_parts
    drv, root, parts = self._parse_args(args)
  File "/opt/conda/lib/python3.7/pathlib.py", line 658, in _parse_args
    a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not int

It looks like the bytes object is recognised as Sequence here: https://github.com/cp2k/cp2k-input-tools/blob/05d7b47b22ff324ac726e2ab89da89d2dd890365/cp2k_input_tools/preprocessor.py#L37