Handling usage functions in python

In our current c-project, we use python scripts for support and testing, such as unit testing, integration testing, benchmarking and communication.

The structure of the current folder (most files are not shown):

.
|-- workingcopy1
|-- |-- config
|-- |-- |-- __init__.py
|-- |-- |-- parameters_one.py
|-- |-- |-- parameters_two.py
|-- |-- |-- parameters_three.py
|-- |-- src
|-- |-- |-- main_application_c_code.c
|-- |-- tests
|-- |-- |-- tools
|-- |-- |-- |-- display_communication_activity.py
|-- |-- |-- run_all_unit_tests.py
|-- |-- tools
|-- |-- |-- script1.py
|-- |-- |-- script2.py
|-- |-- |-- script3.py
|-- |-- utils
|-- |-- |-- python_utils
|-- |-- |-- |-- __init__.py
|-- |-- |-- |-- communication_utils.py
|-- |-- |-- |-- conversion_utils.py
|-- |-- |-- |-- constants.py
|-- |-- |-- |-- time_utils.py
|-- workingcopy2
...
|-- workingcopy3
...

Some python files are intended to be executed as script ( $ python script1.py) files , and some of them are intended to be included in modules in other python files.

What we would like to achieve is a structure that allows us to have parameter functions and functions that can be used:

  • Test code
  • Other Utility Codes
  • A smaller python application used to monitor our system. That is, custom benchmarking tools

It should also be possible to check multiple working copies.

:

import os, sys
current_path = os.path.abspath(os.path.dirname(__file__))
sys.path.append(os.path.join(current_path, '..', 'utils')) # Variates depending on script location in file tree
sys.path.append(os.path.join(current_path, '..', 'config')) # Variates depending on script location in file tree
import python_utils.constants as constants
import config.parameters_one as parameters

20 + script . ?

+4
1

Python, __init__.py.

, Python shebang, Python ( #! (shebang) Python ?).

, , . , (virtualenv), (http://docs.python-guide.org/en/latest/dev/virtualenvs/) (, , virtualenvwrapper, )

, : python , , script , , . , "" , .

pre-post virtualenvwrapper hooks.

+3

All Articles