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

json output is not valid, due to colorized ANSI escape codes #10430

Closed
aaltemara opened this issue May 17, 2024 · 1 comment
Closed

json output is not valid, due to colorized ANSI escape codes #10430

aaltemara opened this issue May 17, 2024 · 1 comment
Labels
triage Needs to be triaged

Comments

@aaltemara
Copy link

Bug Report

Issue name

dvc status --json: not parsable due to color escape codes

Description

Expectation is that --json produces json-compatible output. This is not the case, due to ANSI escape codes that lead to invalid json.

Reproduce

  1. dvc init
  2. dvc data status --json -q > ~/out
  3. vim ~/out
    (Shows)
    ^[[1m{^[[0m^[[1m}^[[0m
    ^[[0m

Expected

(No escape codes)
{}

I expect to be able to pipe the output of a --json command into 'jq' without json formatting errors

Environment information

Output of dvc doctor:

$ dvc doctor
DVC version: 3.50.2 (deb)
-------------------------
Platform: Python 3.10.8 on Linux-4.18.0-425.10.1.el8_7.x86_64-x86_64-with-glibc2.31
Subprojects:

Supports:
        azure (adlfs = 2024.4.1, knack = 0.11.0, azure-identity = 1.16.0),
        gdrive (pydrive2 = 1.19.0),
        gs (gcsfs = 2024.3.1),
        hdfs (fsspec = 2024.3.1, pyarrow = 16.0.0),
        http (aiohttp = 3.9.5, aiohttp-retry = 2.8.3),
        https (aiohttp = 3.9.5, aiohttp-retry = 2.8.3),
        oss (ossfs = 2023.12.0),
        s3 (s3fs = 2024.3.1, boto3 = 1.34.69),
        ssh (sshfs = 2024.4.1),
        webdav (webdav4 = 0.9.8),
        webdavs (webdav4 = 0.9.8),
        webhdfs (fsspec = 2024.3.1)
Config:
        Global: /root/.config/dvc
        System: /etc/xdg/dvc
Cache types: <https://error.dvc.org/no-dvc-cache>
Caches: local
Remotes: None
Workspace directory: xfs on /dev/mapper/vg01-lv01
Repo: dvc, git
Repo.site_cache_dir: /var/tmp/dvc/repo/113fba86254417b4ef5da622c5281b19

Additional Information (if any):

@shcheklein
Copy link
Member

I can't reproduce this right away, I think we have some logic that disables colorize:

def setup(level: int = logging.INFO, log_colors: bool = True) -> None:
    colorama.init()

    color_out = log_colors and bool(sys.stdout) and sys.stdout.isatty()
    color_err = log_colors and bool(sys.stderr) and sys.stderr.isatty()
...

from dvc/logger.py

Moreover, -q doesn't produce (expected any results for me).

Is there anything specific about your setup? What terminal are you using?

@shcheklein shcheklein added the triage Needs to be triaged label May 19, 2024
@shcheklein shcheklein closed this as not planned Won't fix, can't repro, duplicate, stale May 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage Needs to be triaged
Projects
None yet
Development

No branches or pull requests

2 participants