From 0b808b5c5a47b504399a64b80fc545dccd401712 Mon Sep 17 00:00:00 2001 From: Fredrik Svantes Date: Fri, 24 Sep 2021 16:33:14 +0200 Subject: [PATCH] pip no longer invoked by an old script wrapper. while debugging an error I encountered while running setup.py I also saw pip.main was used to installed packages. installing packages through pip.main (pip.main(["install", RUAMEL_YAML_VERSION])) is not recommended, and will be removed from future versions of pip. https://github.com/pypa/pip/issues/5599 https://pip.pypa.io/en/latest/user_guide/#using-pip-from-your-program --- setup.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 7620020e6..e924dfce3 100644 --- a/setup.py +++ b/setup.py @@ -10,15 +10,18 @@ import textwrap from typing import Dict, NamedTuple, List, Sequence, Optional, TypeVar from abc import ABC, abstractmethod import ast - +import subprocess +import sys # NOTE: have to programmatically include third-party dependencies in `setup.py`. +def installPackage(package: str): + subprocess.check_call([sys.executable, '-m', 'pip', 'install', package]) + RUAMEL_YAML_VERSION = "ruamel.yaml==0.16.5" try: import ruamel.yaml except ImportError: - import pip - pip.main(["install", RUAMEL_YAML_VERSION]) + installPackage(RUAMEL_YAML_VERSION) from ruamel.yaml import YAML @@ -26,8 +29,7 @@ MARKO_VERSION = "marko==1.0.2" try: import marko except ImportError: - import pip - pip.main(["install", MARKO_VERSION]) + installPackage(MARKO_VERSION) from marko.block import Heading, FencedCode, LinkRefDef, BlankLine from marko.inline import CodeSpan