Poetry: Adding github dependency

Created on 17 Jul 2018  路  11Comments  路  Source: python-poetry/poetry

In the docs (https://poetry.eustace.io/docs/cli/#add) I see that you can add git dependency but when I tried this I got an error.

I've run this command poetry add --git https://github.com/karantan/[email protected] ansible and I got the following error:

Updating dependencies
Resolving dependencies... (47.5s)

[CalledProcessError]                                                                                                              
Command '['git', '--git-dir', '/var/folders/fk/39r4_x312jnb1qz_pv27jg280000gn/T/pypoetry-git-ansibletxy4by9n/.git', '--work-tree', '/var/fold  
ers/fk/39r4_x312jnb1qz_pv27jg280000gn/T/pypoetry-git-ansibletxy4by9n', 'checkout', 'master']' returned non-zero exit status 1.                 

add [-D|--dev] [--git GIT] [--path PATH] [-E|--extras EXTRAS] [--optional] [--python PYTHON] [--platform PLATFORM] [--allow-prereleases] [--dry-run] [--] <name> (<name>)...

So how can I install my ansible package that is tagged with v2.6.0.1?

CLI Feature

Most helpful comment

Seems like the syntax is actually supposed to be poetry add ansible --git https://github.com/karantan/ansible.

There no difference.

Im still trying to figure out how to specify the tag or a sha.

Unfortunately, there's no way to do it via CLI, but you can manually add an entry into your pyproject.toml like this:

[tool.poetry.dependencies]
python = "^3.6"
ansible = { git = "https://github.com/ansible/ansible.git", branch = "devel" }
# or
ansible = { git = "https://github.com/ansible/ansible.git", tag = "v2.6.6" }
# or
ansible = { git = "https://github.com/ansible/ansible.git", rev = "e5664c4" }

It should work.

All 11 comments

Seems like the syntax is actually supposed to be poetry add ansible --git https://github.com/karantan/ansible. Im still trying to figure out how to specify the tag or a sha.

Seems like the syntax is actually supposed to be poetry add ansible --git https://github.com/karantan/ansible.

There no difference.

Im still trying to figure out how to specify the tag or a sha.

Unfortunately, there's no way to do it via CLI, but you can manually add an entry into your pyproject.toml like this:

[tool.poetry.dependencies]
python = "^3.6"
ansible = { git = "https://github.com/ansible/ansible.git", branch = "devel" }
# or
ansible = { git = "https://github.com/ansible/ansible.git", tag = "v2.6.6" }
# or
ansible = { git = "https://github.com/ansible/ansible.git", rev = "e5664c4" }

It should work.

Do you have plans to improve adding git dependencies via CLI?
Like poetry add --git https://github.com/Rapptz/discord.py.git --branch rewrite or poetry add --git https://github.com/Rapptz/discord.py.git@rewrite?

Solution by @narimanizett works perfectly fine, but better CLI would be great. :)

@nariman @sdispater Is it possible to add dependency to git with category being set to dev?

We have a library that is our dev dependency i.e.

[tool.poetry.dev-dependencies]
moto = { git = "https://github.com/spulec/moto.git", branch = "master" }

now plugin which we use to deploy project to aws lambda uses export function.

Problem is that when you have dependency to git branch added manually, default category in poetry.lock is being set to main.

And when serverless-python-requirements plugin uses export command it includes also dev dependency, because locker includes packages with main category.

I've tried to set category manually as well with:

moto = { git = "https://github.com/spulec/moto.git", branch = "master", category="dev" }

But that didn't help, category is still being set to main. Any suggestions? Or maybe I am just looking at it from wrong angle?

The add command will be improved in the next 1.0.0 release (see https://github.com/sdispater/poetry/pull/1221). For instance, to use the original example, it will now be possible with the following syntax:

poetry add git+https://github.com/karantan/[email protected]

@sdispater will it also work with setting git repository URL as dev dependency?
I've mentioned about it in https://github.com/sdispater/poetry/issues/313#issuecomment-480913093

Has this been silently removed in 1.0.0b7?

[RuntimeError]
The Poetry configuration is invalid:
  - [dependencies.myproject] {'git': 'ssh://[email protected]/myproject.gi', 'tags': '0.47.0'} is not valid under any of the given schemas

Hello @Granitosaurus,

I see two issues:

  1. The section must be named [tool.poetry.dependencies] and not [dependencies.myproject]
  2. tags must be renamed to tag

fin swimmer

@finswimmer Thanks, tags instead of tag was indeed a typo of mine, no idea how it got there though. That being said it would be nice if the error message would be more verbose as debugging this was quite a journey.

It seems that the .git prefix can be safely ignored. So

poetry add git+https://github.com/karantan/[email protected]

works as well. Please correct me if I'm wrong.

My first attempts with ssh failed with the same error. It worked once I switched to https.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AWegnerGitHub picture AWegnerGitHub  路  3Comments

ghost picture ghost  路  3Comments

mozartilize picture mozartilize  路  3Comments

ambv picture ambv  路  3Comments

nikaro picture nikaro  路  3Comments