@@ -92,7 +92,13 @@ from django.core.management import get_commands
92
92
for command_name, module_name in get_commands().items():
93
93
module = import_module(module_name + '.management.commands.' + command_name)
94
94
command = module.Command
95
- result[command_name] = [getsourcefile(command), findsource(command)[1]]
95
+ try:
96
+ source = findsource(command)
97
+ except OSError:
98
+ pass
99
+ else:
100
+ result[command_name] = [getsourcefile(command), source[1]]
101
+
96
102
97
103
" " Python source code to get command definitions." )
98
104
@@ -185,15 +191,25 @@ except ImportError:
185
191
for site in all_sites:
186
192
for admin_instance in site._registry.values():
187
193
admin_class = admin_instance.__class__
188
- result[str(admin_instance)] = [getsourcefile(admin_class), findsource(admin_class)[1]]
194
+ try:
195
+ source = findsource(admin_class)
196
+ except OSError:
197
+ pass
198
+ else:
199
+ result[str(admin_instance)] = [getsourcefile(admin_class), source[1]]
189
200
190
201
" " Python source code to get admin classes." )
191
202
192
203
(defvar djangonaut-get-models-code "
193
204
from inspect import findsource, getsourcefile
194
205
195
206
for model in apps.get_models():
196
- result[model._meta.app_label + '.' + model.__name__] = [getsourcefile(model), findsource(model)[1]]
207
+ try:
208
+ source = findsource(model)
209
+ except OSError:
210
+ pass
211
+ else:
212
+ result[model._meta.app_label + '.' + model.__name__] = [getsourcefile(model), source[1]]
197
213
198
214
" " Python source code to get models." )
199
215
@@ -206,7 +222,12 @@ from django.db.models import Manager
206
222
for obj in get_objects():
207
223
if isclass(obj) and issubclass(obj, Manager):
208
224
name = getmodule(obj).__name__ + '.' + obj.__name__
209
- result[name] = [getsourcefile(obj), findsource(obj)[1]]
225
+ try:
226
+ source = findsource(obj)
227
+ except OSError:
228
+ pass
229
+ else:
230
+ result[name] = [getsourcefile(obj), source[1]]
210
231
211
232
" " Python source code to get model managers." )
212
233
@@ -221,7 +242,12 @@ loader.load_disk()
221
242
for (label, module_name), migration in sorted(loader.disk_migrations.items()):
222
243
name = label + '.' + module_name
223
244
Migration = migration.__class__
224
- result[name] = [getsourcefile(Migration), findsource(Migration)[1]]
245
+ try:
246
+ source = findsource(Migration)
247
+ except OSError:
248
+ pass
249
+ else:
250
+ result[name] = [getsourcefile(Migration), source[1]]
225
251
226
252
" " Python source code to get migrations." )
227
253
@@ -234,7 +260,12 @@ from django.db.models import Func
234
260
for obj in get_objects():
235
261
if isclass(obj) and issubclass(obj, Func):
236
262
name = getmodule(obj).__name__ + '.' + obj.__name__
237
- result[name] = [getsourcefile(obj), findsource(obj)[1]]
263
+ try:
264
+ source = findsource(obj)
265
+ except OSError:
266
+ pass
267
+ else:
268
+ result[name] = [getsourcefile(obj), source[1]]
238
269
239
270
" " Python source code to get sql functions." )
240
271
@@ -253,7 +284,12 @@ for obj in get_objects():
253
284
if receiver is None:
254
285
continue
255
286
name = getmodule(receiver).__name__ + '.' + receiver.__name__
256
- result[name] = [getsourcefile(receiver), findsource(receiver)[1]]
287
+ try:
288
+ source = findsource(receiver)
289
+ except OSError:
290
+ pass
291
+ else:
292
+ result[name] = [getsourcefile(receiver), source[1]]
257
293
258
294
" " Python source code to get signal receivers." )
259
295
@@ -269,7 +305,12 @@ import_module(settings.ROOT_URLCONF)
269
305
for obj in get_objects():
270
306
if isclass(obj) and issubclass(obj, Serializer):
271
307
name = getmodule(obj).__name__ + '.' + obj.__name__
272
- result[name] = [getsourcefile(obj), findsource(obj)[1]]
308
+ try:
309
+ source = findsource(obj)
310
+ except OSError:
311
+ pass
312
+ else:
313
+ result[name] = [getsourcefile(obj), source[1]]
273
314
274
315
" " Python source code to get drf serializers." )
275
316
@@ -285,7 +326,12 @@ import_module(settings.ROOT_URLCONF)
285
326
for obj in get_objects():
286
327
if isclass(obj) and issubclass(obj, BasePermission):
287
328
name = getmodule(obj).__name__ + '.' + obj.__name__
288
- result[name] = [getsourcefile(obj), findsource(obj)[1]]
329
+ try:
330
+ source = findsource(obj)
331
+ except OSError:
332
+ pass
333
+ else:
334
+ result[name] = [getsourcefile(obj), source[1]]
289
335
290
336
" " Python source code to get drf permissions." )
291
337
@@ -333,20 +379,35 @@ def collect_views(resolver):
333
379
# DRF as_view result.
334
380
view = view.cls
335
381
name = getmodule(view).__name__ + '.' + view.__name__
336
- result[name] = [getsourcefile(view), findsource(view)[1]]
382
+ try:
383
+ source = findsource(view)
384
+ except OSError:
385
+ pass
386
+ else:
387
+ result[name] = [getsourcefile(view), source[1]]
337
388
for attrname in dir(view):
338
389
view_attr = getattr(view, attrname)
339
390
if getattr(view_attr, 'bind_to_methods', None):
340
391
# DRF ViewSet method view.
341
- result[name + '.' + attrname] = [getsourcefile(view_attr), findsource(view_attr)[1]]
392
+ try:
393
+ source = findsource(view_attr)
394
+ except OSError:
395
+ pass
396
+ else:
397
+ result[name + '.' + attrname] = [getsourcefile(view_attr), source[1]]
342
398
continue
343
399
else:
344
400
view = unwrap(view)
345
401
if ismethod(view):
346
402
name = getmodule(view).__name__ + '.' + view.__self__.__class__.__name__ + '.' + view.__name__
347
403
else:
348
404
name = getmodule(view).__name__ + '.' + view.__name__
349
- result[name] = [getsourcefile(view), findsource(view)[1]]
405
+ try:
406
+ source = findsource(view)
407
+ except OSError:
408
+ pass
409
+ else:
410
+ result[name] = [getsourcefile(view), source[1]]
350
411
351
412
collect_views(get_resolver(get_urlconf()))
352
413
@@ -359,7 +420,12 @@ from django.utils.module_loading import import_string
359
420
360
421
for name in getattr(settings, 'MIDDLEWARE', None) or settings.MIDDLEWARE_CLASSES:
361
422
middleware = import_string(name)
362
- result[name] = [getsourcefile(middleware), findsource(middleware)[1]]
423
+ try:
424
+ source = findsource(middleware)
425
+ except OSError:
426
+ pass
427
+ else:
428
+ result[name] = [getsourcefile(middleware), source[1]]
363
429
364
430
" " Python source code to get middlewares." )
365
431
@@ -408,7 +474,12 @@ import_module(settings.ROOT_URLCONF)
408
474
for obj in get_objects():
409
475
if isclass(obj) and issubclass(obj, (BaseForm, BaseFormSet)):
410
476
name = getmodule(obj).__name__ + '.' + obj.__name__
411
- result[name] = [getsourcefile(obj), findsource(obj)[1]]
477
+ try:
478
+ source = findsource(obj)
479
+ except OSError:
480
+ pass
481
+ else:
482
+ result[name] = [getsourcefile(obj), source[1]]
412
483
413
484
" " Python source code to get forms." )
414
485
@@ -424,7 +495,12 @@ import_module(settings.ROOT_URLCONF)
424
495
for obj in get_objects():
425
496
if isclass(obj) and issubclass(obj, Widget):
426
497
name = getmodule(obj).__name__ + '.' + obj.__name__
427
- result[name] = [getsourcefile(obj), findsource(obj)[1]]
498
+ try:
499
+ source = findsource(obj)
500
+ except OSError:
501
+ pass
502
+ else:
503
+ result[name] = [getsourcefile(obj), source[1]]
428
504
429
505
" " Python source code to get widgets." )
430
506
@@ -497,13 +573,23 @@ for library_name, library in libraries.items():
497
573
for tag_name, tag in library.tags.items():
498
574
tag = unwrap(tag)
499
575
try:
500
- result[library_name + '.' + tag_name] = [getsourcefile(tag), findsource(tag)[1]]
576
+ try:
577
+ source = findsource(tag)
578
+ except OSError:
579
+ pass
580
+ else:
581
+ result[library_name + '.' + tag_name] = [getsourcefile(tag), source[1]]
501
582
except TypeError:
502
583
# This is Django 1.8 and we met functools.partial result. We take class defined
503
584
# in the decorator from bound keyword arguments. This class has a method with a
504
585
# closure where we can find decorated function.
505
586
tag = tag.keywords['node_class'].render.__closure__[-1].cell_contents
506
- result[library_name + '.' + tag_name] = [getsourcefile(tag), findsource(tag)[1]]
587
+ try:
588
+ source = findsource(tag)
589
+ except OSError:
590
+ pass
591
+ else:
592
+ result[library_name + '.' + tag_name] = [getsourcefile(tag), source[1]]
507
593
508
594
" " Python source code to get template tags." )
509
595
@@ -542,7 +628,12 @@ except ImportError:
542
628
for library_name, library in libraries.items():
543
629
for filter_name, filter in library.filters.items():
544
630
filter = unwrap(filter)
545
- result[library_name + '.' + filter_name] = [getsourcefile(filter), findsource(filter)[1]]
631
+ try:
632
+ source = findsource(filter)
633
+ except OSError:
634
+ pass
635
+ else:
636
+ result[library_name + '.' + filter_name] = [getsourcefile(filter), source[1]]
546
637
547
638
" " Python source code to get template filters." )
548
639
0 commit comments