poetry icon indicating copy to clipboard operation
poetry copied to clipboard

Expose stable Python API

Open thejcannon opened this issue 5 years ago • 1 comments

  • [x] I have searched the issues of this repo and believe that this is not a duplicate.
  • [x] I have searched the documentation and believe that my question is not covered.

Feature Request

Howdy folks,

Our build system is mostly written in Python, so it'd be nice if I could consume poetry's CLI from Python.

As an example, I'd love to be able to do things like:

import poetry.poetry

project = poetry.poetry.Poetry("./my/path")
project.lock()  # Mirrors 'poetry lock'
project.add(...)  # I think you get the idea

(This would also be helpful for my test suites operating on fake projects, as I can generate them on-the-fly).

thejcannon avatar Nov 25 '20 14:11 thejcannon

As a more concrete example, I'm currently testing that our validation check errors if your lock file is out of date.

I've gathered from looking at the command implementations that setting up a project loosely looks like:

poetry.layouts.StandardLayout("bird-snake").create(tmp_path)
poetry = poetry.factory.Factory().create_poetry(str(tmp_path))
installer = poetry.installer.Installer(
    io,  # Oh no
    env,    # Oh geez
    poetry.package, 
    poetry.locker, 
    poetry.pool, 
    poetry.config,
)
installer.lock(update=False)
installer.run()

(Assuming I can find an io and env to pass 😄)

It'd be really cool if this was simply

poetry = poetry.layouts.StandardLayout("bird-snake").create(tmp_path)
poetry.lock()

thejcannon avatar Nov 25 '20 14:11 thejcannon