Skip to content

Commit 86a950a

Browse files
authored
Merge pull request #2084 from kotborealis/master
fix: use find_spec for pip plugins
2 parents 12b11f8 + 172671e commit 86a950a

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/buildstream/_pluginfactory/pluginoriginpip.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313
#
14-
import os
14+
from pathlib import Path
1515

1616
from .._exceptions import PluginError
1717

@@ -34,6 +34,7 @@ def get_plugin_paths(self, kind, plugin_type):
3434

3535
from packaging.requirements import Requirement, InvalidRequirement
3636
from importlib.metadata import distribution, PackageNotFoundError
37+
from importlib.util import find_spec
3738

3839
# Sources and elements are looked up in separate
3940
# entrypoint groups from the same package.
@@ -86,17 +87,19 @@ def get_plugin_paths(self, kind, plugin_type):
8687
reason="plugin-not-found",
8788
)
8889

89-
location = dist.locate_file(entrypoint.module.replace(".", os.sep) + ".py")
90-
defaults = dist.locate_file(entrypoint.module.replace(".", os.sep) + ".yaml")
90+
location = Path(find_spec(entrypoint.module).origin)
91+
defaults = location.with_suffix(".yaml")
9192

9293
if not defaults.exists():
9394
# The plugin didn't have an accompanying YAML file
9495
defaults = None
9596

97+
directory = str(location.parent)
98+
9699
return (
97-
os.path.dirname(location),
100+
directory,
98101
str(defaults),
99-
"python package '{}' version {} at: {}".format(dist.name, dist.version, dist.locate_file("")),
102+
"python package '{}' version {} at: {}".format(dist.name, dist.version, directory),
100103
)
101104

102105
def load_config(self, origin_node):

0 commit comments

Comments
 (0)