https://bugs.kde.org/show_bug.cgi?id=495907

            Bug ID: 495907
           Summary: Scripter and pip:  'DocWrapper' object has no
                    attribute 'flush'
    Classification: Applications
           Product: krita
           Version: 5.2.6
          Platform: Ubuntu
                OS: Linux
            Status: REPORTED
          Severity: wishlist
          Priority: NOR
         Component: Scripting
          Assignee: [email protected]
          Reporter: [email protected]
  Target Milestone: ---

SUMMARY

Calling pip from Scripter does not work due to `runaction` replacing `stderr`
and `stdout` with a `DocWrapper` object. DocWrapper does not have a flush
attribute, which is needed by the `rich` package (used by pip).

STEPS TO REPRODUCE
1.  Install pip to a folder within sys.path.
2.  Open Scripter, and import runpy; then run the following script:
    import runpy
    import sys

    def passive_exit(exitCode)
        return exitCode

    sys.argv = ['', 'install', 'numpy' ]
    sys.exit = passive_exit
    runpy.run_module('pip', run_name='__main__')

OBSERVED RESULT

--- Logging error ---
Traceback (most recent call last):
  File
"/home/username/.local/share/krita/pykrita/pip/_internal/utils/logging.py",
line 177, in emit
    self.console.print(renderable, overflow="ignore", crop=False, style=style)
  File "/home/username/.local/share/krita/pykrita/pip/_vendor/rich/console.py",
line 1673, in print
    with self:
  File "/home/username/.local/share/krita/pykrita/pip/_vendor/rich/console.py",
line 865, in __exit__
    self._exit_buffer()
  File "/home/username/.local/share/krita/pykrita/pip/_vendor/rich/console.py",
line 823, in _exit_buffer
    self._check_buffer()
  File "/home/username/.local/share/krita/pykrita/pip/_vendor/rich/console.py",
line 2065, in _check_buffer
    self.file.flush()
AttributeError: 'DocWrapper' object has no attribute 'flush'
Call stack:
  File
"/tmp/.mount_krita-CyLgzy/usr/share/krita/pykrita/scripter/ui_scripter/actions/runaction/runaction.py",
line 76, in run
    users_module = self.run_py3_document(document)
  File
"/tmp/.mount_krita-CyLgzy/usr/share/krita/pykrita/scripter/ui_scripter/actions/runaction/runaction.py",
line 139, in run_py3_document
    spec.loader.exec_module(users_module)
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/username/development/faycian/krita/scripter_attempt.py", line 9,
in <module>
    runpy.run_module('pip', run_name='__main__')
  File "/tmp/.mount_krita-CyLgzy/usr/lib/python3.10/runpy.py", line 227, in
run_module
    return _run_code(code, {}, init_globals, run_name, mod_spec)
  File "/tmp/.mount_krita-CyLgzy/usr/lib/python3.10/runpy.py", line 86, in
_run_code
    exec(code, run_globals)
  File "/home/username/.local/share/krita/pykrita/pip/__main__.py", line 24, in
<module>
    sys.exit(_main())
  File "/home/username/.local/share/krita/pykrita/pip/_internal/cli/main.py",
line 80, in main
    return command.main(cmd_args)
  File
"/home/username/.local/share/krita/pykrita/pip/_internal/cli/base_command.py",
line 157, in main
    return self._main(args)
  File
"/home/username/.local/share/krita/pykrita/pip/_internal/cli/base_command.py",
line 231, in _main
    return self._run_wrapper(level_number, options, args)
  File
"/home/username/.local/share/krita/pykrita/pip/_internal/cli/base_command.py",
line 105, in _run_wrapper
    status = _inner_run()
  File
"/home/username/.local/share/krita/pykrita/pip/_internal/cli/base_command.py",
line 96, in _inner_run
    return self.run(options, args)
  File
"/home/username/.local/share/krita/pykrita/pip/_internal/cli/req_command.py",
line 67, in wrapper
    return func(self, options, args)
  File
"/home/username/.local/share/krita/pykrita/pip/_internal/commands/install.py",
line 501, in run
    write_output(
  File "/home/username/.local/share/krita/pykrita/pip/_internal/utils/misc.py",
line 374, in write_output
    logger.info(msg, *args)
  File "/tmp/.mount_krita-CyLgzy/usr/lib/python3.10/logging/__init__.py", line
1477, in info
    self._log(INFO, msg, args, **kwargs)
  File "/tmp/.mount_krita-CyLgzy/usr/lib/python3.10/logging/__init__.py", line
1624, in _log
    self.handle(record)
  File "/tmp/.mount_krita-CyLgzy/usr/lib/python3.10/logging/__init__.py", line
1634, in handle
    self.callHandlers(record)
  File "/tmp/.mount_krita-CyLgzy/usr/lib/python3.10/logging/__init__.py", line
1696, in callHandlers
    hdlr.handle(record)
  File "/tmp/.mount_krita-CyLgzy/usr/lib/python3.10/logging/__init__.py", line
968, in handle
    self.emit(record)
  File
"/home/username/.local/share/krita/pykrita/pip/_internal/utils/logging.py",
line 179, in emit
    self.handleError(record)

EXPECTED RESULT

Successful installation without error.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Ubuntu MATE 24.04.1
Qt Version: As per Krita 5.2.6 appimage

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to