From 65395185c3f38aa3d640af3e103590fdca367a9a Mon Sep 17 00:00:00 2001 From: jack1142 <6032823+jack1142@users.noreply.github.com> Date: Thu, 28 May 2020 23:41:06 +0200 Subject: [PATCH] Add lib folder to `pkg_resources`'s working set (#3843) --- redbot/__main__.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/redbot/__main__.py b/redbot/__main__.py index d0abd0643..84eb5f6b1 100644 --- a/redbot/__main__.py +++ b/redbot/__main__.py @@ -7,6 +7,7 @@ import json import logging import os import pip +import pkg_resources import platform import shutil import signal @@ -346,6 +347,14 @@ async def run_bot(red: Red, cli_flags: Namespace) -> None: LIB_PATH.mkdir(parents=True, exist_ok=True) if str(LIB_PATH) not in sys.path: sys.path.append(str(LIB_PATH)) + + # "It's important to note that the global `working_set` object is initialized from + # `sys.path` when `pkg_resources` is first imported, but is only updated if you do + # all future `sys.path` manipulation via `pkg_resources` APIs. If you manually modify + # `sys.path`, you must invoke the appropriate methods on the `working_set` instance + # to keep it in sync." + # Source: https://setuptools.readthedocs.io/en/latest/pkg_resources.html#workingset-objects + pkg_resources.working_set.add_entry(str(LIB_PATH)) sys.meta_path.insert(0, SharedLibImportWarner()) if cli_flags.token: