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

Fix finding mamba on windows #135

Merged
merged 6 commits into from
Apr 17, 2021

Conversation

ericpre
Copy link
Contributor

@ericpre ericpre commented Apr 10, 2021

The following fails on windows:

from subprocess import PIPE, Popen

which = "where"

process = Popen(
    [which, "mamba"], stdout=PIPE, stderr=PIPE, encoding="utf-8"
)
output, error = process.communicate()

if process.returncode != 0:
    raise RuntimeError(error)

mamba_exe = output.strip() or "mamba"

process = Popen(
    [mamba_exe, "--version"],
    stdout=PIPE,
    stderr=PIPE,
    encoding="

with the error:

Traceback (most recent call last):

  File "<ipython-input-1-2076a85bac6b>", line 15, in <module>
    process = Popen(

  File "C:\Users\Eric\HyperSpy-bundle\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in __init__
    super(SubprocessPopen, self).__init__(*args, **kwargs)

  File "C:\Users\Eric\HyperSpy-bundle\lib\subprocess.py", line 858, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,

  File "C:\Users\Eric\HyperSpy-bundle\lib\subprocess.py", line 1311, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,

FileNotFoundError: [WinError 2] The system cannot find the file specified

Because output is 'C:\\Users\\Eric\\HyperSpy-bundle\\Scripts\\mamba.exe\nC:\\Users\\Eric\\HyperSpy-bundle\\condabin\\mamba.bat\n'

I have tried to add a test but I don't understand how the test suite works.

@github-actions
Copy link

Binder 👈 Launch a binder notebook on the branch ericpre/gator/fix_finding_mamba_windows

@fcollonval
Copy link
Member

Good catch @ericpre - thanks a lot for that.

To make it more robust, I propose to change a bit the following code:

-                which = "which"
+                cmd = ["which", "mamba"]
                 if sys.platform == "win32":
-                    which = "where"
+                    cmd =["where", "mamba.exe"]

                 process = Popen(
-                    [which, "mamba"], stdout=PIPE, stderr=PIPE, encoding="utf-8"
+                    cmd, stdout=PIPE, stderr=PIPE, encoding="utf-8"
                 )

So we are sure to capture an executable on Windows and not the shell script.

Regarding testing, the tests are stored in the mamba_gator/tests folder. I would advice creating a new file for this one like test_manager.py (it must start with test_).

Then in that file, the test functions are all function named def test_...(). I would suggest instantiating a EnvManager instance and test the property manager; something like:

def test_EnvManager_manager():
    try:
        import mamba
    except ImportError:
        expected = "conda"
    else:
        expected = "mamba"

    manager = EnvManager("", None)
    
    assert Path(manager.manager).stem == expected

Let me known if you have questions.

@ericpre
Copy link
Contributor Author

ericpre commented Apr 11, 2021

Thanks, your test is god and simple! My issue was mainly with getting a EnvManager instance working. I have tried to do something similar to

class TestCondaVersion(JupyterCondaAPITest):
def test_version(self):
EnvManager._conda_version = None
self.assertIsNone(EnvManager._conda_version)
self.conda_api.get(
["environments",]
)
self.assertIsNotNone(EnvManager._conda_version)
for mamba and it was not working.

Copy link
Member

@fcollonval fcollonval left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ericpre and sorry for the delay - your PR highlights that the CI was actually not testing Mamba has intended.

@fcollonval fcollonval merged commit 86ba9d0 into mamba-org:master Apr 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants