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

Future as "extras_require" (or how to conditionally import future) #592

Open
maxdup opened this issue Aug 28, 2021 · 0 comments
Open

Future as "extras_require" (or how to conditionally import future) #592

maxdup opened this issue Aug 28, 2021 · 0 comments

Comments

@maxdup
Copy link

maxdup commented Aug 28, 2021

Unless I'm mistaken, there's is no way to conditionally import python-future

I have a couple of pasteurised libraries. When in modern environments, my libs don't really require future to run which results in some amount of bloat. To avoid that, I've been trying to leverage setup.py's "extras_require", which would only install future when deemed necessary.

setup(
    ...
    install_requires=[...],
    extras_require={
        ":python_version<='2.7'":  ["future"]
    },
    ...
)

The conventional way of doing a conditional import would look something like this:

try:
    from __future__ import absolute_import
    from __future__ import division
    from __future__ import print_function
    from __future__ import unicode_literals

    from builtins import open
    from future import standard_library
    standard_library.install_aliases()
except ImportError:
    pass

Sadly, with future, this results in SyntaxError: from __future__ imports must occur at the beginning of the file.

I was wondering if conditional imports could be made possible (Or if there's an alternative approach that I'm unaware of here).

Note:
Implementing issue #266 could make this issue irrelevant. Feel free to close if #266 is being prioritised.

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

1 participant