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

Local path is not installable for non-selected dev dependency #2650

Closed
1 task done
DeD1rk opened this issue Feb 24, 2024 · 4 comments · Fixed by j178/pdm#1
Closed
1 task done

Local path is not installable for non-selected dev dependency #2650

DeD1rk opened this issue Feb 24, 2024 · 4 comments · Fixed by j178/pdm#1
Labels
🐛 bug Something isn't working

Comments

@DeD1rk
Copy link

DeD1rk commented Feb 24, 2024

  • I have searched the issue tracker and believe that this is not a duplicate.

Make sure you run commands with -v flag before pasting the output.

Steps to reproduce

  1. Have a dockerfile like this:
FROM python:3.11-slim AS builder

RUN pip install -U pip pdm

COPY workers/demo/pyproject.toml workers/demo/pdm.lock /workers/demo/
WORKDIR /workers/demo/

FROM builder AS prod-venv

RUN python -m venv /opt/venv \
    && pdm use -f /opt/venv \
    && pdm sync --prod --no-editable -v

with these pyproject.toml and pdm.lock files:

[project]
name = "demo"
version = "0.0.0" 
description = ""
authors = [{ name = "foo", email = "[email protected]" }]
license = { text = "Commercial" }

requires-python = ">=3.11"
dependencies = []

[tool.pdm.dev-dependencies]
dev = [
    "workers_dev @ file:///${PROJECT_ROOT}/../..",
]
# This file is @generated by PDM.
# It is not intended for manual editing.

[metadata]
groups = ["default", "dev"]
strategy = ["cross_platform", "inherit_metadata"]
lock_version = "4.4.1"
content_hash = "sha256:97e6e2e93bd110dbe0692baf70e8656259efa053a1f503c7a290942234175855"

[[package]]
name = "workers-dev"
version = "0.0.0"
requires_python = ">=3.11"
path = "../.."
summary = ""
groups = ["dev"]
  1. Build this: docker build -f Dockerfile ../..

Actual behavior

We get an error because the dev dependency workers-dev (at ../.., i.e. at / in the container) is not found in the container:

 > [prod-venv 1/1] RUN python -m venv /opt/venv     && pdm use -f /opt/venv     && pdm sync --prod --no-editable -v:                    
#9 4.372 Using Python interpreter: /opt/venv/bin/python3 (3.11)                                                                         
#9 5.049 STATUS: Resolving packages from lockfile...
#9 5.084 [RequirementError]: The local path '../..' is not installable.

Expected behavior

pdm sync --prod should ignore workers-dev as it's not selected for being installed.

Environment Information

# Paste the output of `pdm info && pdm info --env` below:

Using Python interpreter: /opt/venv/bin/python3 (3.11)         
PDM version:                                                   
  2.12.3                                                       
Python Interpreter:
  /opt/venv/bin/python3 (3.11)
Project Root:
  /workers/demo
Local Packages:
  
{
  "implementation_name": "cpython",
  "implementation_version": "3.11.8",
  "os_name": "posix",
  "platform_machine": "x86_64",
  "platform_release": "5.15.133.1-microsoft-standard-WSL2",
  "platform_system": "Linux",
  "platform_version": "#1 SMP Thu Oct 5 21:02:42 UTC 2023",
  "python_full_version": "3.11.8",
  "platform_python_implementation": "CPython",
  "python_version": "3.11",
  "sys_platform": "linux"
}
@DeD1rk DeD1rk added the 🐛 bug Something isn't working label Feb 24, 2024
@DeD1rk
Copy link
Author

DeD1rk commented Feb 24, 2024

This is caused here in the _check_installable call:

def __post_init__(self) -> None:
super().__post_init__()
self._parse_url()
if self.is_local_dir:
self._check_installable()

This check is only done if is_local, which means it's skipped if the directory does not exist. So if in my example, workers-dev was not at ../.., but e.g. ../../dev or any other directory that doesn't exist in my docker container, it would work fine. However, that's not a good option for me. I need its pyproject.toml to be at the repository root for linting configuration.

I don't know much about PDMs internals, but I think it would be nice if PDM would just ignore it when a local file dependency that's not going to be installed has a path that exists but isn't installable, just like it handles the case if the path doesn't exist at all.

Edit: An (ugly) workaround for me is to add a touch /setup.py step that tricks the _check_installable call.

@DeD1rk
Copy link
Author

DeD1rk commented Feb 26, 2024

Hey @frostming, thanks for looking at it so quickly! However, I'm afraid 0ae5611 doesn't actually fix this. _check_installable was already not being called when the directory does not exist. The problem is when the directory does exist (which is likely for e.g. .., ../.., etc.) but has no pyproject or setup.py.

@DeD1rk
Copy link
Author

DeD1rk commented Feb 26, 2024

I think the _check_installable call should be moved FileRequirement.__post_init__ to somewhere like the Candidate or PreparedCandidate classes, so that it only runs once you try to actually install a local file package

@frostming
Copy link
Collaborator

Can you suggest a patch in a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants