Repository: pypa/pipenv

Issue:
Newlines in output of `--py`
### Issue description

`pipenv --py` adds newlines. For instance
`python -c "import subprocess; print(subprocess.Popen(['pipenv', '--py'], stdout=subprocess.PIPE).stdout.read())"`

### Expected result

should print something like `b'/home/user/.local/share/virtualenvs/name-hash/bin/python\n'`

### Actual result

but actually prints things like `b'/home/user/.local/share/virtualenvs/name-hash/bin/p\nython\n'`. This is due to
https://github.com/pypa/pipenv/blob/e45cc7a9ab7e7d805ef6008db80a5469f038806c/pipenv/cli/command.py#L771

### Steps to replicate

- make the console small enough so the path doesn't fit on one line
- run `python -c "import subprocess; print(subprocess.Popen(['pipenv', '--py'], stdout=subprocess.PIPE).stdout.read())"`

This is an issue if run as part of a script or application, for instance [here](https://github.com/fannheyward/coc-pyright/blob/8789fcc25cd055a0cc1e70fc83bfcca90720c384/src/configSettings.ts#L77). Maybe add the argument `bare` similar to https://github.com/pypa/pipenv/blob/e45cc7a9ab7e7d805ef6008db80a5469f038806c/pipenv/utils/virtualenv.py#L360


Discussion:
Proposal:

<details>

```diff
diff --git a/pipenv/cli/command.py b/pipenv/cli/command.py
index fb4ee05..a61b9a6 100644
--- a/pipenv/cli/command.py
+++ b/pipenv/cli/command.py
@@ -27,6 +27,7 @@ from pipenv.utils.processes import subprocess_run
 from pipenv.vendor.click import (
     Choice,
     argument,
+    echo,
     edit,
     group,
     option,
@@ -125,7 +126,7 @@ def cli(
             do_where(state.project, bare=True)
             return 0
         elif py:
-            do_py(state.project, ctx=ctx)
+            do_py(state.project, ctx=ctx, bare=True)
             return 0
         # --support was passed...
         elif support:
@@ -758,7 +759,7 @@ if __name__ == "__main__":
     cli()
 
 
-def do_py(project, ctx=None, system=False):
+def do_py(project, ctx=None, system=False, bare=False):
     if not project.virtualenv_exists:
         err.print(
             "[red]No virtualenv has been created for this project[/red] "
@@ -768,6 +769,7 @@ def do_py(project, ctx=None, system=False):
         ctx.abort()
 
     try:
-        console.print(project._which("python", allow_global=system))
+        (echo if bare else console.print)(project._which("python", allow_global=system))
     except AttributeError:
         console.print("No project found!", style="red")
+        ctx.abort()
```

</details>
@notEvil Feel free to open a PR since it seems like you have a patch.  I am not quite sure I understand where the new line is coming from though.
I'd say here

https://github.com/pypa/pipenv/blob/e45cc7a9ab7e7d805ef6008db80a5469f038806c/pipenv/patched/pip/_vendor/rich/segment.py#L304C52-L304C52

coming from

https://github.com/pypa/pipenv/blob/e45cc7a9ab7e7d805ef6008db80a5469f038806c/pipenv/patched/pip/_vendor/rich/console.py#L1715C45-L1715C45

Resolving patch:
diff --git a/pipenv/cli/command.py b/pipenv/cli/command.py
--- a/pipenv/cli/command.py
+++ b/pipenv/cli/command.py
@@ -125,7 +125,7 @@ def cli(
             do_where(state.project, bare=True)
             return 0
         elif py:
-            do_py(state.project, ctx=ctx)
+            do_py(state.project, ctx=ctx, bare=True)
             return 0
         # --support was passed...
         elif support:
@@ -758,7 +758,7 @@ def requirements(
     cli()
 
 
-def do_py(project, ctx=None, system=False):
+def do_py(project, ctx=None, system=False, bare=False):
     if not project.virtualenv_exists:
         err.print(
             "[red]No virtualenv has been created for this project[/red] "
@@ -768,6 +768,7 @@ def do_py(project, ctx=None, system=False):
         ctx.abort()
 
     try:
-        console.print(project._which("python", allow_global=system))
+        (print if bare else console.print)(project._which("python", allow_global=system))
     except AttributeError:
         console.print("No project found!", style="red")
+        ctx.abort()


Test patch: