Repository: pypa/pipenv

Issue:
PosixPath' object has no attribute 'strip' since 2023.11.14 on Python 3.11.6
### Issue description

Starting with 2023.11.14 we get an error in pipenv in all our python builds (Linux on upstream python 3.11 container) and locally on Linux/Mac.

### Expected result

`pipenv install .` succeeds as in `2023.10.24`.

### Actual result

pipenv crashes:

```
⠸ Locking...
✔ Success!
Traceback (most recent call last):
  File "/usr/local/bin/pipenv", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/usr/local/lib/python3.11/site-packages/pipenv/vendor/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pipenv/cli/options.py", line 58, in main
    return super().main(*args, **kwargs, windows_expand_args=False)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pipenv/vendor/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pipenv/vendor/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pipenv/vendor/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pipenv/vendor/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pipenv/vendor/click/decorators.py", line 92, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pipenv/vendor/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pipenv/cli/command.py", line 209, in install
    do_install(
  File "/usr/local/lib/python3.11/site-packages/pipenv/routines/install.py", line 297, in do_install
    raise e
  File "/usr/local/lib/python3.11/site-packages/pipenv/routines/install.py", line 281, in do_install
    do_init(
  File "/usr/local/lib/python3.11/site-packages/pipenv/routines/install.py", line 672, in do_init
    do_lock(
  File "/usr/local/lib/python3.11/site-packages/pipenv/routines/lock.py", line 65, in do_lock
    venv_resolve_deps(
  File "/usr/local/lib/python3.11/site-packages/pipenv/utils/resolver.py", line 875, in venv_resolve_deps
    return prepare_lockfile(
           ^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pipenv/utils/locking.py", line 140, in prepare_lockfile
    lockfile_entry = get_locked_dep(project, dep, pipfile, current_entry)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pipenv/utils/locking.py", line 123, in get_locked_dep
    lockfile_entry = clean_resolved_dep(project, dep, is_top_level, current_entry)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pipenv/utils/dependencies.py", line 277, in clean_resolved_dep
    potential_hashes = unearth_hashes_for_dep(project, dep)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pipenv/utils/dependencies.py", line 189, in unearth_hashes_for_dep
    install_req, markers, _ = install_req_from_pipfile(dep["name"], dep)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pipenv/utils/dependencies.py", line 1097, in install_req_from_pipfile
    install_req, _ = expansive_install_req_from_line(
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pipenv/utils/dependencies.py", line 954, in expansive_install_req_from_line
    pip_line = pip_line.strip("'").lstrip(" ")
               ^^^^^^^^^^^^^^
AttributeError: 'PosixPath' object has no attribute 'strip'
```

### Steps to replicate

Provide the steps to replicate (which usually at least includes the commands and the Pipfile).

Run `pipenv install .`.

Pipfile:
```
cat Pipfile
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]

[dev-packages]

[requires]
python_version = "3.11"
```

setup.py:
```
from setuptools import setup, find_packages

setup(
    name='xxx',
    version='0.1',

    packages=find_packages('app'),
    package_dir={'': 'app'},
    include_package_data=True,

    install_requires=(
        'Flask==3.0.0',
        'Flask-Login==0.6.3',
        'flask-oidc-ext==1.4.5',
        'Flask-Session==0.5.0',
        'Flask-WTF==1.2.1',
        'Flask-Bootstrap==3.3.7.1',
        'Werkzeug==3.0.1',
        'chardet==5.2.0',
        'cryptography==41.0.5',
        'gunicorn==21.2.0',
        'pyOpenSSL==23.3.0',
        'PyJWT[crypto]==2.8.0',
        'requests==2.31.0',
        'requests_pkcs12==1.22',
        'sqlite3dict==1.0.1',
        'pem==23.1.0',
        'tabulate==0.9.0',
        'setuptools==68.2.2',
        'pyjks==20.0.0',
        'itsdangerous>=2.1.2,<2.2',
    )
)
```

-------------------------------------------------------------------------------

<details><summary>$ pipenv --support</summary>

Pipenv version: `'2023.11.14'`

Pipenv location: `'/usr/local/lib/python3.11/site-packages/pipenv'`

Python location: `'/usr/local/opt/python@3.11/bin/python3.11'`

OS Name: `'posix'`

User pip version: `'23.3.1'`

user Python installations found:


PEP 508 Information:

```
{'implementation_name': 'cpython',
 'implementation_version': '3.11.6',
 'os_name': 'posix',
 'platform_machine': 'x86_64',
 'platform_python_implementation': 'CPython',
 'platform_release': '22.6.0',
 'platform_system': 'Darwin',
 'platform_version': 'Darwin Kernel Version 22.6.0: Fri Sep 15 13:39:52 PDT '
                     '2023; root:xnu-8796.141.3.700.8~1/RELEASE_X86_64',
 'python_full_version': '3.11.6',
 'python_version': '3.11',
 'sys_platform': 'darwin'}
```

System environment variables:

  - `TERM_SESSION_ID`
  - `SSH_AUTH_SOCK`
  - `LC_TERMINAL_VERSION`
  - `COLORFGBG`
  - `ITERM_PROFILE`
  - `XPC_FLAGS`
  - `LANG`
  - `PWD`
  - `SHELL`
  - `__CFBundleIdentifier`
  - `SECURITYSESSIONID`
  - `TERM_PROGRAM_VERSION`
  - `TERM_PROGRAM`
  - `PATH`
  - `LC_TERMINAL`
  - `COLORTERM`
  - `COMMAND_MODE`
  - `TERM`
  - `HOME`
  - `TMPDIR`
  - `USER`
  - `XPC_SERVICE_NAME`
  - `LOGNAME`
  - `LaunchInstanceID`
  - `__CF_USER_TEXT_ENCODING`
  - `ITERM_SESSION_ID`
  - `SHLVL`
  - `OLDPWD`
  - `P9K_TTY`
  - `_P9K_TTY`
  - `ZSH`
  - `PAGER`
  - `LESS`
  - `LSCOLORS`
  - `LS_COLORS`
  - `P9K_SSH`
  - `KUBE_EDITOR`
  - `KOPS_STATE_STORE`
  - `AWS_PROFILE`
  - `_`
  - `PIP_DISABLE_PIP_VERSION_CHECK`
  - `PYTHONDONTWRITEBYTECODE`
  - `PYTHONFINDER_IGNORE_UNSUPPORTED`

Pipenv–specific environment variables:


Debug–specific environment variables:

  - `PATH`: `/usr/local/opt/python@3.8/bin:/usr/local/sbin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/Users/xxx/.krew/bin:/Users/xxx/.cargo/bin:/Users/xxx/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Users/xxx/.local/bin`
  - `SHELL`: `/bin/zsh`
  - `LANG`: `de_DE.UTF-8`
  - `PWD`: `/Users/xxx/src/xxx/xxx`


---------------------------

Contents of `Pipfile` ('/Users/xxx/src/xxx/xxx/Pipfile'):

```toml
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]

[dev-packages]

[requires]
python_version = "3.11"

```

</details>

This also happens on a freshly installed pipenv in Docker on all of our projects. Downgrade fixes it.


Discussion:
Will take a look tonight.
+1 getting the same error on Python 3.10.13

Resolving patch:
diff --git a/pipenv/utils/dependencies.py b/pipenv/utils/dependencies.py
--- a/pipenv/utils/dependencies.py
+++ b/pipenv/utils/dependencies.py
@@ -667,11 +667,11 @@ def ensure_path_is_relative(file_path):
     # Check if the paths are on different drives
     if abs_path.drive != current_dir.drive:
         # If on different drives, return the absolute path
-        return abs_path
+        return str(abs_path)
 
     try:
         # Try to create a relative path
-        return abs_path.relative_to(current_dir)
+        return str(abs_path.relative_to(current_dir))
     except ValueError:
         # If the direct relative_to fails, manually compute the relative path
         common_parts = 0


Test patch:
diff --git a/tests/integration/test_install_twists.py b/tests/integration/test_install_twists.py
--- a/tests/integration/test_install_twists.py
+++ b/tests/integration/test_install_twists.py
@@ -7,6 +7,35 @@
 from pipenv.utils.shell import temp_environ
 
 
+@pytest.mark.extras
+@pytest.mark.install
+@pytest.mark.local
+def test_local_path_issue_6016(pipenv_instance_pypi):
+    with pipenv_instance_pypi() as p:
+        setup_py = os.path.join(p.path, "setup.py")
+        with open(setup_py, "w") as fh:
+            contents = """
+from setuptools import setup, find_packages
+setup(
+    name='testpipenv',
+    version='0.1',
+    description='Pipenv Test Package',
+    author='Pipenv Test',
+    author_email='test@pipenv.package',
+    license='MIT',
+    packages=find_packages(),
+    install_requires=[],
+    extras_require={'dev': ['six']},
+    zip_safe=False
+)
+            """.strip()
+            fh.write(contents)
+        # project.write_toml({"packages": pipfile, "dev-packages": {}})
+        c = p.pipenv("install .")
+        assert c.returncode == 0
+        assert "testpipenv" in p.lockfile["default"]
+
+
 @pytest.mark.extras
 @pytest.mark.install
 @pytest.mark.local