mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
[Core/Downloader] Add 3rd-party lib folder to sys.path before loading cogs (#3062)
* fix(core,downloader): add lib folder to sys.path before loading cogs * chore(changelog): add towncrier entry * fix(core): always append 3rd-party lib path to the end of `sys.path`
This commit is contained in:
parent
8267ad9aab
commit
3b0fa0c05d
1
changelog.d/3036.bugfix.rst
Normal file
1
changelog.d/3036.bugfix.rst
Normal file
@ -0,0 +1 @@
|
||||
Add 3rd-party lib folder to ``sys.path`` before loading cogs. This prevents issues with 3rd-party cogs failing to load without loaded Downloader due to unavailable requirements.
|
||||
1
changelog.d/3062.bugfix.rst
Normal file
1
changelog.d/3062.bugfix.rst
Normal file
@ -0,0 +1 @@
|
||||
Always append 3rd-party lib folder to the end of ``sys.path`` to avoid shadowing Red's dependencies.
|
||||
@ -119,6 +119,13 @@ def main():
|
||||
init_global_checks(red)
|
||||
init_events(red, cli_flags)
|
||||
|
||||
# lib folder has to be in sys.path before trying to load any 3rd-party cog (GH-3061)
|
||||
# We might want to change handling of requirements in Downloader at later date
|
||||
LIB_PATH = data_manager.cog_data_path(raw_name="Downloader") / "lib"
|
||||
LIB_PATH.mkdir(parents=True, exist_ok=True)
|
||||
if str(LIB_PATH) not in sys.path:
|
||||
sys.path.append(str(LIB_PATH))
|
||||
|
||||
red.add_cog(Core(red))
|
||||
red.add_cog(CogManagerUI())
|
||||
if cli_flags.dev:
|
||||
|
||||
@ -43,15 +43,11 @@ class Downloader(commands.Cog):
|
||||
self.SHAREDLIB_PATH = self.LIB_PATH / "cog_shared"
|
||||
self.SHAREDLIB_INIT = self.SHAREDLIB_PATH / "__init__.py"
|
||||
|
||||
self.LIB_PATH.mkdir(parents=True, exist_ok=True)
|
||||
self.SHAREDLIB_PATH.mkdir(parents=True, exist_ok=True)
|
||||
if not self.SHAREDLIB_INIT.exists():
|
||||
with self.SHAREDLIB_INIT.open(mode="w", encoding="utf-8") as _:
|
||||
pass
|
||||
|
||||
if str(self.LIB_PATH) not in syspath:
|
||||
syspath.insert(1, str(self.LIB_PATH))
|
||||
|
||||
self._repo_manager = RepoManager()
|
||||
|
||||
async def initialize(self):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user