Skip to content

BLD lazy import of tempita to avoid cython dependency#15313

Merged
rth merged 7 commits intoscikit-learn:masterfrom
jeremiedbb:lazy-import-tempita
Oct 25, 2019
Merged

BLD lazy import of tempita to avoid cython dependency#15313
rth merged 7 commits intoscikit-learn:masterfrom
jeremiedbb:lazy-import-tempita

Conversation

@jeremiedbb
Copy link
Copy Markdown
Member

Fixes #15298

Same fix as #13980.
There are no other occurrence.


with open(pyxfiles, "r") as f:
tmpl = f.read()
from Cython import Tempita # noqa
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could this be a function in sklearn/_build_utils/__init__.py. Something along these lines:

def tempita_sub(*args, **kwargs):
    """Helper function.
    This does lazy import of Cython to make sure that we do not depend on Cython when building from a  release sdist (since it contains the .c files already)
    """
    from Cython import Tempita
    Tempita.sub(*args, **kwargs)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Or adding a comment above the import about it.

Copy link
Copy Markdown
Member

@rth rth left a comment

Choose a reason for hiding this comment

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

LGTM, aside for the comment below.


with open(pyxfiles, "r") as f:
tmpl = f.read()
from Cython import Tempita # noqa
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Or adding a comment above the import about it.

@jeremiedbb
Copy link
Copy Markdown
Member Author

I went for the utility fonction


import numpy

from sklearn._build_utils import gen_from_templates
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

out of curiosity, can you explain me why an absolute import is required here ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It doesn't work if we use a relative import?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No, they also did it for the deprecated modules in sklearn/setup.py
Maybe @thomasjpfan knows better about that ?

@jeremiedbb jeremiedbb added this to the 0.22 milestone Oct 22, 2019
Copy link
Copy Markdown
Member

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

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

A few comments but looks good

Copy link
Copy Markdown
Member

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

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

Thanks @jeremiedbb , I think it's clear now.

LGTM, though I'm still curious about the need for the absolute import

@jeremiedbb
Copy link
Copy Markdown
Member Author

@lesteve @rth I think it's ready to merge

Copy link
Copy Markdown
Member

@rth rth left a comment

Choose a reason for hiding this comment

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

Nice!

@rth rth changed the title [MRG] lazy import of tempita to avoid cython dependency when building from c files BLD lazy import of tempita to avoid cython dependency Oct 25, 2019
@rth rth merged commit c2115b1 into scikit-learn:master Oct 25, 2019
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.

Undeclared build dependency on cython

4 participants