-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcomponent.py
More file actions
60 lines (42 loc) · 1.45 KB
/
component.py
File metadata and controls
60 lines (42 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# -*- coding: utf-8 -*-
"""
component
~~~~~~~~~
A module that implements various helper functions to help consume
components from popular package managers like bower.
:copyright: (c) 2013 by Daniel Chatfield
:license: MIT, see LICENSE for details.
"""
import os
import sys
setup_done = False
def setup(base_dir=None, depth=1, directory='components'):
"""Helper function that fixes python path.
:param base_dir: Pass __file__ so component knows where your application
files are.
:param depth: The number of times `os.path.dirname()` needs to be
called on `base_dir` to get the folder immediately
above bower_components Defaults to 1.
:param directory: The directory where the components are installed to.
Defaults to `components`.
"""
global setup_done
if setup_done:
return
if not base_dir:
base_dir = __file__
for i in range(depth):
base_dir = up_a_level(base_dir)
bower_path = os.path.join(base_dir, directory)
sys.path.insert(0, bower_path)
setup_done = True
def up_a_level(current_pointer):
"""A helper function to traverse up a level of the filesystem"""
return os.path.dirname(current_pointer)
def require(component_name):
"""A wrapper that allows importing of components as python packages
"""
setup()
return __import__(component_name)
def export(object):
pass