Pipenv: generate pip {dev-}requirements.txt from Pipfile.lock

Created on 25 Jan 2017  路  7Comments  路  Source: pypa/pipenv

Maybe add argument to pipenv lock --gen-pip-lockfiles(or something similar) which would generate both files automatically after vendoring. This is a must for external tools(or Heroku for example), for building packages etc ...

Quick invoke task for those who stumble upon this

@task
def vendor(ctx):
    with io.open('Pipfile.lock') as f:
        data = json.load(f)
        prod = []
        dev = []
        for name, meta in data['develop'].items():
            dev.append('{}{}'.format(name, meta['version']))
        for name, meta in data['default'].items():
            prod.append('{}{}'.format(name, meta['version']))

    with io.open('requirements.txt', 'wt') as r:
        r.truncate(0)
        r.seek(0)
        r.write(u'\n'.join(sorted(prod)))
    with io.open('dev-requirements.txt', 'wt') as r:
        r.truncate(0)
        r.seek(0)
        r.write(u'\n'.join(sorted(dev)))

Most helpful comment

This is now possible: pipenv lock --requirements will produce a requirements file for the non-dev requirements and pipenv lock --requirements --dev will produce one for just the dev requirements.

All 7 comments

we already have $pip install --requirements :)

@kennethreitz can you explain what you mean by this?

I get

$ pip install --requirements

Usage:
  pip install [options] <requirement specifier> [package-index-options] ...
  pip install [options] -r <requirements file> [package-index-options] ...
  pip install [options] [-e] <vcs project url> ...
  pip install [options] [-e] <local project path> ...
  pip install [options] <archive url/path> ...

no such option: --requirements

As far as I can tell there's no way to get separate requirements.txt files with and without dev dependencies

@frankh, this was a typo at the time, it should have been pipenv install --requirements. However, we've also changed this since then. The current version of pipenv will provide requirements with the command pipenv lock --requirements.

In response to the second question, no, there isn't currently a way to divide requirements.txt dependencies between dev and default.

This is now possible: pipenv lock --requirements will produce a requirements file for the non-dev requirements and pipenv lock --requirements --dev will produce one for just the dev requirements.

It'd be ultra convenient if the generated requirements file contained the index-url directives, for packages that come from alternate sources.

For example, the example from the docs:

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

[[source]]
url = "http://pypi.home.kennethreitz.org/simple"
verify_ssl = false
name = "home"

[dev-packages]

[packages]
requests = {version="*", index="home"}
maya = {version="*", index="pypi"}
records = "*"

could output this following with pipenv lock --requirements

--index-url http://pypi.home.kennethreitz.org/simple
requests==1.2.3

--index-url https://pypi.python.org/simple
maya==2.3.4
records==3.4.5

In keeping with the idea that the Pipfile.lock, like the requirements.txt file it replaces, is specifying not just which packages and versions you should be installing, but from where to get them.

@triplepoint see #1980

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jerzyk picture jerzyk  路  3Comments

Californian picture Californian  路  3Comments

jeyraof picture jeyraof  路  3Comments

erinxocon picture erinxocon  路  3Comments

bgjelstrup picture bgjelstrup  路  3Comments