Repo for the Python functions of Nachbarschaftstrom.
- Get the source code:
sudo apt-get update -y
git clone https://github.com/tomasruizt/tms-nachbarstrom-python
cd tms-nachbarstrom-python/
- Prepare a folder for the credentials:
mkdir cred
- If running on Azure, you can find a machine address e.g. 'the-machine-address' to connect to.
- Put the Google service credentials on the server. For example, by copying them from your machine to the server:
scp -i private_key google_service_credentials.json
the-machine-address:~/tms-nachbarstrom-python/cred
- Run the setup script for 'Ubuntu 16.04 LTS', or follow its steps, if you are on another platform.
bash install_environment.sh
- Your new Python environment is located in the 'env-prod/' folder.
- Activate your Python environment. If you are on Windows, replace the command with 'env-prod/Scripts/activate'.
source env-prod/bin/activate
- Set your environment variables, for example API keys.
- Finally, you can start the server either in 'production' mode or in 'develop' mode.
For production:
nohup sudo --preserve-env $(which python3) -m nachbarstrom.inference.web_server.app >>logs 2>>logs &
- Here
preserve-envis used to keep the environment variables when usingsudo. - We use
-mto call theapp.pyas a module. >>logs 2>>logsredirects all output to thelogsfile.- The
&command detaches the process from the command line.
For development:
sudo --preserve-env $(which python3) -m nachbarstrom.inference.web_server.app --develop
Make sure your Python environment is active.
- Run unit tests. The option 'rs' stands for report skipped.
python -m pytest -rs
- Integration tests: Usually launched on the 'develop', but not necessarily.
python -m pytest -rs --integration
sudo killall python3
Lint the code:
pylint app.pyUse static type checker:
mypy --ignore-missing-imports app.py