Log in or init with insufficient user information#

!lamin close
import lamindb_setup as lnsetup
from lamindb_setup.dev._settings_store import (
    current_user_settings_file,
    get_settings_file_name_prefix,
    settings_dir,
)
import pytest

Log in with in-sufficient information#

with pytest.raises(TypeError):
    lnsetup.login()

If we add an email or handle it looks up the password from the stored env file (lamin login testuser1@lamin.ai):

lnsetup.login("testuser1@lamin.ai")

Now, let’s start with a fresh environment without any user profiles stored.

(
    settings_dir / f"{get_settings_file_name_prefix()}user--testuser1@lamin.ai.env"
).unlink()
(settings_dir / f"{get_settings_file_name_prefix()}user--testuser1.env").unlink()
current_user_settings_file().unlink()

If we try to login with a handle at first login, this will error:

with pytest.raises(RuntimeError):
    lnsetup.login("testuser1", password="cEvcwMJFX4OwbsYVaMt2Os6GxxGgDUlBGILs2RyS")

If we try to login without password, this will error:

with pytest.raises(RuntimeError):
    lnsetup.login("testuser1@lamin.ai")

If we try login with a wrong password, this will error:

from gotrue.errors import AuthApiError

with pytest.raises(AuthApiError):
    lnsetup.login("testuser1@lamin.ai", key="hello")

Hence, we need to login once with email and password:

lnsetup.login("testuser1@lamin.ai", key="cEvcwMJFX4OwbsYVaMt2Os6GxxGgDUlBGILs2RyS")

And now we can have the convenient login just with the handle.

lnsetup.login("testuser1")

Init with insufficient information#

current_user_settings_file().unlink()

We’d also get an error about not being logged in if we try to init an instance without it being set:

with pytest.raises(Exception):
    lnsetup.init(storage="mydata")

Let’s log in again.

lnsetup.login("testuser1")

Let’s now try to init without providing storage (lamin init):

with pytest.raises(TypeError):
    lnsetup.init()