Saturday, April 6, 2024

I made some test to check whether redirection to stderr and/or stdout work as expected. It does so, perfectly.

$ pip install -U django
Requirement already satisfied: django in .../lib/python3.10/site-packages (5.0.4)
Requirement already satisfied: asgiref<4,>=3.7.0 in .../lib/python3.10/site-packages (from django) (3.7.2)
Requirement already satisfied: sqlparse>=0.3.1 in .../lib/python3.10/site-packages (from django) (0.4.2)
Requirement already satisfied: typing-extensions>=4 in .../lib/python3.10/site-packages (from asgiref<4,>=3.7.0->django) (4.8.0)
$ pip install -U django > tmp.txt
$ cat tmp.txt
Requirement already satisfied: django in .../lib/python3.10/site-packages (5.0.4)
Requirement already satisfied: asgiref<4,>=3.7.0 in .../lib/python3.10/site-packages (from django) (3.7.2)
Requirement already satisfied: sqlparse>=0.3.1 in .../lib/python3.10/site-packages (from django) (0.4.2)
Requirement already satisfied: typing-extensions>=4 in .../lib/python3.10/site-packages (from asgiref<4,>=3.7.0->django) (4.8.0)

$ pip install -U djangofoo
ERROR: Could not find a version that satisfies the requirement djangofoo (from versions: none)
ERROR: No matching distribution found for djangofoo
$ pip install -U djangofoo > tmp.txt
ERROR: Could not find a version that satisfies the requirement djangofoo (from versions: none)
ERROR: No matching distribution found for djangofoo
$ cat tmp.txt
$

When I deliberately introduce a mistake into settings.py so that pm prep fails, then the traceback is sent to stderr (not to stdout):

$ go chatter
$ pm prep --noinput > tmp.txt
$ nano settings.py # (modify settings.py)
$ pm prep --noinput > tmp.txt
Traceback (most recent call last):
  File ".../projects/chatter/manage.py", line 8, in <module>
    execute_from_command_line(sys.argv)
  File ".../lib/python3.10/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File ".../lib/python3.10/site-packages/django/core/management/__init__.py", line 382, in execute
    settings.INSTALLED_APPS
  File ".../lib/python3.10/site-packages/django/conf/__init__.py", line 89, in __getattr__
    self._setup(name)
  File ".../lib/python3.10/site-packages/django/conf/__init__.py", line 76, in _setup
    self._wrapped = Settings(settings_module)
  File ".../lib/python3.10/site-packages/django/conf/__init__.py", line 190, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File ".../projects/chatter/settings/demo.py", line 5, in <module>
    class Site(Site):
  File ".../projects/chatter/settings/demo.py", line 7, in Site
    the_demo_date = i2d(201410231)
  File ".../rstgen/rstgen/utils.py", line 84, in i2d
    raise Exception("Invalid date specification {0}.".format(i))
Exception: Invalid date specification 201410231.
$ cat tmp.txt
$