def print_pep582_command(ui: termui.UI, shell: str = "AUTO"): """Print the export PYTHONPATH line to be evaluated by the shell.""" import shellingham if os.name == "nt": try: set_env_in_reg("PYTHONPATH", PEP582_PATH) except PermissionError: ui.echo( termui.red( "Permission denied, please run the terminal as administrator." ), err=True, ) ui.echo( termui.green("The environment variable has been saved, " "please restart the session to take effect.")) return lib_path = PEP582_PATH.replace("'", "\\'") if shell == "AUTO": shell = shellingham.detect_shell()[0] shell = shell.lower() if shell in ("zsh", "bash"): result = f"export PYTHONPATH='{lib_path}':$PYTHONPATH" elif shell == "fish": result = f"set -x PYTHONPATH '{lib_path}' $PYTHONPATH" elif shell in ("tcsh", "csh"): result = f"setenv PYTHONPATH '{lib_path}':$PYTHONPATH" else: raise PdmUsageError( f"Unsupported shell: {shell}, please specify another shell " "via `--pep582 <SHELL>`") ui.echo(result)
def print_pep582_command(shell: str = "AUTO"): """Print the export PYTHONPATH line to be evaluated by the shell.""" import shellingham if os.name == "nt": set_env_in_reg("PYTHONPATH", PEP582_PATH) return lib_path = PEP582_PATH.replace("'", "\\'") if shell == "AUTO": shell = shellingham.detect_shell()[0] shell = shell.lower() if shell in ("zsh", "bash"): result = f"export PYTHONPATH='{lib_path}':$PYTHONPATH" elif shell == "fish": result = f"set -x PYTHONPATH '{lib_path}' $PYTHONPATH" elif shell in ("tcsh", "csh"): result = f"setenv PYTHONPATH '{lib_path}':$PYTHONPATH" else: raise PdmUsageError( f"Unsupported shell: {shell}, please specify another shell " "via `--pep582 <SHELL>`") stream.echo(result)