1- '''
1+ """
22Staticfiles finders for Dash assets
33
44Copyright (c) 2018 Gibbs Consulting and others - see CONTRIBUTIONS.md
2020LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2121OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222SOFTWARE.
23- '''
23+ """
2424
2525import os
2626import importlib
3838from django_plotly_dash .dash_wrapper import all_apps
3939from django_plotly_dash .util import full_asset_path
4040
41+
4142class DashComponentFinder (BaseFinder ):
42- ' Find static files in components'
43+ " Find static files in components"
4344
44- #pylint: disable=abstract-method, redefined-builtin
45+ # pylint: disable=abstract-method, redefined-builtin
4546
4647 def __init__ (self ):
47-
4848 self .locations = []
4949 self .storages = OrderedDict ()
5050 self .components = {}
5151
52- self .ignore_patterns = ["*.py" , "*.pyc" ,]
52+ self .ignore_patterns = [
53+ "*.py" ,
54+ "*.pyc" ,
55+ ]
5356
5457 try :
5558 components = settings .PLOTLY_COMPONENTS
5659 except :
5760 components = []
5861
59- built_ins = [('dash' , ['dcc' , 'html' , 'dash_table' , 'deps' , 'dash-renderer' , 'dash-renderer/build' ]),
60- ('plotly' , ['package_data' ]),
61- ]
62+ built_ins = [
63+ (
64+ "dash" ,
65+ [
66+ "dcc" ,
67+ "html" ,
68+ "dash_table" ,
69+ "deps" ,
70+ "dash-renderer" ,
71+ "dash-renderer/build" ,
72+ ],
73+ ),
74+ ("plotly" , ["package_data" ]),
75+ ]
6276
6377 for component_name in components :
64-
65- split_name = component_name .split ('/' )
78+ split_name = component_name .split ("/" )
6679 try :
6780 module_name = "." .join (split_name )
6881 module = importlib .import_module (module_name )
6982 path_directory = os .path .dirname (module .__file__ )
7083 except :
7184 module_name = "." .join (split_name [:- 1 ])
7285 module = importlib .import_module (module_name )
73- path_directory = os .path .join (os .path .dirname (module .__file__ ),
74- split_name [- 1 ])
86+ path_directory = os .path .join (
87+ os .path .dirname (module .__file__ ), split_name [- 1 ]
88+ )
7589
7690 root = path_directory
7791 storage = FileSystemStorage (location = root )
@@ -89,20 +103,18 @@ def __init__(self):
89103 self .components [path ] = component_name
90104
91105 for module_name , component_list in built_ins :
92-
93106 module = importlib .import_module (module_name )
94107
95108 for specific_component in component_list :
96-
97- path_directory = os .path .join ( os . path . dirname (module .__file__ ),
98- specific_component )
109+ path_directory = os . path . join (
110+ os .path .dirname (module .__file__ ), specific_component
111+ )
99112
100113 root = path_directory
101114 component_name = f"{ module_name } /{ specific_component } "
102115 path = f"dash/component/{ component_name } "
103116
104117 if path not in self .components :
105-
106118 storage = FileSystemStorage (location = root )
107119 storage .prefix = path
108120
@@ -113,16 +125,19 @@ def __init__(self):
113125
114126 super ().__init__ ()
115127
116- def find (self , path , all = False ):
128+ def find (self , path , find_all = False , all = False ):
129+ all = all or find_all
117130 matches = []
118131 for component_name in self .locations :
119132 storage = self .storages [component_name ]
120- location = storage .location # dir on disc
133+ location = storage .location # dir on disc
121134
122135 component_path = "dash/component/%s" % component_name
123- if len (path ) > len (component_path ) and path [:len (component_path )] == component_path :
124-
125- matched_path = os .path .join (location , path [len (component_path )+ 1 :])
136+ if (
137+ len (path ) > len (component_path )
138+ and path [: len (component_path )] == component_path
139+ ):
140+ matched_path = os .path .join (location , path [len (component_path ) + 1 :])
126141 if os .path .exists (matched_path ):
127142 if not all :
128143 return matched_path
@@ -132,7 +147,7 @@ def find(self, path, all=False):
132147
133148 # pylint: disable=inconsistent-return-statements, no-self-use
134149 def find_location (self , path ):
135- ' Return location, if it exists'
150+ " Return location, if it exists"
136151 if os .path .exists (path ):
137152 return path
138153
@@ -142,23 +157,25 @@ def list(self, ignore_patterns):
142157 for path in get_files (storage , ignore_patterns + self .ignore_patterns ):
143158 yield path , storage
144159
160+
145161class DashAppDirectoryFinder (BaseFinder ):
146- ' Find static fies in application subdirectories'
162+ " Find static files in application subdirectories"
147163
148164 def __init__ (self ):
149165 # get all registered apps
150166
151167 self .locations = []
152168 self .storages = OrderedDict ()
153169
154- self .ignore_patterns = ["*.py" , "*.pyc" ,]
170+ self .ignore_patterns = [
171+ "*.py" ,
172+ "*.pyc" ,
173+ ]
155174
156175 for app_config in apps .get_app_configs ():
157-
158- path_directory = os .path .join (app_config .path , 'assets' )
176+ path_directory = os .path .join (app_config .path , "assets" )
159177
160178 if os .path .isdir (path_directory ):
161-
162179 storage = FileSystemStorage (location = path_directory )
163180
164181 storage .prefix = full_asset_path (app_config .name , "" )
@@ -168,8 +185,8 @@ def __init__(self):
168185
169186 super ().__init__ ()
170187
171- #pylint: disable=redefined-builtin
172- def find (self , path , all = False ):
188+ # pylint: disable=redefined-builtin
189+ def find (self , path , all = False , ** kwargs ):
173190 return []
174191
175192 def list (self , ignore_patterns ):
@@ -180,12 +197,11 @@ def list(self, ignore_patterns):
180197
181198
182199class DashAssetFinder (BaseFinder ):
183- ' Find static files in asset directories'
200+ " Find static files in asset directories"
184201
185- #pylint: disable=unused-import, unused-variable, no-name-in-module, import-error, abstract-method
202+ # pylint: disable=unused-import, unused-variable, no-name-in-module, import-error, abstract-method
186203
187204 def __init__ (self ):
188-
189205 # Ensure urls are loaded
190206 root_urls = settings .ROOT_URLCONF
191207 importlib .import_module (root_urls )
@@ -197,37 +213,37 @@ def __init__(self):
197213 self .locations = []
198214 self .storages = OrderedDict ()
199215
200- self .ignore_patterns = ["*.py" , "*.pyc" ,]
216+ self .ignore_patterns = [
217+ "*.py" ,
218+ "*.pyc" ,
219+ ]
201220
202221 added_locations = {}
203222
204223 for app_slug , obj in self .apps .items ():
205-
206224 caller_module = obj .caller_module
207225 location = obj .caller_module_location
208226 subdir = obj .assets_folder
209227
210228 path_directory = os .path .join (os .path .dirname (location ), subdir )
211229
212230 if os .path .isdir (path_directory ):
213-
214231 component_name = app_slug
215232 storage = FileSystemStorage (location = path_directory )
216- path = full_asset_path (obj .caller_module .__name__ ,"" )
233+ path = full_asset_path (obj .caller_module .__name__ , "" )
217234 storage .prefix = path
218235
219236 self .locations .append (component_name )
220237 self .storages [component_name ] = storage
221238
222239 super ().__init__ ()
223240
224- #pylint: disable=redefined-builtin
225- def find (self , path , all = False ):
241+ # pylint: disable=redefined-builtin
242+ def find (self , path , all = False , ** kwargs ):
226243 return []
227244
228245 def list (self , ignore_patterns ):
229246 for component_name in self .locations :
230247 storage = self .storages [component_name ]
231248 for path in get_files (storage , ignore_patterns + self .ignore_patterns ):
232249 yield path , storage
233-
0 commit comments