Skip to content

use of installed packages means poetry lock does not fully respect designated source for dependencies #8328

@jclerman

Description

@jclerman
  • Poetry version: 1.5.1
  • Python version: 3.10.12
  • OS version and name: MacOS 12.6.8
  • pyproject.toml:
  • I am on the latest stable Poetry version, installed using a recommended method.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have consulted the FAQ and blog for any relevant entries or release notes.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option) and have included the output below. N/A

Issue

When I started writing this, I thought the issue was different - now I think I see what's happening.

In a clean project for which poetry.lock has never been run before, poetry works as expected.

However, the results of poetry lock seem to be influenced by poetry's cache (somehow), since in an existing project, where poetry has successfully done lock before, it does not seem to be possible to tell poetry to limit where it looks for a given dependency.

Let's say we have the following pyproject.toml in a clean, new project, and that my_dep is only available in private repo privaterepo:

[tool.poetry]
name = "my-project"
version = "0.1.0"
description = ""
authors = ["Jeff Lerman <[email protected]>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.10.0"
my-dep = {version = "^0.8.2", source = "PyPI"}

[[tool.poetry.source]]
name = "private_repo"
url = "https://repo.shared.privaterepo.com/repository/pypi-privaterepo/simple"
priority = "explicit"

[[tool.poetry.source]]
name = "PyPI"
priority = "supplemental"

[build-system]
requires = ["poetry-core>=1.4.0"]
build-backend = "poetry.core.masonry.api"

poetry lock correctly tells us:

Because my-project depends on my-dep (^0.8.2) which doesn't match any versions, version solving failed.

But now if we:

  1. change the pyproject.toml to indicate the correct source (private_repo)
  2. run poetry lock (completes successfully)
  3. run poetry install (this is key!!)
  4. change pyproject.toml back to the wrong source (PyPI)
  5. run poetry lock

Then there is no failure anymore. We get the following clause in the resulting poetry.lock:

[[package]]
name = "my-dep"
version = "0.8.3"
description = "this is a very private package"
optional = false
python-versions = "*"
files = []

So, poetry is seeing the dependency in its local cache (somehow), using that to decide that it's a valid package, but not getting any metadata for it except the version & description - and populating an awfully sparse-looking poetry.lock clause.

That means there's no way to tell poetry, once a package has been found and installed (presumably, from any repo) that now we want to install it from a specific private repo - also no way to ensure that we've completely locked down the source for packages that we want to only ever come from our private repo.

I noticed this when trying to upgrade existing projects to the new poetry 1.5.x style of specifying sources, and not getting failures when I should have been.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/depsRelated to representing and locking dependenciesarea/sourcesReleated to package sources/indexes/repositorieskind/bugSomething isn't working as expectedstatus/triageThis issue needs to be triaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions