From 2222f165f02002ba0839bc4ed65b7ce4db4498e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20Can=20Ya=C5=9Far?= Date: Tue, 20 Dec 2022 18:37:19 +0300 Subject: [PATCH] Pip20 support with sys (#1) * pip 20+ support --- setup.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/setup.py b/setup.py index 8364d6b..c50b3ac 100644 --- a/setup.py +++ b/setup.py @@ -12,19 +12,28 @@ # pip <= 9.0.3 from pip.req import parse_requirements -try: - # pip >= 10 - from pip._internal.download import PipSession -except ImportError: - # pip <= 9.0.3 - from pip.download import PipSession +PipSession = None +download_module_names = [ "pip._internal.network.download", "pip._internal.download", "pip.download" ] +for module_name in download_module_names: + try: + PipSession = __import__(f'{module_name}', globals(), locals(), [None], 0).PipSession + break + except ImportError: + pass + +if not PipSession: + raise ImportError("Could not find PipSession") def get_requirements(): requirements = parse_requirements( os.path.join(os.path.dirname(__file__), "requirements.txt"), session=PipSession()) - return [str(req.req) for req in requirements] + + try: + return [str(req.requirement) for req in requirements] + except AttributeError: + return [str(req.req) for req in requirements] def read(fname):