Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xonsh uses native paths #10167

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

xonsh uses native paths #10167

wants to merge 4 commits into from

Conversation

scopatz
Copy link
Contributor

@scopatz scopatz commented Aug 16, 2020

I believe that this will fix the issue described in xonsh/xonsh#3676

CC melund

@scopatz scopatz requested a review from a team as a code owner August 16, 2020 23:08
@cla-bot cla-bot bot added the cla-signed [bot] added once the contributor has signed the CLA label Aug 16, 2020
@melund
Copy link
Contributor

melund commented Aug 17, 2020

Nope. It doesn't work.

Also, It doesn't fix the wrongs paths generated in .xonshrc by conda init xonsh

e.g. /C/Users/...

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
import sys as _sys
from types import ModuleType as _ModuleType
_mod = _ModuleType("xontrib.conda",
                   "Autogenerated from $(/C/Users/mel/Miniconda3/Scripts/conda.exe shell.xonsh hook)")
__xonsh__.execer.exec($("/C/Users/mel/Miniconda3/Scripts/conda.exe" "shell.xonsh" "hook"),

Fixing this manually, allows xonsh to start but gives a re.error trying to activate an environment.

snail@sea ~
🐌 conda activate pytest6
re.error: bad escape \U at position 2

snail@sea ~
🐌

@scopatz
Copy link
Contributor Author

scopatz commented Aug 21, 2020

Thanks @melund - I have seen this same behavior on windows now myself too

@scopatz
Copy link
Contributor Author

scopatz commented Aug 21, 2020

@melund - in your manual fix you probably needed to write \\U rather than \U, to avoid unicode interpolation

@scopatz
Copy link
Contributor Author

scopatz commented Aug 21, 2020

OK, I think I have fixed the path issue with the init command

@melund
Copy link
Contributor

melund commented Aug 21, 2020

@scopatz That fixes the init script.

But it leave the error _get_deactivate_scripts() in "activate.py".

``TypeError: expected str, bytes or os.PathLike object, not NoneType```

(base) snail@sea ~
🐌 conda activate pytest6

# >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<

    Traceback (most recent call last):
      File "C:\Users\mel\Miniconda3\lib\site-packages\conda\cli\main.py", line 140, in main
        return activator_main()
      File "C:\Users\mel\Miniconda3\lib\site-packages\conda\activate.py", line 1096, in main
        print(activator.execute(), end='')
      File "C:\Users\mel\Miniconda3\lib\site-packages\conda\activate.py", line 182, in execute
        return getattr(self, self.command)()
      File "C:\Users\mel\Miniconda3\lib\site-packages\conda\activate.py", line 156, in activate
        builder_result = self.build_activate(self.env_name_or_prefix)
      File "C:\Users\mel\Miniconda3\lib\site-packages\conda\activate.py", line 301, in build_activate
        return self._build_activate_stack(env_name_or_prefix, False)
      File "C:\Users\mel\Miniconda3\lib\site-packages\conda\activate.py", line 379, in _build_activate_stack
        deactivate_scripts = self._get_deactivate_scripts(old_conda_prefix)
      File "C:\Users\mel\Miniconda3\lib\site-packages\conda\activate.py", line 708, in _get_deactivate_scripts
        prefix, 'etc', 'conda', 'deactivate.d', '*' + self.script_extension
      File "C:\Users\mel\Miniconda3\lib\ntpath.py", line 76, in join
        path = os.fspath(path)
    TypeError: expected str, bytes or os.PathLike object, not NoneType

`$ C:\Users\mel\Miniconda3\Scripts\conda-script.py shell.xonsh activate pytest6`

  environment variables:
                 CIO_TEST=<not set>
                CONDA_BAT=C:\Users\mel\Miniconda3\condabin\conda.bat
        CONDA_DEFAULT_ENV=base
                CONDA_EXE=C:/Users/mel/Miniconda3/Scripts/conda.exe
    CONDA_PROMPT_MODIFIER=(base)
         CONDA_PYTHON_EXE=C:/Users/mel/Miniconda3/python.exe
               CONDA_ROOT=C:\Users\mel\Miniconda3
              CONDA_SHLVL=1
           CURL_CA_BUNDLE=<not set>
                 HOMEPATH=\Users\mel
                     PATH=C:\Users\mel\Miniconda3\condabin;C:\Program Files\WindowsApps\Microsof
                          t.WindowsTerminalPreview_1.2.2234.0_x64__8wekyb3d8bbwe;C:\WINDOWS\syst
                          em32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPo
                          werShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program
                          Files\TortoiseGit\bin;C:\Program
                          Files\dotnet\;C:\ProgramData\chocolatey\bin;C:\Program
                          Files\PowerShell\7\;C:\Program Files\Git\cmd;C:\Program
                          Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\mel\Minico
                          nda3;C:\Users\mel\Miniconda3\Library\mingw-w64\bin;C:\Users\mel\Minico
                          nda3\Library\usr\bin;C:\Users\mel\Miniconda3\Library\bin;C:\Users\mel\
                          Miniconda3\Scripts;C:\Users\mel\AppData\Local\Microsoft\WindowsApps;C:
                          \Users\mel\AppData\Local\Programs\Microsoft VS Code\bin;C:\Program
                          Files\CMake\bin;C:\Program Files (x86)\GitHub CLI\;C:\src\flutter\bin;
             PSMODULEPATH=C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\Windows
                          PowerShell\v1.0\Modules
         PYTHONIOENCODING=1252
       REQUESTS_CA_BUNDLE=<not set>
            SSL_CERT_FILE=<not set>

     active environment : None
            shell level : 1
       user config file : C:\Users\mel\.condarc
 populated config files : C:\Users\mel\.condarc
          conda version : 4.8.4
    conda-build version : 3.19.2
         python version : 3.7.6.final.0
       virtual packages : __cuda=10.2
       base environment : C:\Users\mel\Miniconda3  (writable)
           channel URLs : https://conda.anaconda.org/conda-forge/win-64
                          https://conda.anaconda.org/conda-forge/noarch
                          https://repo.anaconda.com/pkgs/main/win-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/win-64
                          https://repo.anaconda.com/pkgs/r/noarch
                          https://repo.anaconda.com/pkgs/msys2/win-64
                          https://repo.anaconda.com/pkgs/msys2/noarch
          package cache : C:\Users\mel\Miniconda3\pkgs
                          C:\Users\mel\.conda\pkgs
                          C:\Users\mel\AppData\Local\conda\conda\pkgs
       envs directories : C:\Users\mel\Miniconda3\envs
                          C:\Users\mel\.conda\envs
                          C:\Users\mel\AppData\Local\conda\conda\envs
               platform : win-64
             user-agent : conda/4.8.4 requests/2.22.0 CPython/3.7.6 Windows/10 Windows/10.0.19041
          administrator : False
             netrc file : None
           offline mode : False


An unexpected error has occurred. Conda has prepared the above report.

If submitted, this report will be used by core maintainers to improve
future releases of conda.
Would you like conda to send this report to the core maintainers?

@scopatz
Copy link
Contributor Author

scopatz commented Aug 21, 2020

@melund - that seems like it might be because you are in some weird state where $CONDA_PREFIX is not set. That error in the deactivate part is being caused by https://github.com/conda/conda/blob/master/conda/activate.py#L316. This seems like a general conda activation issues, rather than something specifically caused by the Xonsh activation here

@melund
Copy link
Contributor

melund commented Aug 23, 2020

Well. Somehow %CONDA_PREFIX% is not set after xonsh lunches. So I think it is a problem with the init script.

On a side note: The new conda activate system is mess on windows. If you have both conda init cmd.exe and conda init xonsh enabled. Then the both init scripts are always run when starting xonsh and I get this warnings:

WARNING: conda environment not activated properly. This is likely because you have a conda init inside of your ~/.bashrc (unix) or *.bat activation file (windows). This is causing conda to activate twice in xonsh. Please remove the conda init block from your other shell.

This is because the conda init cmd.exe hooks into HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun which will always run when xonsh starts.

@scopatz
Copy link
Contributor Author

scopatz commented Aug 23, 2020

If you have both conda init cmd.exe and conda init xonsh enabled.

Yeah I have seen that on Linux with Bash too

@jezdez jezdez added cli::xonsh pertains to the CLI in Xonsh cli pertains to the CLI interface labels Jun 1, 2021
@melund
Copy link
Contributor

melund commented Sep 13, 2021

@scopatz I have a potential fix for this. I will make a PR to your branch...

@melund
Copy link
Contributor

melund commented Sep 13, 2021

@scopatz Could I get you to accept the PR to your fork (scopatz#1)? I have also merged upstream/master so there is a chance that tests will pass this time.

@travishathaway travishathaway added the source::community catch-all for issues filed by community members label Feb 7, 2023
@travishathaway travishathaway reopened this Feb 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed [bot] added once the contributor has signed the CLA cli::xonsh pertains to the CLI in Xonsh cli pertains to the CLI interface source::community catch-all for issues filed by community members
Projects
Status: 🆕 New
Development

Successfully merging this pull request may close these issues.

None yet

4 participants