pydatabangalore / talks

Talks at PyData Bangalore meetups
MIT License
36 stars 11 forks source link

Learn Pipenv for great good! #13

Closed ultimatecoder closed 5 years ago

ultimatecoder commented 5 years ago

Learn Pipenv for great good

Description

Pipenv is a development workflow for humans. Pipenv isolates python dependencies in an dedicated environment. It is a higher level wrapper over virtualenv and virtualenvwrapper. Advantage of Pipenv compared to other tools is its simplicity and delicacy. Learning Pipenv is an investment of a few minutes which paybacks as a saving of handsome amount of time to manage dependencies.

Duration

Audience

Anyone who is developing applications using Python

Outline

Installing Pipenv

pip install pipenv

Example Flask app for demonstration (app.py)

#! /usr/bin/env python
# -*- coding: utf-8 -*-

from flask import Flask

app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello world!"

Installing a new package

pipenv install flask

Installing developer dependencies

pipenv install --dev pytest

Pipfile

This file will maintain an meta information of package. This includes information like name of the package, url, dependencies and version of Python it is dependent on.

Example

[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
pytest = "*"

[packages]
flask = "*"

[requires]
python_version = "3.7"

You should commit this file in your version control system of choice.

Pipfile.lock

I am not sharing it as an example here because it will contain too many values of package and its meta package. This tool tracks packages by its hash value. Every time when new version is available, it updates it automatically and regenerate lock file. You should commit this file at your preferred version control system.

Using an installed packages

pipenv run flask run

Installing developer dependencies

pipenv install --dev pytest

Spawn an virtual environment

pipenv shell

Graph of dependency

pipenv graph

Checking safety of the package

pipenv check

Command to make build at anywhere

pipenv install

This command checks a safety of installed package using PEP 508.