Debian Codegraph @

envisage/i_import_manager.py

raw
1 # (C) Copyright 2007-2025 Enthought, Inc., Austin, TX
2 # All rights reserved.
3 #
4 # This software is provided without warranty under the terms of the BSD
5 # license included in LICENSE.txt and may be redistributed only under
6 # the conditions described in the aforementioned license. The license
7 # is also available online at http://www.enthought.com/licenses/BSD.txt
8 #
9 # Thanks for using Enthought open source!
10 """ The interface for import managers. """
11
12
13 # Enthought library imports.
14 from traits.api import Interface
15
16
17 class IImportManager(Interface):
18 """The interface for import managers."""
19
20 def import_symbol(self, symbol_path):
21 """Import the symbol defined by the specified symbol path.
22
23 'symbol_path' is a string containing the path to a symbol through the
24 Python package namespace.
25
26 It can be in one of two forms:
27
28 1) 'foo.bar.baz'
29
30 Which is turned into the equivalent of an import statement that
31 looks like::
32
33 from foo.bar import baz
34
35 With the value of 'baz' being returned.
36
37 2) 'foo.bar:baz' (i.e. a ':' separating the module from the symbol)
38
39 Which is turned into the equivalent of::
40
41 from foo import bar
42 eval('baz', bar.__dict__)
43
44 With the result of the 'eval' being returned.
45
46 The second form is recommended as it allows for nested symbols to be
47 retreived, e.g. the symbol path 'foo.bar:baz.bling' becomes::
48
49 from foo import bar
50 eval('baz.bling', bar.__dict__)
51
52 The first form is retained for backwards compatability.
53
54 """