- About The Project
- Getting Started
- Getting Started With Docker
- Unit Testing
- Usage
- Contributing
- Contact
- Acknowledgments
This project is the part of the Innopolis University DevOps course. The aim of the project is to get acquainted with the Python best practices and frameworks for developing web applications using the example of a small web application that shows the current time in Moscow.
Following the instructions below, you can create a local copy of the project and run the Time web application, which will show the current time in Moscow.
My main development environment is Visual Studio Code, so all further steps will be determined to work in this particular IDE. If you do not have VS Code installed, then you can download it from this !link or use this tutorial to get started with Flask if you want to use any other development environment.
-
Install the Python extension to VS Code.
-
Make sure that you have. You can download from python.org.
-
On Windows, make sure the location of your Python interpreter is included in your PATH environment variable. You can check the location by running
path
at the command prompt. If the Python interpreter's folder isn't included, open Windows Settings, search for "environment", select Edit environment variables for your account, then edit the Path variable to include that folder. -
Make sure you have already installed both Docker Engine and Docker Compose. You don’t need to install Python or Redis, as both are provided by Docker images.
Run this command in your Terminal to clone the repository:
git clone https://github.com/Amina19058/DevOps.git
cd DevOps
git checkout lab3
At this point, you will activate your Python environment and install Flask using the pip
package installer.
-
Open VS Code, make sure that you are in the project directory.
-
Open the Command Palette (View > Command Palette. Then select the Python: Select Interpreter command. From the presented list, select the virtual environment in your project folder that starts with
./.venv
or.\.venv
. -
Run Terminal: Create New Terminal from the Command Palette.
-
Use the following command to create and activate a virtual environment named
.venv
based on your current interpreter:# Linux sudo apt-get install python3-venv python3 -m venv .venv source venv/bin/activate # macOS python3 -m venv .venv source venv/bin/activate # Windows py -3 -m venv .venv venv\scripts\activate
-
Also in the Terminal, run the following command to update
pip
:python3 -m pip install --upgrade pip
-
Then, run this to install the requirements:
python3 -m pip install -r requirements.txt
-
Move to code directory:
cd src
-
Run the app.py by
python3 -m flask run
, which runs the Flask development server. The development server looks forapp.py
by default. When you run Flask, you should see output similar to the following:(venv) amina@Aminas-MacBook-Air src % python3 -m flask run * Debug mode: off WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Running on http://127.0.0.1:5000 Press CTRL+C to quit
If you see an error that the Flask module cannot be found, make sure you've run
python3 -m pip install flask
in your virtual environment as described at the end of the previous section. -
See the result on
http://127.0.0.1:5000
. You also can use the Live Server in VSCode. -
Stop the app by using
Ctrl+C
in the terminal.
Before running the application, please install all the prerequisites:
-
Make sure you have already installed both Docker Engine and Docker Compose. You don’t need to install Python or Flusk, as both are provided by Docker images.
-
Run this command in your Terminal to clone the repository:
git clone https://github.com/Amina19058/DevOps.git
cd DevOps
git checkout lab3
-
In the project directory open the Terminal and start up the application by running:
docker-compose build docker-compose up
-
See the result on
http://127.0.0.1:8000
. -
Stop the app by using
Ctrl+C
in the terminal.
-
Make sure that you are in the application directory:
cd DevOps
-
Run the tests:
pytest .
Best practices of Unit Testing are also described in PYTHON.md
You can use this project for educational purposes. All the steps above allow you to launch an application that shows the current time in Moscow.
During their execution, you will learn how to create and activate a virtual environment, install Flask and develop simple web applications.
Also, in the PYTHON.md file you can find information about the best Python and Unit Testing practices, the advantage of Flask, why to use linters.
And in the DOCKER.md file you can find information about the best Dockerfile practices, what linters to use.
I will gladly accept any contributions you make, as we will be able to make this project better together. Moreover, each of us will gain incredible experience in creating web applications and the correct design of the project.
If you have a suggestion that would make this project better, do not hesitate to contact me or fork the repo and create a pull request.
Amina Khusnutdinova - [email protected]
Project Link: https://github.com/Amina19058/app_python
- 5 Python Best Practices That Every Programmer Should Follow
- Python Best Practices
- Code Style
- Python Best Practices
- Flask Tutorial
- Best Practices for Flask
- A Guide to Python Good Practices
- PEP 8 – Style Guide for Python Code
- Best-README-Template
- README Templates
- How to Write Beautiful Python Code With PEP 8
- Flask Tutorial in Visual Studio Code
- Создание веб-приложения с помощью Flask в Python 3
- shields.io