-
-
Notifications
You must be signed in to change notification settings - Fork 422
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
Output of 'pdm export' gets line wrapped even when the output isn't a terminal #2390
Comments
We support output to file flag |
If using With subprocess, I suppose using import os
import subprocess
from tempfile import TemporaryDirectory
with TemporaryDirectory() as tmpdir:
tmpfile = os.path.join(tmpdir, "requirements.txt")
subprocess.run(f"pdm export -o {tmpfile}".split())
with open(tmpfile) as file:
requirements = file.read() Using I'm actually doing the same thing as @datalogics-kam in my project tasks to check my dependencies: @duty
def check_dependencies(ctx: Context) -> None:
requirements = ctx.run(
["pdm", "export", "-f", "requirements", "--without-hashes"],
title="Exporting dependencies as requirements",
allow_overrides=False,
)
ctx.run(
safety.check(requirements),
title="Checking dependencies",
command="pdm export -f requirements --without-hashes | safety check --stdin",
) Apparently I'm just lucky that none of them use an extra index URL 🤔 I'll verify that to confirm. |
Is it possible that pytest is the culprit here? Without seeing your code and how you test it, it's difficult to guess 🤔 |
It breaks in a situation where there are a lot of layers...coverage calls pytest calls (AWS) I've tried probing to see what's going on, but my best guess is that something along the way is using a pty or setting environment variables that makes Rich think the output is a terminal that's 80 columns wide. It's also not real consistent. I tried making a small For now I did in fact use |
I'm not opposed to changing to a regular |
Erm, I'm so sorry @frostming, I pushed directly to the main branch 😱 |
By the way I can probably do the git reset + force push, but I don't want to make any more mistake, so I'll wait for your input 🙂 |
Don't worry about it. I think we should protect the main branch, but sometimes I like to push commits to it, which may not be a good habit.😟 |
I think it's possible to remove push access to the main branch for specific collaborators only, while keeping it for yourself. |
@pawamoy done, now you continue with your PR. |
Thanks! I'm not sure why but I'm getting 72 Mypy errors when pre-commit runs, preventing me from committing, so I'll just disable the Git hook for now. |
Thanks, @pawamoy, for the fix!! |
Make sure you run commands with
-v
flag before pasting the output.Steps to reproduce
In the actual case, we're using
subprocess.run(...,stdout=subprocess.PIPE)
to consume the output frompdm export
. We make a hash and then decide if we want to write some files.I've been trying to make a small test case, but I haven't figured out what is causing the wrapping behavior. The actual run of PDM is buried in a series of nested subprocesses, and I haven't found anything that would trigger Rich to wrap, like the environment variable COLUMNS being set, or TERM being set to a dumb terminal.
Actual behavior
It seems to work fine most of the time locally, but when running from inside pytest the file gets corrupted: A long line with
--extra-index-url
with our AWS CodeArtifact URL in it gets line wrapped, and then pip can't use the file.Expected behavior
I would expect that in no case would the output of
pdm export
be formatted in any way. Even if the output is a bit wide for the terminal, it should be consumable by, for instance, pip.The question I have is whether the export output should be sent through Rich.
Environment Information
The text was updated successfully, but these errors were encountered: