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

Adding github dependency #313

Closed
karantan opened this issue Jul 17, 2018 · 16 comments
Closed

Adding github dependency #313

karantan opened this issue Jul 17, 2018 · 16 comments
Labels
area/cli Related to the command line kind/feature Feature requests/implementations
Milestone

Comments

@karantan
Copy link

karantan commented Jul 17, 2018

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?

@perobertson
Copy link

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.

@nariman
Copy link

nariman commented Oct 25, 2018

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.

@senpos
Copy link

senpos commented Jan 14, 2019

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. :)

@sdispater sdispater added area/cli Related to the command line kind/feature Feature requests/implementations labels Mar 2, 2019
@sdispater sdispater added this to the 1.0 milestone Mar 2, 2019
@whisller
Copy link

whisller commented Apr 8, 2019

@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?

@sdispater
Copy link
Member

The add command will be improved in the next 1.0.0 release (see #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]

@whisller
Copy link

whisller commented Jul 17, 2019

@sdispater will it also work with setting git repository URL as dev dependency?
I've mentioned about it in #313 (comment)

@Granitosaurus
Copy link

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

@finswimmer
Copy link
Member

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

@Granitosaurus
Copy link

@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.

@laike9m
Copy link
Contributor

laike9m commented May 2, 2020

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.

@P403n1x87
Copy link

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

@carlos-lm
Copy link

Hi guys, sorry to post this in a closed issue, not know if I need open a new issue for this...

we're working with a private repo, when I add the package in the cli, using https protocol this work fine, but it's asking me user and password and because we'll deploy the code with CI/CD I'd prefer use ssh and use the stored ssh keys...

when I replace this

poetry add git+https.....

for this

poetry add git+git@gitlab....

or

poetry add git@gitlab.....

this doesn't work

 Could not find a matching version of package git+git

  at ~/.local/pipx/venvs/poetry/lib/python3.9/site-packages/poetry/console/commands/init.py:367 in _find_best_version_for_package
      363│         )
      364│ 
      365│         if not package:
      366│             # TODO: find similar
    → 367│             raise ValueError(
      368│                 "Could not find a matching version of package {}".format(name)
      369│             )
      370│ 
      371│         return package.pretty_name, selector.find_recommended_require_version(package)

I've also tried add my package in the pyproject.toml

[tool.poetry.dependencies]
python = "^3.9"
ccxt = "^1.55.69"
xyzidb = { git = "[email protected]:avanti-sf/public/xyzi-team/xyzi/utils/xyzi", branch = "dev" }

here the error is this

at ~/.local/pipx/venvs/poetry/lib/python3.9/site-packages/poetry/core/utils/helpers.py:27 in canonicalize_name
       23│ _canonicalize_regex = re.compile(r"[-_]+")
       24│ 
       25│ 
       26│ def canonicalize_name(name):  # type: (str) -> str
    →  27│     return _canonicalize_regex.sub("-", name).lower()
       28│ 
       29│ 
       30│ def module_name(name):  # type: (str) -> str
       31│     return canonicalize_name(name).replace(".", "_").replace("-", "_")

what would be the best way to include my private git repo here? thank you guys, best regards.

@perobertson
Copy link

perobertson commented Sep 4, 2021

In your GitLab CI job you could try something like this

build:
  before_script:
    - git config --global url."https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com".insteadOf "ssh://[email protected]"
  script:
    - poetry install

That way you can keep the ssh config and then the CI job would use a temporary token to access the repo with the same permissions as whoever runs the job.

You may need to try different values for ssh://[email protected] depending on how you added it to pyproject.toml

@phuong
Copy link

phuong commented Dec 14, 2021

In my case
Tried: poetry add git+https://github.com/karantan/[email protected]
Got: Command '['git', 'config', '-l']' returned non-zero exit status 128.

My directory

ls -l
-rw-rw-r--  1 1000 1000   45 Nov  3 01:37 .git
drwxrwxr-x  4 1000 1000 4.0K Nov  3 01:37 .github
-rw-rw-r--  1 1000 1000  809 Nov  3 01:37 .gitignore
...

My git is a submodule, i need to move .git to other name to make it work.
Any idea for git submodule issue?

@ghost
Copy link

ghost commented Mar 27, 2022

Poetry (version 1.2.0a2) doesn't want to work with version boundary using GitHub git URLs.
For example, I have a repo (acme-some-package) with version tag v0.7.0 on the master branch.
When I add refer to it from another project without version boundary acme-some-package = { git = "ssh://[email protected]/acme/acme-some-package.git" } everything works. But if I change to
acme-some-package = { git = "ssh://[email protected]/acme/acme-some-package.git", version = "^07" }

I do get:

  RuntimeError

  The Poetry configuration is invalid:
    - [dependencies.acme-some-package] {'git': 'ssh://[email protected]/acme/acme-some-package.git', 'version': '^0.7'} is not valid under any of the given schemas

Copy link

github-actions bot commented Mar 2, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/cli Related to the command line kind/feature Feature requests/implementations
Projects
None yet
Development

No branches or pull requests