Allow loading extensions via relative paths #2465
Labels
feature request
This is a feature request.
help appreciated
Good issue to work on
suggestion
A suggestion
The Problem
I would like to use relative import paths to describe my extensions, e.g.,
.extensions.foo
rather than requiring an absolute path likemy_bot.extensions.foo
. I use relative paths for package-internal imports, so it seems logical that extensions would follow the same pattern.This does not currently work. I get the following error:
It would seam this library is using
importlib
internally, which can handle relative paths, but is not passing enough parameters.The Ideal Solution
I would like
Bot.load_extension
to take an optional second parameter, which would specify the package to resolve against. This follows the example ofimportlib.import_module
, which takes a package parameter in the same way. If no package is provided, the path is looked up as if from a top-level script (the current behavior).This would allow us to say
which would load the extension relative to the current package.
The Current Solution
Currently the solution is to only use absolute paths. I use
importlib.utils.resolve_name
to resolve my relative paths to absolute ones:Summary
Please allow us to load extensions using relative paths via an optional package parameter in
Bot.load_extension
.This feature request looks similar to #1703, but that request wants something similar old Python 2.x-style relative paths (just concatenating package and name with a dot). I would like something compatible with Python 3 and
importlib
.I would be willing to work on a merge request. I just wanted to make an issue first in case there was a conscious decision not to support relative paths. (I would still ask you to reconsider.)
The text was updated successfully, but these errors were encountered: