Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

weldx.asdf.util.get_yaml_header doesn't work with AsdfFile #307

Closed
Devmawi opened this issue Mar 28, 2021 · 2 comments
Closed

weldx.asdf.util.get_yaml_header doesn't work with AsdfFile #307

Devmawi opened this issue Mar 28, 2021 · 2 comments

Comments

@Devmawi
Copy link

Devmawi commented Mar 28, 2021

Try to get the yaml header of a weldx file and got an exception:

new_asdf_file = asdf.open("vgroove.asdf")
yaml_header = weldx.asdf.util.get_yaml_header(new_asdf_file)

# Exception has occurred: TypeError
# expected str, bytes or os.PathLike object, not AsdfFile
#  File "D:\Documents\dev\python\kisa-weldx-examples\asdf_file_handling.py", line 26, in <module>
#    yaml_header = weldx.asdf.util.get_yaml_header(new_asdf_file)

weldx version = 0.3.1
Python 3.8.8 (default, Feb 24 2021, 15:54:32) [MSC v.1928 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.

See the full example under:

kisa-weldx-examples/asdf_file_handling.py

@marscher
Copy link
Collaborator

marscher commented Mar 28, 2021

Hi Devmawi,

according to the documentation you should pass a file name to the get_header function. This makes sense, because the asdf.open() function already reads in all the meta-data and runs validation and so forth (e.g. creates a heavy-weight object).

https://letmegooglethat.com/?q=weldx+get_yaml_header

edit: funnily the wrapped google result does not point to the readthedocs result I get without the wrapper. They must know me very well. Sorry for playing the wise guy here!

@Devmawi
Copy link
Author

Devmawi commented Mar 28, 2021

Who can read is better off:

def get_yaml_header(file) -> str:  # pragma: no cover
    """Read the YAML header part (excluding binary sections) **OF** an ASDF file.

    Parameters
    ----------
    file
        filename, ``pathlib.Path`` or ``BytesIO`` buffer **OF** ASDF file

Thank you for your prompt reply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants