Skip to content

♻️ Remove auto-connect switches #138

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions lamin_cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,20 +181,19 @@ def init(
@click.argument("instance", type=str)
# fmt: on
def connect(instance: str):
"""Connect to an instance.
"""Configure an instance for auto-connect.

Pass a slug (`account/name`) or URL (`https://lamin.ai/account/name`).

`lamin connect` switches
{attr}`~lamindb.setup.core.SetupSettings.auto_connect` to `True` so that you
auto-connect in a Python session upon importing `lamindb`.
`lamin connect` configures a current instance in your local user environment
to which you auto-connect in subsequent CLI operations, Python, or R sessions.

For manually connecting in a Python session, use {func}`~lamindb.connect`.
Alternatively, you can connect to a Python session via {func}`~lamindb.connect`
without changing the current instance.
"""
from lamindb_setup import connect as connect_
from lamindb_setup import settings as settings_

settings_.auto_connect = True
return connect_(instance, _reload_lamindb=False, _write_settings=True)


Expand Down Expand Up @@ -269,7 +268,6 @@ def load(entity: str, uid: str | None = None, key: str | None = None, with_env:
# click.echo(
# f"! please use: lamin connect {entity}"
# )
settings_.auto_connect = True
return connect(entity, _reload_lamindb=False, _write_settings=True)
else:
from lamin_cli._load import load as load_
Expand Down
22 changes: 5 additions & 17 deletions lamin_cli/_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,9 @@ def save_from_path_cli(
branch: str | None,
registry: str | None,
) -> str | None:
import lamindb_setup as ln_setup
from lamindb_setup.core.upath import LocalPathClasses, UPath, create_path

# this will be gone once we get rid of lamin load or enable loading multiple
# instances sequentially
auto_connect_state = ln_setup.settings.auto_connect
ln_setup.settings.auto_connect = True

import lamindb as ln

if not ln.setup.core.django.IS_SETUP:
sys.exit(-1)
from lamindb._finish import save_context_core

ln_setup.settings.auto_connect = auto_connect_state
from lamindb_setup.core.upath import LocalPathClasses, UPath, create_path

# this allows to have the correct treatment of credentials in case of cloud paths
path = create_path(path)
Expand Down Expand Up @@ -144,13 +132,13 @@ def save_from_path_cli(
artifact.save()
logger.important(f"saved: {artifact}")
logger.important(f"storage path: {artifact.path}")
if ln_setup.settings.storage.type == "s3":
if ln.setup.settings.storage.type == "s3":
logger.important(f"storage url: {artifact.path.to_url()}")
if project is not None:
artifact.projects.add(project_record)
logger.important(f"labeled with project: {project_record.name}")
if ln_setup.settings.instance.is_remote:
slug = ln_setup.settings.instance.slug
if ln.setup.settings.instance.is_remote:
slug = ln.setup.settings.instance.slug
logger.important(f"go to: https://lamin.ai/{slug}/artifact/{artifact.uid}")
return None

Expand Down Expand Up @@ -239,7 +227,7 @@ def save_from_path_cli(
logger.important(f"labeled with project: {project_record.name}")
# latest run of this transform by user
run = ln.Run.filter(transform=transform).order_by("-started_at").first()
if run is not None and run.created_by.id != ln_setup.settings.user.id:
if run is not None and run.created_by.id != ln.setup.settings.user.id:
response = input(
"You are trying to save a transform created by another user: Source"
" and report files will be tagged with *your* user id. Proceed?"
Expand Down
1 change: 0 additions & 1 deletion tests/core/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ def pytest_sessionstart(session: pytest.Session):
storage="./default_storage_cli",
name="lamin-cli-unit-tests",
)
ln.setup.settings.auto_connect = True


def pytest_sessionfinish(session: pytest.Session):
Expand Down