Skip to content
This repository has been archived by the owner on Jun 10, 2021. It is now read-only.

drkostas/template_python_project

Repository files navigation

Template Python Project

CircleCI GitHub license

Table of Contents

About

This is a template repository for python projects.

This README serves as a template too. Feel free to modify it until it describes your project.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

You need to have a machine with Python > 3.6 and any Bash based shell (e.g. zsh) installed.

$ python3.6 -V
Python 3.6.9

echo $SHELL
/usr/bin/zsh

You will also need to setup the following:

Set the required environment variables

In order to run the main.py or the tests you will need to set the following environmental variables in your system:

$ export DROPBOX_API_KEY=<VALUE>
$ export MYSQL_HOST=<VALUE>
$ export MYSQL_USERNAME=<VALUE>
$ export MYSQL_PASSWORD=<VALUE>
$ export MYSQL_DB_NAME=<VALUE>
$ export EMAIL_ADDRESS=<VALUE>
$ export GMAIL_API_KEY=<VALUE>

Installing, Testing, Building

All the installation steps are being handled by the Makefile.

If you don't want to go through the setup steps and finish the installation and run the tests, execute the following command:

$ make install server=local

If you executed the previous command, you can skip through to the Running locally section.

Check the available make commands

$ make help

-----------------------------------------------------------------------------------------------------------
                                              DISPLAYING HELP                                              
-----------------------------------------------------------------------------------------------------------
make delete_venv
       Delete the current venv
make create_venv
       Create a new venv for the specified python version
make requirements
       Upgrade pip and install the requirements
make run_tests
       Run all the tests from the specified folder
make setup
       Call setup.py install
make clean_pyc
       Clean all the pyc files
make clean_build
       Clean all the build folders
make clean
       Call delete_venv clean_pyc clean_build
make install
       Call clean create_venv requirements run_tests setup
make help
       Display this message
-----------------------------------------------------------------------------------------------------------

Clean any previous builds

$ make clean server=local
make delete_venv
make[1]: Entering directory '/home/drkostas/Projects/template_python_project'
Deleting venv..
rm -rf venv
make[1]: Leaving directory '/home/drkostas/Projects/template_python_project'
make clean_pyc
make[1]: Entering directory '/home/drkostas/Projects/template_python_project'
Cleaning pyc files..
find . -name '*.pyc' -delete
find . -name '*.pyo' -delete
find . -name '*~' -delete
make[1]: Leaving directory '/home/drkostas/Projects/template_python_project'
make clean_build
make[1]: Entering directory '/home/drkostas/Projects/template_python_project'
Cleaning build directories..
rm --force --recursive build/
rm --force --recursive dist/
rm --force --recursive *.egg-info
make[1]: Leaving directory '/home/drkostas/Projects/template_python_project'

Create a new venv and install the requirements

$ make create_venv server=local
Creating venv..
python3.6 -m venv ./venv

$ make requirements server=local
Upgrading pip..
venv/bin/pip install --upgrade pip wheel setuptools
Collecting pip
.................

Run the tests

The tests are located in the tests folder. To run all of them, execute the following command:

$ make run_tests server=local
source venv/bin/activate && \
.................

Build the project locally

To build the project locally using the setup.py command, execute the following command:

$ make setup server=local
venv/bin/python setup.py install '--local'
running install
.................

Running the code locally

In order to run the code now, you will only need to change the yml file if you need to and run either the main or the created console script.

Modifying the Configuration

There is an already configured yml file under confs/template_conf.yml with the following structure:

tag: production
cloudstore:
  config:
    api_key: !ENV ${DROPBOX_API_KEY}
  type: dropbox
datastore:
  config:
    hostname: !ENV ${MYSQL_HOST}
    username: !ENV ${MYSQL_USERNAME}
    password: !ENV ${MYSQL_PASSWORD}
    db_name: !ENV ${MYSQL_DB_NAME}
    port: 3306
  type: mysql
email_app:
  config:
    email_address: !ENV ${EMAIL_ADDRESS}
    api_key: !ENV ${GMAIL_API_KEY}
  type: gmail

The !ENV flag indicates that a environmental value follows. You can change the values/environmental var names as you wish. If a yaml variable name is changed/added/deleted, the corresponding changes should be reflected on the Configuration class and the yml_schema.json too.

Execution Options

First, make sure you are in the created virtual environment:

$ source venv/bin/activate
(venv) 
OneDrive/Projects/template_python_project  dev 

$ which python
/home/drkostas/Projects/template_python_project/venv/bin/python
(venv) 

Now, in order to run the code you can either call the main.py directly, or the template_python_project console script.

$ python main.py --help
usage: main.py -m {run_mode_1,run_mode_2,run_mode_3} -c CONFIG_FILE [-l LOG]
               [-d] [-h]

A template for python projects.

required arguments:
  -m {run_mode_1,run_mode_2,run_mode_3}, --run-mode {run_mode_1,run_mode_2,run_mode_3}
                        Description of the run modes
  -c CONFIG_FILE, --config-file CONFIG_FILE
                        The configuration yml file
  -l LOG, --log LOG     Name of the output log file

optional arguments:
  -d, --debug           enables the debug log messages

# Or

$ template_python_project --help
usage: template_python_project -m {run_mode_1,run_mode_2,run_mode_3} -c
                               CONFIG_FILE [-l LOG] [-d] [-h]

A template for python projects.

required arguments:
  -m {run_mode_1,run_mode_2,run_mode_3}, --run-mode {run_mode_1,run_mode_2,run_mode_3}
                        Description of the run modes
  -c CONFIG_FILE, --config-file CONFIG_FILE
                        The configuration yml file
  -l LOG, --log LOG     Name of the output log file

optional arguments:
  -d, --debug           enables the debug log messages
  -h, --help            Show this help message and exit

Deployment

The deployment is being done to Heroku. For more information you can check the setup guide.

Make sure you check the defined Procfile (reference) and that you set the above-mentioned environmental variables (reference).

Continuous Integration

For the continuous integration, the CircleCI service is being used. For more information you can check the setup guide.

Again, you should set the above-mentioned environmental variables (reference) and for any modifications, edit the circleci config.

TODO

Read the TODO to see the current task list.

Built With

License

This project is licensed under the GNU License - see the LICENSE file for details.

Acknowledgments