Skip to content

MNT: Make yaml import truly optional in io.misc.yaml#10257

Merged
bsipocz merged 5 commits intoastropy:masterfrom
pllim:optional-import-yaml
May 3, 2020
Merged

MNT: Make yaml import truly optional in io.misc.yaml#10257
bsipocz merged 5 commits intoastropy:masterfrom
pllim:optional-import-yaml

Conversation

@pllim
Copy link
Member

@pllim pllim commented May 1, 2020

Description

This pull request is to address the yaml import error mentioned in #10246 .

_______________________________________ ERROR collecting astropy/io/misc/yaml.py _______________________________________
astropy/io/misc/yaml.py:81: in <module>
    import yaml
E   ModuleNotFoundError: No module named 'yaml'

During handling of the above exception, another exception occurred:
astropy/io/misc/yaml.py:83: in <module>
    raise ImportError('`import yaml` failed, PyYAML package is required for YAML')
E   ImportError: `import yaml` failed, PyYAML package is required for YAML

With this patch, without PyYAML installed:

>>> from astropy.io.misc import yaml  # No more error
>>> a = yaml.AstropyLoader()
ImportError: `import yaml` failed, PyYAML package is required for YAML and must be 3.12 or later

TODO

  • If this is acceptable, add a change log after milestone is set.

Copy link
Member

@taldcroft taldcroft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks OK to me. Is the min 3.12 requirement new? Maybe this needs to be mentioned in https://docs.astropy.org/en/stable/install.html?

@pllim
Copy link
Member Author

pllim commented May 1, 2020

Is the min 3.12 requirement new?

Not really. It is already in the docstring and I am just making the implementation consistent. This line was added in #5486 by @taldcroft .

.. Note ::
This module requires PyYaml version 3.12 or later.

Copy link
Member

@bsipocz bsipocz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two minor caveats:

  • please add pyyaml==3.12 to the tox file for the oldest deps env
  • mention this version in docs/install.rst

@bsipocz
Copy link
Member

bsipocz commented May 1, 2020

Oh, the the 32bit failure is related

@pllim
Copy link
Member Author

pllim commented May 2, 2020

Re: 32-bit -- I think the failure is not so much 32-bit but the parallel part. Maybe __doctest_requires__ = {'*': ['yaml']} doesn't work well with pytest-xdist. I'll have to ponder this.

@bsipocz
Copy link
Member

bsipocz commented May 2, 2020

ugly workaround just for this, but what if we run the 32bit tests with alldeps? I would generarly feel a bit better to have alldeps the default to make sure we run as many tests as possible for a setting, and only have one run with the mandatory only to make sure the bare minimum works as well, rather the other way around.

pinging @astrofrog as he may recall if there was any such reason to do the 32bit this way.

@pllim
Copy link
Member Author

pllim commented May 2, 2020

I am a little afraid that adding alldeps to 32-bit will open a can of worms but why not try it?

@bsipocz
Copy link
Member

bsipocz commented May 2, 2020

yeah, I wouldn't be surprised by the tiny monster 🐛 crawling out from their hides

@pllim pllim force-pushed the optional-import-yaml branch from 3a9efad to a197269 Compare May 2, 2020 01:23
@pllim
Copy link
Member Author

pllim commented May 2, 2020

Yup... Can o' worms:

    src/checkdep_freetype2.c:9:22: fatal error: ft2build.h: No such file or directory
     #include <ft2build.h>
                          ^
    compilation terminated.
    error: command 'gcc' failed with exit status 1

I'll think of a way to just do a custom skip on that doctest...

@pllim pllim force-pushed the optional-import-yaml branch from 8180dd0 to ff6daf4 Compare May 2, 2020 05:09
@pllim
Copy link
Member Author

pllim commented May 2, 2020

I think I addressed all the comments. Had to move the docstring to RST though to use the doctest directive that we know would work. I successfully ran all the tests locally without yaml installed with this patch. Let's see what the CI says... 🤞 CI passed!

@bsipocz bsipocz added this to the v4.0.2 milestone May 3, 2020
@bsipocz
Copy link
Member

bsipocz commented May 3, 2020

I don't think this needs a changelog, nothing really changed on for the users.

@bsipocz bsipocz merged commit ced2e9c into astropy:master May 3, 2020
@bsipocz
Copy link
Member

bsipocz commented May 3, 2020

Thanks @pllim for taking care all these import issues.

@pllim pllim deleted the optional-import-yaml branch May 4, 2020 16:26
@pllim
Copy link
Member Author

pllim commented May 4, 2020

I hope it works. I think I must have missed something but I think @mhvk fixed it somewhere else. I am sorry!

@mhvk
Copy link
Contributor

mhvk commented May 4, 2020

Yes, fixed elsewhere. And, overall, very nice to have those imports be truly optional! It would be even nicer if there was some way of bailing from module loading (with __all__ empty), but I don't think that's possible.

astrofrog pushed a commit that referenced this pull request May 19, 2020
MNT: Make yaml import truly optional in io.misc.yaml
astrofrog pushed a commit that referenced this pull request May 19, 2020
MNT: Make yaml import truly optional in io.misc.yaml
astrofrog pushed a commit that referenced this pull request May 19, 2020
MNT: Make yaml import truly optional in io.misc.yaml
astrofrog added a commit to astrofrog/astropy that referenced this pull request May 20, 2020
…skip doctest collection in astropy.io.misc.yaml if PyYAML is not available.
astrofrog added a commit to astrofrog/astropy that referenced this pull request May 20, 2020
…skip doctest collection in astropy.io.misc.yaml if PyYAML is not available.
astrofrog added a commit to astrofrog/astropy that referenced this pull request May 20, 2020
…skip doctest collection in astropy.io.misc.yaml if PyYAML is not available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants