Git Product home page Git Product logo

Comments (10)

vstinner avatar vstinner commented on June 12, 2024 2

Maybe add a site._CAN_USE_PYREPL constant and modify _pyrepl/__main__.py to set site._CAN_USE_PYREPL?

from cpython.

mi1acl avatar mi1acl commented on June 12, 2024 2

I can do this if it's ok

from cpython.

mi1acl avatar mi1acl commented on June 12, 2024 1

@danielhollas I worked with @lysnikolaou during PyCon sprints on this one, we came to the same conclusion but he said this is not the best practice to export the env variable to the system. He said he will take a deeper look as to why this might be happening

from cpython.

vstinner avatar vstinner commented on June 12, 2024 1

I proposed PR gh-119269 to fix this issue.

from cpython.

danielhollas avatar danielhollas commented on June 12, 2024

Looks like the write_history callback is registered in site.py here:

def write_history():

        def write_history():
            try:
                if os.getenv("PYTHON_BASIC_REPL"):
                    readline.write_history_file(history)
                else:
                    _pyrepl.readline.write_history_file(history)
            except (FileNotFoundError, PermissionError):
                # home directory does not exist or is not writable
                # https://bugs.python.org/issue19891
                pass

It clearly needs to get more clever to detect whether pyrepl is actually in use.

Maybe it can just look at the _pyrepl.__main__.CAN_USE_PYREPL global.

from cpython.

eugenetriguba avatar eugenetriguba commented on June 12, 2024

@danielhollas CAN_USE_PYREPL just checks whether we're on a Windows system, so I wouldn't think checking that would help in this case.

Maybe: We set PYTHON_BASIC_REPL to true if TERM is set to "dumb"?

from cpython.

danielhollas avatar danielhollas commented on June 12, 2024

@eugenetriguba if you look at the _pyrepl/__main__.py, CAN_USE_PYREPL is indeed checking for windows at import, but then later it is set to False if for any reason the new repl cannot be used, on line 41.

I tried to fix this by checking CAN_USE_PYREPL in the write_history callback function but couldn't make it work -- accessing CAN_USE_PYREPL from __main__ module seems to be cursed, and moving it to __init__ did not help.

from cpython.

danielhollas avatar danielhollas commented on June 12, 2024

Maybe: We set PYTHON_BASIC_REPL to true if TERM is set to "dumb"?

The following patch indeed fixes the issue, happy to make a PR if this seems like a right approach

diff --git a/Lib/_pyrepl/__main__.py b/Lib/_pyrepl/__main__.py
index c598019e7c..40cdd6d9fe 100644
--- a/Lib/_pyrepl/__main__.py
+++ b/Lib/_pyrepl/__main__.py
@@ -39,6 +39,7 @@ def interactive_console(mainmodule=None, quiet=False, pythonstartup=False):
         trace(msg)
         print(msg, file=sys.stderr)
         CAN_USE_PYREPL = False
+        os.environ["PYTHON_BASIC_REPL"] = "true"
     if run_interactive is None:
         return sys._baserepl()
     return run_interactive(mainmodule)

from cpython.

lysnikolaou avatar lysnikolaou commented on June 12, 2024

Leaving this open since #119269 did not fix the problem.

from cpython.

vstinner avatar vstinner commented on June 12, 2024

Please check my second fix: PR gh-119332.

from cpython.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.