Show More
The requested changes are too big and content was truncated. Show full diff
@@ -1,92 +1,91 b'' | |||
|
1 | 1 | import inspect |
|
2 | 2 | import logging |
|
3 | 3 | |
|
4 | 4 | from pyramid.config import Configurator |
|
5 | 5 | |
|
6 | 6 | log = logging.getLogger(__name__) |
|
7 | 7 | |
|
8 | 8 | class InspectProxy(object): |
|
9 | 9 | """ |
|
10 | 10 | Proxy to the `inspect` module that allows us to use the pyramid include |
|
11 | 11 | mechanism for cythonized modules without source file. |
|
12 | 12 | """ |
|
13 | 13 | |
|
14 | 14 | def _get_cyfunction_func_code(self, cyfunction): |
|
15 | 15 | """ |
|
16 | 16 | Unpack the `func_code` attribute of a cython function. |
|
17 | 17 | """ |
|
18 | 18 | if inspect.ismethod(cyfunction): |
|
19 | 19 | cyfunction = cyfunction.im_func |
|
20 | 20 | return getattr(cyfunction, 'func_code') |
|
21 | 21 | |
|
22 | 22 | def getmodule(self, *args, **kwds): |
|
23 | 23 | """ |
|
24 | 24 | Simple proxy to `inspect.getmodule`. |
|
25 | 25 | """ |
|
26 | 26 | return inspect.getmodule(*args, **kwds) |
|
27 | 27 | |
|
28 | 28 | def getsourcefile(self, obj): |
|
29 | 29 | """ |
|
30 | 30 | Proxy to `inspect.getsourcefile` or `inspect.getfile` depending on if |
|
31 | 31 | it's called to look up the source file that contains the magic pyramid |
|
32 | 32 | `includeme` callable. |
|
33 | 33 | |
|
34 | 34 | For cythonized modules the source file may be deleted. Therefore we |
|
35 | 35 | return the result of `inspect.getfile` instead. In the case of the |
|
36 | 36 | `configurator.include` method this is OK, because the result is passed |
|
37 | 37 | to `os.path.dirname` which strips the file name. So it doesn't matter |
|
38 | 38 | if we return the path to the source file or another file in the same |
|
39 | 39 | directory. |
|
40 | 40 | """ |
|
41 | 41 | # Check if it's called to look up the source file that contains the |
|
42 | 42 | # magic pyramid `includeme` callable. |
|
43 | 43 | if getattr(obj, '__name__') == 'includeme': |
|
44 | 44 | try: |
|
45 | 45 | return inspect.getfile(obj) |
|
46 | 46 | except TypeError as e: |
|
47 | 47 | # Cython functions are not recognized as functions by the |
|
48 | 48 | # inspect module. We have to unpack the func_code attribute |
|
49 | 49 | # ourself. |
|
50 | 50 | if 'cyfunction' in e.message: |
|
51 | 51 | obj = self._get_cyfunction_func_code(obj) |
|
52 | 52 | return inspect.getfile(obj) |
|
53 | 53 | raise |
|
54 | 54 | else: |
|
55 | 55 | return inspect.getsourcefile(obj) |
|
56 | 56 | |
|
57 | 57 | |
|
58 | 58 | class CythonCompatConfigurator(Configurator): |
|
59 | 59 | """ |
|
60 | 60 | Customized configurator to replace the inspect class attribute with |
|
61 | 61 | a custom one that is cython compatible. |
|
62 | 62 | """ |
|
63 | 63 | inspect = InspectProxy() |
|
64 | 64 | |
|
65 | 65 | |
|
66 | 66 | def register_appenlight_plugin(config, plugin_name, plugin_config): |
|
67 | 67 | def register(): |
|
68 | 68 | log.warning('Registering plugin: {}'.format(plugin_name)) |
|
69 | 69 | if plugin_name not in config.registry.appenlight_plugins: |
|
70 | 70 | config.registry.appenlight_plugins[plugin_name] = { |
|
71 | 71 | 'javascript': None, |
|
72 | 72 | 'static': None, |
|
73 | 73 | 'css': None, |
|
74 | 'top_nav': None, | |
|
75 | 74 | 'celery_tasks': None, |
|
76 | 75 | 'celery_beats': None, |
|
77 | 76 | 'fulltext_indexer': None, |
|
78 | 77 | 'sqlalchemy_migrations': None, |
|
79 | 78 | 'default_values_setter': None, |
|
80 | 79 | 'resource_types': [], |
|
81 | 80 | 'url_gen': None |
|
82 | 81 | } |
|
83 | 82 | config.registry.appenlight_plugins[plugin_name].update( |
|
84 | 83 | plugin_config) |
|
85 | 84 | # inform AE what kind of resource types we have available |
|
86 | 85 | # so we can avoid failing when a plugin is removed but data |
|
87 | 86 | # is still present in the db |
|
88 | 87 | if plugin_config.get('resource_types'): |
|
89 | 88 | config.registry.resource_types.extend( |
|
90 | 89 | plugin_config['resource_types']) |
|
91 | 90 | |
|
92 | 91 | config.action('appenlight_plugin={}'.format(plugin_name), register) |
|
1 | NO CONTENT: modified file | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: modified file | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: modified file | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: modified file | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: modified file | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: modified file | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: modified file | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: modified file | |
The requested commit or file is too big and content was truncated. Show full diff |
General Comments 0
You need to be logged in to leave comments.
Login now