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

When using --print-settings, error message should go to STDERR, not STDOUT #3342

Open
egberts opened this issue Jun 21, 2024 · 3 comments
Open
Labels

Comments

@egberts
Copy link

egberts commented Jun 21, 2024

  • [X ] I have read the Filing Issues and subsequent “How to Get Help” sections of the documentation.
  • [ X] I have searched the issues (including closed ones) and believe that this is not a duplicate.

Issue

When attempting to automate the setup of Pelican using bash, the STDOUT output of the command pelican --print-settings VAR gets cluttered with non-related info.

$ pelican --print-settings PATH   2>/dev/null
[15:47:16] WARNING  WRITE_SELECTED is present in settings but this       settings.py:563
                    functionality was removed. It will have no effect.                  
           WARNING  Feeds generated without SITEURL set properly may not settings.py:678
                    be valid                                                            

PATH: '/home/user/admin/websites/example.test/content'

Confirmed that these WARNING outputs are using fd=1 (STDOUT) using strace -s132 -f pelican --print-settings PATH.

Ideally, these WARNINGS (and INFO and whatnots) should be outputted to UNIX STDERR so that we can better handle error scenario in GitHub Actions or other CIs as well.

  • OS version and name: Debian 12.2
  • Python version: Python 3.11
  • Pelican version: GIT HEAD
  • Link to theme: m.css
  • Links to plugins: none
  • Link to your site: n/a
  • Link to your source: n/a
@egberts egberts added the bug label Jun 21, 2024
@egberts
Copy link
Author

egberts commented Jun 27, 2024

Not sure where to put this snippet into the Pelican code base because it is missing a "front-end" binary for use with UNINSTALLED Pelican package (commonly used when testing UNINSTALLED Pelican).

Why is this pelican, main Python for Pelican, missing from the code tree?

A working snippet for ${top_dir}/pelican command:

#!python
# -*- coding: utf-8 -*-
import re
import sys
import logging
from pelican.__main__ import main


class InfoFilter(logging.Filter):
    def filter(self, rec):
        return rec.levelno in (logging.DEBUG, logging.INFO)


logger = logging.getLogger("__name__")
logger.setLevel(logging.DEBUG)

h1 = logging.StreamHandler(sys.stdout)
h1.setLevel(logging.DEBUG)
h1.addFilter(InfoFilter())
h2 = logging.StreamHandler()
h2.setLevel(logging.WARNING)

logger.addHandler(h1)
logger.addHandler(h2)

if __name__ == "__main__":

    sys.argv[0] = re.sub(r"(-script\.pyw|\.exe)?$", "", sys.argv[0])
    sys.exit(main())

@egberts
Copy link
Author

egberts commented Jul 4, 2024

When we type in <unix-command> --help (or <unix-command> -h, ouputs are to STDERR, no?

@virtadpt
Copy link

virtadpt commented Jul 4, 2024

Ordinarily, yes. I tried a few things from coreutils and that seems to be the case. A couple of other common utilities (mpg123, gcc, make) as well.

For whatever it's worth, I just ran pelican --print-settings 1>/dev/null on my workstation (Pelican v4.9.1, Python v3.12.3), and the output didn't show, so that means it was on stdout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants