API_Py  0.0.2
API_Py exporte le projet API vers un module python dans l’environnement python choisi. Le module python se nomme wxcpppy.
wxcpppyconfig.py
1 # Copyright 20018-2019 wxCppPy. All Rights Reserved.
2 # Licensed to MIT see LICENSE.txt
3 
4 import os
5 import sys
6 import argparse
7 # https://docs.python.org/3/library/configparser.html
8 import configparser
9 import sysconfig
10 
11 
13  """
14  Définition des chemins pour compiler wxCppPy.
15 
16  pyenv_path (str): Le chemin du répertoire de l'environement python.
17  pyenv_sp_path (str): Le chemin du répertoire «site-packages» dans l'environement python.
18  pyenv_include_path (str): Le chemin du répertoire «include/pythonx.yz» dans l'environement python.
19  pyenv_version (str): La version de python ex : 35m
20  pybind11_path (str): Le chemin du répertoire de pybind11.
21  wxpython_path (str): Le chemin du répertoire de wxpython.
22  cppclay_path (str): Le chemin du répertoire de cppclay..
23  cppclaydll_path (str): Le chemin du répertoire des «.dll»/«.so» de cppclay.
24  """
25 
26  ms_Filename = 'config.cfg'
27 
28  def __init__(self):
29  wxcpppy_config = configparser.ConfigParser()
30  wxcpppy_config.read(WXCppPyConfig.ms_Filename)
31 
32  py_version_short = sysconfig.get_config_var('py_version_short')
33 
34  self.pyenv_path = sysconfig.get_config_var('installed_base')
35  self.pyenv_sp_path = self.pyenv_path + '/lib64/python' + py_version_short + '/site-packages'
36  self.pyenv_include_path = self.pyenv_path + '/include/python' + py_version_short + sys.abiflags
37  self.pyenv_ext_suffix = WXCppPyConfig.get_extersion_suffix()
38  self.pybind11_path = wxcpppy_config['pybind11']['path']
39  self.wxpython_path = wxcpppy_config['wxpython']['path']
40  self.cppclay_path = wxcpppy_config['cppclay']['path']
41  self.cppclaydll_path = wxcpppy_config['cppclay']['dll_path']
42 
43  @staticmethod
44  def get_extersion_suffix():
45  # https://stackoverflow.com/questions/42020937/why-pyvenv-does-not-install-python-config
46  ext_suffix = sysconfig.get_config_var('EXT_SUFFIX')
47  if ext_suffix is None:
48  ext_suffix = sysconfig.get_config_var('SO')
49 
50  return ext_suffix
51 
52 
53 # https://stackoverflow.com/questions/11415570/directory-path-types-with-argparse
54 class ReadableDir(argparse.Action):
55  def __call__(self, parser, namespace, values, option_string=None):
56  prospective_dir = values
57  if not os.path.isdir(prospective_dir):
58  raise argparse.ArgumentTypeError("readable_dir:{0} is not a valid path".format(prospective_dir))
59  if os.access(prospective_dir, os.R_OK):
60  setattr(namespace, self.dest, prospective_dir)
61  else:
62  raise argparse.ArgumentTypeError("readable_dir:{0} is not a readable dir".format(prospective_dir))
63 
64 
65 def main():
66  parser = argparse.ArgumentParser(description='Définition des chemins pour compiler wxCppPy.')
67 
68  parser.add_argument('--pybind11_path', action=ReadableDir, required=True,
69  help="Le chemin du répertoire de pybind11.")
70 
71  parser.add_argument('--wxpython_path', action=ReadableDir, required=True,
72  help="Le chemin du répertoire de wxpython.")
73 
74  parser.add_argument('--cppclay_path', action=ReadableDir, required=True,
75  help="Le chemin du répertoire de cppclay.")
76 
77  parser.add_argument('--cppclaydll_path', action=ReadableDir, required=True,
78  help="Le chemin du répertoire des «.dll»/«.so» de cppclay.")
79 
80  args = parser.parse_args()
81 
82  wxcpppy_config = configparser.ConfigParser()
83 
84  wxcpppy_config['pybind11'] = {'path': args.pybind11_path}
85 
86  wxcpppy_config['wxpython'] = {'path': args.wxpython_path}
87 
88  wxcpppy_config['cppclay'] = {'path': args.cppclay_path,
89  'dll_path': args.cppclaydll_path}
90 
91  with open(WXCppPyConfig.ms_Filename, 'w') as configfile:
92  wxcpppy_config.write(configfile)
93 
94 
95 if __name__ == "__main__":
96  main()
97 
98  config = WXCppPyConfig()
99 
100  print('============================================================================')
101  print('wxCppPy Config:')
102  print('pyenv_path : ' + config.pyenv_path)
103  print('pyenv_sp_path : ' + config.pyenv_sp_path)
104  print('pyenv_include_path : ' + config.pyenv_include_path)
105  print('pyenv_ext_suffix : ' + config.pyenv_ext_suffix)
106  print('pybind11_path : ' + config.pybind11_path)
107  print('wxpython_path : ' + config.wxpython_path)
108  print('cppclay_path : ' + config.cppclay_path)
109  print('cppclaydll_path : ' + config.cppclaydll_path)
110  print('============================================================================')