33# Picard, the next-generation MusicBrainz tagger
44#
55# Copyright (C) 2024 Laurent Monin
6- # Copyright (C) 2024 Philipp Wolfer
6+ # Copyright (C) 2024-2025 Philipp Wolfer
77#
88# This program is free software; you can redistribute it and/or
99# modify it under the terms of the GNU General Public License
2020# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2121
2222import importlib .util
23- import os
23+ from pathlib import Path
2424import sys
2525
2626from picard .plugin3 .api import PluginApi
@@ -41,7 +41,7 @@ class PluginSourceSyncError(Exception):
4141class PluginSource :
4242 """Abstract class for plugin sources"""
4343
44- def sync (self , target_directory : str ):
44+ def sync (self , target_directory : Path ):
4545 raise NotImplementedError
4646
4747
@@ -54,15 +54,15 @@ def __init__(self, url: str, ref: str = None):
5454 self .url = url
5555 self .ref = ref or 'main'
5656
57- def sync (self , target_directory : str ):
58- if os . path . isdir ( target_directory ):
57+ def sync (self , target_directory : Path ):
58+ if target_directory . is_dir ( ):
5959 print (f'{ target_directory } exists, fetch changes' )
60- repo = pygit2 .Repository (target_directory )
60+ repo = pygit2 .Repository (target_directory . absolute () )
6161 for remote in repo .remotes :
6262 remote .fetch (callbacks = GitRemoteCallbacks ())
6363 else :
6464 print (f'Cloning { self .url } to { target_directory } ' )
65- repo = pygit2 .clone_repository (self .url , target_directory , callbacks = GitRemoteCallbacks ())
65+ repo = pygit2 .clone_repository (self .url , target_directory . absolute () , callbacks = GitRemoteCallbacks ())
6666 print (list (repo .references ))
6767 print (list (repo .branches ))
6868 print (list (repo .remotes ))
@@ -81,27 +81,24 @@ def sync(self, target_directory: str):
8181class PluginSourceLocal (PluginSource ):
8282 """Plugin is stored in a local directory, but is not a git repo"""
8383
84- def sync (self , target_directory : str ):
84+ def sync (self , target_directory : Path ):
8585 # TODO: copy tree to plugin directory (?)
8686 pass
8787
8888
8989class Plugin :
90- local_path : str = None
90+ local_path : Path = None
9191 remote_url : str = None
9292 ref = None
9393 name : str = None
9494 module_name : str = None
9595 manifest : PluginManifest = None
9696 _module = None
9797
98- def __init__ (self , plugins_dir : str , plugin_name : str ):
99- if not os .path .exists (plugins_dir ):
100- os .makedirs (plugins_dir )
101- self .plugins_dir = plugins_dir
98+ def __init__ (self , plugins_dir : Path , plugin_name : str ):
10299 self .name = plugin_name
103100 self .module_name = f'picard.plugins.{ self .name } '
104- self .local_path = os . path . join ( self . plugins_dir , self .name )
101+ self .local_path = plugins_dir . joinpath ( self .name )
105102
106103 def sync (self , plugin_source : PluginSource = None ):
107104 """Sync plugin source"""
@@ -113,13 +110,13 @@ def sync(self, plugin_source: PluginSource = None):
113110
114111 def read_manifest (self ):
115112 """Reads metadata for the plugin from the plugin's MANIFEST.toml"""
116- manifest_path = os . path . join ( self .local_path , 'MANIFEST.toml' )
113+ manifest_path = self .local_path . joinpath ( 'MANIFEST.toml' )
117114 with open (manifest_path , 'rb' ) as manifest_file :
118115 self .manifest = PluginManifest (self .name , manifest_file )
119116
120117 def load_module (self ):
121118 """Load corresponding module from source path"""
122- module_file = os . path . join ( self .local_path , '__init__.py' )
119+ module_file = self .local_path . joinpath ( '__init__.py' )
123120 spec = importlib .util .spec_from_file_location (self .module_name , module_file )
124121 module = importlib .util .module_from_spec (spec )
125122 sys .modules [self .module_name ] = module
0 commit comments