Skip to content

Conversation

@mhvk
Copy link
Contributor

@mhvk mhvk commented Jul 12, 2018

This does two things: remove the use of pkg_resources in utils.misc.minversion in favour of its backup (distutils.version.LooseVersion), which is much more light-weight; ensure urllib gets imported only when actually needed, at least at import time.

Especially the removal of pkg_resources has a large effect; with this PR:

python -X importtime -c "import astropy"
# 0.28 s -> 0.16 s

@mhvk mhvk added this to the v3.1 milestone Jul 12, 2018
@mhvk mhvk requested a review from pllim July 12, 2018 22:02
@astropy-bot
Copy link

astropy-bot bot commented Jul 12, 2018

Hi there @mhvk 👋 - thanks for the pull request! I'm just a friendly 🤖 that checks for issues related to the changelog and making sure that this pull request is milestoned and labeled correctly. This is mainly intended for the maintainers, so if you are not a maintainer you can ignore this, and a maintainer will let you know if any action is required on your part 😃.

Everything looks good from my point of view! 👍

If there are any issues with this message, please report them here.

if m:
version = m.group(0)
from distutils.version import LooseVersion
# LooseVersion raises a TypeError when strings like dev, rc1 are part
Copy link
Member

Choose a reason for hiding this comment

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

I don't know if this is true anymore:

In [5]: LooseVersion('3.0dev0') < LooseVersion('3.0dev1')
Out[5]: True

Copy link
Member

Choose a reason for hiding this comment

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

(this was added in #5944 so we should check why)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. All tests pass on python 3.7 at least without it. I'll push a new commit that removes the doctoring - we'll see if the tests #5944 added pass on all versions.

@astrofrog
Copy link
Member

Very nice improvement!

@bsipocz
Copy link
Member

bsipocz commented Jul 13, 2018

Wow, very nice catch!

@mhvk
Copy link
Contributor Author

mhvk commented Jul 13, 2018

OK, tests all passed without the LooseVersion work-around, so I think this was simply something that got solved in the meantime (if not, easy enough to put something back!). Shall we put it in?

@pllim pllim added the utils label Jul 13, 2018
assert not minversion(test_module, version)


def test_minversion():
Copy link
Member

Choose a reason for hiding this comment

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

Does _minversion_test above still run with this removed?

Copy link
Member

Choose a reason for hiding this comment

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

I agree, I think _minversion_test needs to be renamed to test_minversion

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wow, proof yet again how useful review is... How could I have missed that!

@mhvk mhvk force-pushed the simple-import-time-reduction branch from d686fc0 to 4855071 Compare July 13, 2018 15:10
@bsipocz
Copy link
Member

bsipocz commented Jul 13, 2018

I'm merging this as it's been reviewed and then approved. Thanks @mhvk!

@bsipocz bsipocz merged commit 6417f79 into astropy:master Jul 13, 2018
@mhvk mhvk deleted the simple-import-time-reduction branch July 13, 2018 20:40
HarshitZom added a commit to HarshitZom/astropy that referenced this pull request Nov 23, 2025
Switch to robust version parsing (packaging/pkg_resources)
to avoid LooseVersion comparison errors for dev versions.
Adds regression test for issue astropy#7647.
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