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

command/add: introduce --editable option #3940

Merged
merged 1 commit into from
Apr 21, 2021

Conversation

abn
Copy link
Member

@abn abn commented Apr 13, 2021

This change allows for vcs/path dependencies to be installed with
develop=true configured.

Relates-to: #3931

This change allows for vcs/path dependencies to be installed with
`develop=true` configured.
@abn abn requested a review from a team April 13, 2021 21:52
@finswimmer
Copy link
Member

Also Related: #3004
Closes: #3220
Replaces: #3250

@gc-ss
Copy link

gc-ss commented Apr 17, 2021

@abn This is going to be very helpful. Could you explain, after merging this PR - What is the command I would need to type so that my-package = { path = "../my-package/", develop = true } will appear in the TOML file (no longer requiring me to edit the TOML file manually?)

Specific topic with details: #3962

@abn
Copy link
Member Author

abn commented Apr 17, 2021

@gc-ss as described in the doc (see changed files),

poetry add --editable /path/to/package

@gc-ss
Copy link

gc-ss commented Apr 17, 2021

@gc-ss as described in the doc (see changed files),

poetry add --editable /path/to/package

Can't wait to use this!

I am assuming this would work for git repos too?

TO clarify, if I want to add a python package directly from git in editable/development mode, all I need to do is:

poetry add --editable git+https://github.com/python-poetry/poetry.git#develop/branch/name/with/slashes/in/it

@fredrikaverpil
Copy link
Contributor

fredrikaverpil commented Apr 17, 2021

@gc-ss I haven't tried this myself, but I think you can give this a whirl by pipx-installing poetry;

pipx install --suffix=@3940 'poetry @ git+https://github.com/python-poetry/poetry.git@refs/pull/3940/head'
poetry@3940 add --editable /path/to/package

@fredrikaverpil
Copy link
Contributor

@abn if you already have the package installed, can you somehow make it into an editable one by doing something like poetry update packagex --editable?

@abn
Copy link
Member Author

abn commented Apr 17, 2021

Unfortunately for that you have to first run remove. The commands are not idempotent. I am guessing you are thinking of something similar to the new source command.

@fredrikaverpil
Copy link
Contributor

fredrikaverpil commented Apr 17, 2021

@abn there's something strange going on here...

First I install package b locally from path:

$ poetry@3940 add ../b/ --editable

Updating dependencies
Resolving dependencies... (0.9s)

Writing lock file

Package operations: 5 installs, 1 update, 0 removals

  • Installing certifi (2020.12.5): Installing...
  • Installing chardet (4.0.0): Installing...
  • Installing idna (2.10): Installing...
  • Installing urllib3 (1.26.4): Installing...
  • Installing requests (2.25.1): Installing...
  • Updating b (2.1.3.dev0+g77bcc5e.d20210417090856 -> 0.0.0 /home/fredrik/code/repos/b)

Then I remove it:

$ poetry@3940 remove b
Updating dependencies
Resolving dependencies... (0.1s)

Writing lock file

Package operations: 0 installs, 0 updates, 6 removals

  • Removing b (0.0.0 /home/fredrik/code/repos/b)
  • Removing certifi (2020.12.5)
  • Removing chardet (4.0.0)
  • Removing idna (2.10)
  • Removing requests (2.25.1)
  • Removing urllib3 (1.26.4)

And finally, I'm attempting to install it without it being editable:

$ poetry@3940 add ../b/

  TypeError

  expected string or bytes-like object

  at ~/.local/pipx/venvs/poetry@3940/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: str) -> str:
    →  27│     return _canonicalize_regex.sub("-", name).lower()
       28│
       29│
       30│ def module_name(name: str) -> str:
       31│     return canonicalize_name(name).replace(".", "_").replace("-", "_")

Not sure what is going on here. When I add in a print(name) I can see it is None.

EDIT: Oh okay so there was a lingering dist-info folder in my site-packages for b. Let me try all of this again.

@abn
Copy link
Member Author

abn commented Apr 17, 2021

Shouldn't be anything that changed here. Might be good to see the full traceback.

@fredrikaverpil
Copy link
Contributor

fredrikaverpil commented Apr 17, 2021

On my machine, the following sequence leaves folders behind in site-packages:

Install b from path:

$ poetry@3940 add ../b/

Updating dependencies
Resolving dependencies... (0.1s)

Writing lock file

Package operations: 1 install, 0 updates, 0 removals

  • Installing b (0.0.0 /home/fredrik/code/repos/b): Building...

Then I wanted to see what happens if I try to add it again but with the --editable arg:

$ poetry@3940 add --editable ../b/

Updating dependencies
Resolving dependencies... (0.1s)

Writing lock file

Package operations: 0 installs, 1 update, 0 removals

  • Updating b (2.1.3.dev0+g77bcc5e.d20210417114942 /home/fredrik/code/repos/b -> 0.0.0 /home/fredrik/code/repos/b)

Finally uninstalling b:

$ poetry@3940 remove b
Updating dependencies
Resolving dependencies... (0.1s)

Writing lock file

Package operations: 0 installs, 0 updates, 1 removal

  • Removing b (0.0.0 /home/fredrik/code/repos/b)

But unfortunately, b was not completely removed, likely due to the fact that I was able to run poetry add twice:

image

And now it seems the .venv is b0rked, as there is suddenly a None package:

$ poetry@3940 show

  TypeError

  expected string or bytes-like object

  at ~/.local/pipx/venvs/poetry@3940/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: str) -> str:
    →  27│     return _canonicalize_regex.sub("-", name).lower()
       28│
       29│
       30│ def module_name(name: str) -> str:
       31│     return canonicalize_name(name).replace(".", "_").replace("-", "_")

@abn
Copy link
Member Author

abn commented Apr 17, 2021

This might be related to #3900. The direct_url files are not being added to metadata. So package file discovery does not see them. Will fix it.

@kasteph kasteph merged commit 494dec2 into python-poetry:master Apr 21, 2021
@abn abn deleted the commands/add-editable branch April 22, 2021 19:33
@sdispater sdispater mentioned this pull request Apr 23, 2021
@eode
Copy link

eode commented Apr 26, 2021

@stephsamson @abn Thank you! This was what was holding me back from using Poetry. I'll dive in now.

Copy link

This pull request 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 Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants