Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Describe how to use pip-tools with Flask and setup.py #787

Closed
slykar opened this issue Apr 17, 2019 · 6 comments
Closed

Describe how to use pip-tools with Flask and setup.py #787

slykar opened this issue Apr 17, 2019 · 6 comments
Labels
docs Documentation related

Comments

@slykar
Copy link
Contributor

slykar commented Apr 17, 2019

It's not very clear how you should use pip-compile when developing a Flask application.

In order to properly package a Flask application you need to create a setup.py file.
You then install it using python setup.py develop to start working with the code.

How I'm dealing with this:

  1. define requirements in setup.py
  2. Run pip-compile to generate requirements.txt file
  3. Run pip install -r requirements.txt -e . to install pinned packages and Flask app in editable mode

It took me some time to figure this out (and stick to it), as I was trying too hard to make this work by just specifying -r requirements.txt and placing -e . in either requirements.txt file by hand or adding this to requirements.in.

I think it might be useful to add an example usage like this, since you are using Flask in your examples anyway and it might be hard for newbies to figure this out.

@atugushev
Copy link
Member

Hello @slykar

3. Run pip install -r requirements.txt -e . to install pinned packages and Flask app in editable mode

Why not pip-sync && pip install -e .?

I think it might be useful to add an example usage like this, since you are using Flask in your examples anyway and it might be hard for newbies to figure this out.

IMO the pip-tools is supposed to work only with app's dependencies. If you want to install dependencies - just pip-sync. If you want to instal app in editable mode for a local development, simple use pip install -e ..

@slykar
Copy link
Contributor Author

slykar commented Apr 19, 2019

Hi @atugushev

I completely agree that pip-tools should only install app deps. What I wanted to say, is that maybe there should be some sort of a cookbook on how to use pip-tools in different setups.

You have an example on homepage which is great, but it's more about showing how pip-tools work rather than focusing on any particular setup. I understand that maybe pip-tools as a generic tool should not concern itself with the setup it's used in, but providing a set of context specific examples is usually a great way to introduce new people to the tool.

I get questions like "How do I use it with Flask?" or "How do I use it with Django?" from colleagues I show pip-tools to. I thought why not describe it at source. A GitHub wiki would work fine.

I think I saw some other issues related to managing dev and prod dependencies on the issue tracker here, so it seems people are having some confusions / ideas / questions about using pip-tools in different scenarios.


About my workflow.

I'm usually putting pip-tools as a dev dependency in the setup.py, so first time install is always pip install -r requirements.txt -e .[dev].

When running in Docker i just run pip install -r requirements.txt -e . to install a Flask application.

The pip-sync is what I would use during development, but I can't use it alone, because it will wipe my dev dependencies, so I don't use it at all. I know I could pin dev deps too, but I want them to be most recent.

That's not the point tough :)

@atugushev
Copy link
Member

@slykar,

It's a good idea to have a cookbook for some of scenarios. Contributions are always welcomed :)

@atugushev atugushev added the docs Documentation related label Apr 21, 2019
@atugushev
Copy link
Member

Btw, why do you use setup.py for Flask app?

I recommend to read this nice article https://caremad.io/posts/2013/07/setup-vs-requirement/ about when you should use setup.py or requirements.txt. Looks like you should use requirements.txt, not setup.py.

@slykar
Copy link
Contributor Author

slykar commented Sep 7, 2019

I could use requirements.txt with -e . in it, but pip-compile evaluates -e . from requirements.in file to a full local system path and this would make the generated requirements.txt file non transferable between environments.

# requirements.in
-e .
# generated with pip-compile: requirements.txt
-e file:///Users/slykar/projects/flask_sample

Without installing your Flask application you won't be able to import it. So you either have to create a setup.py file to install your app or fiddle with Python paths like Django does.

Using setup.py is recommended by Flask for larger apps: https://flask.palletsprojects.com/en/1.1.x/patterns/packages/

Using setup.py is also a standard way if you use a Pyramid framework. It's most likely a standard way for any other framework that is not Django.

Maybe instead of creating a guideline for other frameworks pip-compile should just fix the support for -e .

@atugushev
Copy link
Member

atugushev commented Oct 17, 2019

@slykar

Maybe instead of creating a guideline for other frameworks pip-compile should just fix the support for -e .

+1 on the fix. I'll link this to the #204 and close the issue then. Feel free to reopen it if you have any other issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation related
Projects
None yet
Development

No branches or pull requests

2 participants