On Thu, Oct 13, 2016 at 7:27 AM, Arthur Goldberg <artgoldb...@gmail.com> wrote:
> We're building utilities to create portable test environments on a
> continuous integration and delivery platform (CircleCI). We want our
> packages to run on Python 2 and 3 (2.7 and 3.5, currently). We've developed
> build utilities that creates these environments, runs tests, and then saves
> the results.
> We use pip to create environments from requirements.txt files in the
> packages. But I'm finding it tricky to use pip and obtain good error
> handling. For example, this approach
> with open('requirements.txt', 'r') as file:
> reqs = [line.rstrip() for line in file.readlines()]
> pip.main(['install'] + reqs)
> raises exceptions for lines in requirements.txt that just contain comments.
> Is there a recommended way to use pip, especially pip install, from within a
> program and obtain good error handling?
I think the only supported option is
subprocess.run(["pip", "install", "-r", "requirements.txt"])
though I suppose you could try passing that to pip.main as well.
Nathaniel J. Smith -- https://vorpus.org