cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
gen_env Namespace Reference

Functions

def print_incomplete (msg="")
 
def get_sys_python_env ()
 
def main ()
 

Function Documentation

◆ get_sys_python_env()

def gen_env.get_sys_python_env ( )

Definition at line 82 of file gen_env.py.

82 def get_sys_python_env():
83  # this is not working, we need the python3 without the virutalenv
84  # sys_py_bin = os.popen('which python3').read()
85  sys_py_bin = None
86  if 'cFsysPy3_cmd_hint_0' in os.environ and os.path.isfile(os.environ['cFsysPy3_cmd_hint_0']):
87  sys_py_bin = os.environ['cFsysPy3_cmd_hint_0']
88  elif 'cFsysPy3_cmd_hint_1' in os.environ and os.path.isfile(os.environ['cFsysPy3_cmd_hint_1']):
89  sys_py_bin = os.environ['cFsysPy3_cmd_hint_1']
90  elif os.path.isfile('/usr/bin/python3.8'):
91  sys_py_bin = '/usr/bin/python3.8'
92  elif os.path.isfile('/usr/bin/python3'):
93  sys_py_bin = '/usr/bin/python3'
94  else:
95  # as fallback, better than nothing
96  # returns the virtualenv python
97  sys_py_bin = os.popen('which python3').read()
98  return sys_py_bin
99 
100 
def get_sys_python_env()
Definition: gen_env.py:82
Here is the caller graph for this function:

◆ main()

def gen_env.main ( )

Definition at line 101 of file gen_env.py.

101 def main():
102  me_abs = os.path.dirname(os.path.realpath(__file__))
103  cfp_json_file = me_abs + __cfp_json_path__
104  with open(cfp_json_file, 'r') as json_file:
105  data = json.load(json_file)
106 
107  root_abs = os.path.realpath(me_abs+"/../")
108  data['abs_path'] = root_abs
109  sys_py_bin = get_sys_python_env()
110 
111  # check for virtualenv
112  cfenv_dir = os.path.abspath(root_abs + __cfenv_path_from_root__)
113  if not os.path.isdir(cfenv_dir) or not os.path.isfile("{}/bin/activate".format(cfenv_dir)):
114  # delete it, to be sure
115  os.system("rm -rf {}".format(cfenv_dir))
116  # creating it
117  print("[INFO] the python virutalenv for this project on this machine is missing, installing it...")
118  os.system('cd {}; virtualenv -p {} {}'
119  .format(os.path.abspath(cfenv_dir + '/../'), sys_py_bin, __cfenv_small_name__))
120  os.system('/bin/bash -c "source {}/bin/activate; pip install {}"'.format(cfenv_dir, __cfenv_req_packages__))
121 
122  data['cfenvPath'] = cfenv_dir
123  data['sysPython3Bin'] = sys_py_bin
124 
125  for e in __mandatory_keys__:
126  if e not in data.keys():
127  print_incomplete("The mandatory key {} is missing.".format(e))
128 
129  env_file = me_abs + __env_file_name__
130 
131  # first, check the timestamps
132  if os.path.exists(env_file):
133  json_time = os.path.getmtime(cfp_json_file)
134  env_time = os.path.getmtime(env_file)
135 
136  if env_time >= json_time:
137  # the environment was already created...nothing to do
138  exit(0)
139 
140  with open(me_abs + "/machine_env.template", "r") as input, open(env_file, "w+") as outfile:
141  out = input.read()
142  for i in range(0, len(__match_regex__)):
143  out = re.sub(re.escape(__match_regex__[i]), data[__replace_regex__[i]], out)
144 
145  if 'additional_lines' in data.keys():
146  out += '\n\n'
147  for e in data['additional_lines']:
148  new_line = str(e) + '\n'
149  out += new_line
150  out += '\n\n'
151 
152  outfile.write(out)
153 
154  os.system("chmod +x {}".format(env_file))
155 
156 
def main()
Definition: gen_env.py:101
def print_incomplete(msg="")
Definition: gen_env.py:74
Here is the call graph for this function:

◆ print_incomplete()

def gen_env.print_incomplete (   msg = "")

Definition at line 74 of file gen_env.py.

74 def print_incomplete(msg=""):
75  me_abs = os.path.realpath(__file__)
76  cfp_json_file = os.path.abspath(me_abs + __cfp_json_path__)
77  print("The project describing file {} is invalid.\n{}\n".format(cfp_json_file, msg) +
78  "Please use 'cFBuild update' to fix this project setup.")
79  exit(1)
80 
81 
Here is the caller graph for this function: