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

fix: create path dependencies relative to package rather than lockfile (#4245) #4246

Merged
merged 3 commits into from
Jul 29, 2021

Conversation

md384
Copy link
Contributor

@md384 md384 commented Jul 2, 2021

Resolves path dependencies relative to the package and lockfile rather than just the lockfile.

Resolves: #4245

  • Added tests for changed code.
  • Updated documentation for changed code.

@@ -176,20 +176,26 @@ def locked_repository(
package.marker = parse_marker(split_dep[1].strip())

for dep_name, constraint in info.get("dependencies", {}).items():

root_dir = self._lock.path.parent
if package.source_type == "directory":
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we need to handle file source types too

Copy link
Member

@abn abn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to the comments in the reivew, I wonder if this is going to cause issues if libB from your issue is also a dependency of libC, I suspect not if libC is at the same location as libA, however could get a bit hairy if it is not and/or libCis nested in libA.

if package.source_type == "directory":
# root dir should be the source of the package relative to the lock path
root_dir = Path(
os.path.relpath(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of points;

  1. Move to using pathlib if possible.
  2. We cannot always be sure a "directory" package is relative as it could also be an absolute path.

@sonarcloud
Copy link

sonarcloud bot commented Jul 6, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@md384
Copy link
Contributor Author

md384 commented Jul 6, 2021

@abn to test this, I created a new project with the following structure

my-package/
  pyproject.toml
  lib/
    lib-a/
      lib-a/
      pyproject.toml
      lib-c/
        lib-c/
        pyproject.toml
    lib-b/
      lib-b/
      pyproject.toml
      lib-d/
        lib-d/
        pyproject.toml
  tools/
    my_tool/
      my_tool/
      pyproject.toml

I created nested libraries across directories like you suggested. my-package depends on lib-a which depends on lib-b which depends on lib-c which depends on lib-d which depends on my_tool. I added the relevant part of the poetry lock file for my-project (the root package) below.

[[package]]
name = "lib-a"
version = "0.1.0"
description = ""
category = "main"
optional = false
python-versions = "^3.9"
develop = true

[package.dependencies]
lib-b = {path = "../lib_b", develop = true}

[package.source]
type = "directory"
url = "lib/lib_a"

[[package]]
name = "lib-b"
version = "0.1.0"
description = ""
category = "main"
optional = false
python-versions = "^3.9"
develop = true

[package.dependencies]
lib-c = {path = "../lib_a/lib_c", develop = true}

[package.source]
type = "directory"
url = "lib/lib_b"

[[package]]
name = "lib-c"
version = "0.1.0"
description = ""
category = "main"
optional = false
python-versions = "^3.9"
develop = true

[package.dependencies]
lib-d = {path = "../../lib_b/lib_d", develop = true}

[package.source]
type = "directory"
url = "lib/lib_a/lib_c"

[[package]]
name = "lib-d"
version = "0.1.0"
description = ""
category = "main"
optional = false
python-versions = "^3.9"
develop = true

[package.dependencies]
my-tool = {path = "../../../tools/my_tool", develop = true}

[package.source]
type = "directory"
url = "lib/lib_b/lib_d"

[[package]]
name = "my-tool"
version = "0.1.0"
description = ""
category = "main"
optional = false
python-versions = "^3.9"
develop = true

[package.source]
type = "directory"
url = "tools/my_tool"

I was able to install and import all the libs from my-package.

my-package % poetry run python
Python 3.9.5 (default, May  4 2021, 03:36:27) 
[Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import lib_a
>>> import lib_b
>>> import lib_c
>>> import lib_d
>>> import my_tool

I hope no-one would do such a thing as this though 😉

@md384
Copy link
Contributor Author

md384 commented Jul 6, 2021

@abn it turns out that we already calculate the relative path

url = self._lock.path.parent.joinpath(url).resolve().as_posix()
so I am just using that now.

You commented before that a directory source url could be an absolute path. Does that line need to be changed?

@sdispater sdispater merged commit 89575f6 into python-poetry:master Jul 29, 2021
@sdispater
Copy link
Member

Thanks!

sdispater added a commit that referenced this pull request Jul 30, 2021
fix: create path dependencies relative to package rather than lockfile (#4245)
sdispater added a commit that referenced this pull request Jul 30, 2021
fix: create path dependencies relative to package rather than lockfile (#4245)
sdispater added a commit that referenced this pull request Jul 30, 2021
fix: create path dependencies relative to package rather than lockfile (#4245)
@sdispater sdispater mentioned this pull request Aug 19, 2021
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.

Directory does not exist errors for path dependencies
3 participants