Skip to content

naeem-bebit/data-project

Repository files navigation

Python application

Run flask locally

  1. Activate the virtual environment

    Install virtualenv if not available

    pip install virtualenv
    python3 -m venv env or python -m venv env
    source env/bin/activate

    Or

    . env/bin/activate

    Windows (Command Prompt)

    virtualenv myenv  ##(name of the env)
    myenv\Scripts\activate
    env\Scripts\activate.bat

    To check Python environment (Windows)

    where python
    C:\Users\..\..\env\Scripts\python.exe
    C:\Users\..\AppData\Local\Programs\Python\Python310\python.exe
    C:\Users\..\AppData\Local\Microsoft\WindowsApps\python.exe

    To list all installed packages

    pip list
  2. To delete virtual environment

    rmdir env /s
  3. To deactivate the virtual environment

    deactivate
  4. Install requirements

    pip3 install -r requirements.txt
  5. Get packages from main Python environment

    python -m venv env --system-site-packages

    Check for local Python packages

    pip list --local
  6. Setting up the flask development environment

    export FLASK_ENV=development
    export FLASK_APP=/src/app.py #optional
  7. Run app locally

    FLASK_APP=src/app.py flask run

    Or

    python -m flask run

    Or

    flask run
    flask --app app(name of the file) run --debug #auto reload

    The server will be up on http://127.0.0.1:5000/

  8. Run tests

    Specify the folder tests

    python -m pytest tests

    Or It will look recurcisvely for the test_*.py files

    python -m pytest

    Or

    py.test -v
  9. Flake8 settings

    .flake8 used by Github Actions .github/workflows/lint-test.yaml

  10. pipreqs for requirements

  11. Docker build and docker run

    docker build -t flask_app:v1 .
    docker run flask_app
    docker container run -d -p 5000:5000 flask_app:v1
  12. Check for Dockerfile Linter

    docker run --rm -i hadolint/hadolint < Dockerfile
  13. Docker debug

    docker container prune # to remove existing containers.
    docker-compose build --no-cache # to rebuild docker images.
    docker-compose up --build --force-recreate
    docker stop $(docker ps -aq) # to stop all running dockers
    docker ps # to list of all running dockers
    docker run -p 5000:5000 docker_image # to run on port 5000
  14. Docker verify installation

    docker run --name repo alpine/git clone https://github.com/docker/getting-started.git
    cd getting-started
    docker build -t docker101tutorial .
    docker run -d -p 80:80 --name docker-tutorial docker101tutorial
    docker tag docker101tutorial naeem15/docker101tutorial
    docker push naeem15/docker101tutorial
  15. Typescript setting

    tsc main.ts --outFile ../js/main.js --watch
  16. Sass

    sass --watch main.sass ../css/main.css
  17. Conda (windows)

    conda create --name env_name python=3.11
    conda activate env_name
    conda deactivate

References

About

Project Flask

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •