- Project Structure
- Project Requirements
- How-To: Execute the Code
- How-To: Include HackMob Modules
- How-To: Comment Python Code
- How-To: Create Absolute Paths
It's mandatory that you respect the structure of the project. The folders are:
- docs/: autogenerated documentation of the
hackmob
package. - hackmob/: main package of the project. All the modules (in Python, every .py file is a module) must be inside this folder. ONLY FUNCTIONAL CODE MUST BE UPLOADED HERE
- hackmob_tests/: tests package of the project. Code in this folder will not be uploaded to GitHub. Use this package to make every test you want.
- img/: folder to store the images of the people in the face recognition database.
- models/: deep learning models used in the project.
- res/: folder to place resource files, like SQLite Databases.
We will use Python 3.6 to develop this project. The list of dependencies so far is:
numpy
, opencv-python
To install dependencies using pip
use the following syntax:
pip3 install dependency_name
We will use the __main__.py
file to execute the hackmob
package.
Move to the root folder and execute:
python3 hackmob
We need to modify the default execution behavior. To do that:
- Go to
Run -> Edit Configurations
- Click the + icon and select "Python".
- Change "Script path" by "Module name" and set it to "hackmob".
- Uncheck the "Show command line afterwards" option (if checked).
If you want to execute a test module execute it as you always do. If it doesn't work tell me
To include modules of the hackmob
package we must use the following notation:
from hackmob.my_module include MyClass
We can access modules from the hackmob_tests
package as well:
from hackmob_tests.my_test_module include MyClass
Remember that the project folder must be in the $PYTHONPATH environment variable.
In order to create the documentation automatically, certain comment rules must be followed. The Sphinx Domain is the standard way to comment Python Code. An example of a commented function is:
def compute_sum(a,b):
"""
Computes the sum of the input values
:param a: first number
:param b: second number
:return: sum of the numbers
"""
return a + b
It's a good practice to use absolute paths to avoid problems. Python provides the os.path
package to work with paths. We will use two main functions:
os.path.dirname(file_path)
: returns the absolute path of the directy containing the file.os.path.join(path, *paths)
: joins various paths.
For example, if we want to load an image from the img/ path from the hackmob/main.py, we can obtain the absolute with the command:
image_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'img', 'image_name.png')
Where __file__
would return the absolute path of the executed file. Notice that we have to use two os.path.dirname
.