prompt-toolkit / ptpython

A better Python REPL
BSD 3-Clause "New" or "Revised" License
5.2k stars 277 forks source link

How to configure in windows environment? #304

Open gt299792 opened 5 years ago

gt299792 commented 5 years ago

In Linux, It can create a ~/.ptpython/config.py file to customize the configuration. But, I use ptpython in windows, where can I create this file.

zachvalenta commented 5 years ago

afaik you should be able to set this via CLI flag:

ptpython --config-dir=path/to/dir

https://github.com/prompt-toolkit/ptpython/blob/0b97478e6f6ee3cb0abdd7d99ffe6f0f9c7a9a4c/ptpython/entry_points/run_ptpython.py#L12

gt299792 commented 5 years ago

If I don't want use flag, I want to use config file automatically. Is there any way to setup the default config path?

timsavage commented 4 years ago

The default config file location is at os.path.expanduser("~/.ptpython/config.py") .

For me on Windows 7 that is C:\Users\USERNAME\.ptpython\config.py

timsavage commented 4 years ago

Covered in pull request #324

daytonb commented 4 years ago

In case someone else comes looking, on Windows you can put the config.py in %LOCALAPPDATA%\prompt_toolkit\ptpython\ folder.

I found this location because ptpython kept complaining that my history file was still in %USERPROFILE%\.ptpython\history rather than the new location %LOCALAPPDATA%\prompt_toolkit\ptpython\history.

SpaceShaman commented 2 years ago

On windows you can set the default config also by adding to the environment variables a variable named "PYTHONSTARTUP" with the path to the file with the following code:

import sys

def configure(repl):
    """
    Configuration method. This is called during the start-up of ptpython.
    :param repl: `PythonRepl` instance.
    """
    # Show function signature (bool).
    repl.show_signature = True

    # Show docstring (bool).
    repl.show_docstring = True

    # Fuzzy and dictionary completion.
    repl.enable_fuzzy_completion = True

    # Enable auto suggestions. (Pressing right arrow will complete the input,
    # based on the history.)
    repl.enable_auto_suggest = True

try:
    from ptpython.repl import embed
except ImportError:
    print("ptpython is not available: falling back to standard prompt")
else:
    sys.exit(embed(globals(), locals(), configure=configure))

This will make ptpython your default Python REPL along with your custom setting. Follow this link for instructions on how to set up PYTHONPATH: https://stackoverflow.com/questions/4208659/when-to-use-sys-path-append-and-when-modifying-pythonpath-is-enough/4209102#4209102

zbyna commented 2 years ago

In case someone else comes looking, on Windows you can put the config.py in %LOCALAPPDATA%\prompt_toolkit\ptpython\ folder.

I found this location because ptpython kept complaining that my history file was still in %USERPROFILE%\.ptpython\history rather than the new location %LOCALAPPDATA%\prompt_toolkit\ptpython\history.

λ ptpython Warning: ~/.ptpython/config.py is deprecated, move your configuration to C:\Users\decak\AppData\Local\prompt_toolkit\ptpython\config.py