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

♻️ Overhaul init for more convenient use in laminhub #857

Merged
merged 20 commits into from
Sep 24, 2024
Merged

Conversation

Koncopd
Copy link
Member

@Koncopd Koncopd commented Sep 18, 2024

https://github.com/laminlabs/laminhub/issues/1271

This moves all internal utility arguments to kwargs in lamindb_setup.connect.
Adds 2 additional arguments: _user and _write_settings.

  1. _user allows to pass user settings (with access_token) to connect and they are used instead of lamindb_setup.settings.user.
  2. _write_settings when set to False forces connect not to write any settings env files. It is set to True by default for now.

I believe this addresses point 1-2 in the linked issue.

@Koncopd Koncopd marked this pull request as draft September 18, 2024 16:02

kwargs.get("access_token", None)
_raise_not_found_error = kwargs.get("_raise_not_found_error", True)
_test = kwargs.get("_test", False)
Copy link
Member Author

Choose a reason for hiding this comment

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

@falexwolf are you fine with moving all internal arguments to kwargs in connect and init?

Copy link
Member

Choose a reason for hiding this comment

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

Ok!

Copy link
Member

Choose a reason for hiding this comment

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

I thought about this again and what I'd prefer is to have a properly typed signature of a function called connect_internal() that's wrapped by the user-facing connect().

This way we eliminate **kwargs. We really shouldn't have them anywhere unless those places where we can't come up with a different solution.

Copy link
Member

Choose a reason for hiding this comment

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

The user-facing connect() will be super minimal and simple after also incorporating this change: #862

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree, i just think that this probably to do in another PR, it requires a lot of other things, its own tests etc that i don't want to do here.

Copy link
Member

Choose a reason for hiding this comment

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

Ok!

Copy link

github-actions bot commented Sep 18, 2024

@github-actions github-actions bot temporarily deployed to pull request September 18, 2024 16:08 Inactive
Copy link

codecov bot commented Sep 18, 2024

Codecov Report

Attention: Patch coverage is 80.48780% with 16 lines in your changes missing coverage. Please review.

Project coverage is 83.52%. Comparing base (7f2bbb1) to head (b7c8912).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
lamindb_setup/_connect_instance.py 70.83% 7 Missing ⚠️
lamindb_setup/_init_instance.py 80.00% 6 Missing ⚠️
lamindb_setup/core/cloud_sqlite_locker.py 50.00% 2 Missing ⚠️
lamindb_setup/core/_settings_instance.py 88.88% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #857      +/-   ##
==========================================
+ Coverage   83.45%   83.52%   +0.07%     
==========================================
  Files          43       43              
  Lines        3367     3400      +33     
==========================================
+ Hits         2810     2840      +30     
- Misses        557      560       +3     
Flag Coverage Δ
83.52% <80.48%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions github-actions bot temporarily deployed to pull request September 18, 2024 16:55 Inactive
@github-actions github-actions bot temporarily deployed to pull request September 19, 2024 08:20 Inactive
@github-actions github-actions bot temporarily deployed to pull request September 19, 2024 09:10 Inactive
@github-actions github-actions bot temporarily deployed to pull request September 19, 2024 10:53 Inactive
@github-actions github-actions bot temporarily deployed to pull request September 19, 2024 16:15 Inactive
@github-actions github-actions bot temporarily deployed to pull request September 19, 2024 17:19 Inactive
@github-actions github-actions bot temporarily deployed to pull request September 20, 2024 08:22 Inactive
@github-actions github-actions bot temporarily deployed to pull request September 20, 2024 08:42 Inactive
@github-actions github-actions bot temporarily deployed to pull request September 20, 2024 10:59 Inactive
@github-actions github-actions bot temporarily deployed to pull request September 20, 2024 11:32 Inactive
@Koncopd Koncopd marked this pull request as ready for review September 20, 2024 12:31
@Koncopd
Copy link
Member Author

Koncopd commented Sep 23, 2024

@falexwolf @fredericenard this is ready for a review.

except InstanceNotFoundError as e:
if _raise_not_found_error:
raise e
else:
return "instance-not-found"
if isinstance(isettings, str):
return isettings
# after we checked that isettings is not a string
Copy link
Member

Choose a reason for hiding this comment

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

The comment here is incomprehensible to me just because the wording is poor.

Copy link
Member Author

Choose a reason for hiding this comment

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

edited

client: Client,
ssettings: StorageSettings,
auto_populate_instance: bool,
created_by: str | None = None,
Copy link
Member

Choose a reason for hiding this comment

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

Can you call this created_by_uuid and type it with UUID instead of str? The conversion via .hex should come right before hitting the REST API so the the code internals are all properly typed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Can i leave it created_by, but redo the typing? Because i think it is just redundant to do both, i.e. renaming to created_by_uuid and typing with UUID?

Copy link
Member Author

Choose a reason for hiding this comment

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

Now using UUID.



def _init_instance(isettings: InstanceSettings, client: Client) -> None:
def _init_instance(
client: Client, isettings: InstanceSettings, account_id: str | None = None
Copy link
Member

Choose a reason for hiding this comment

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

Well, I guess it works if client is the first argument. Then let's keep it this way.

But account_id has to be a UUID not a str!

Copy link
Member Author

Choose a reason for hiding this comment

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

done

shutil.copy2(filepath, current_instance_settings_file())
# persist under settings class for same session reference
# need to import here to avoid circular import
def _persist(self, write: bool = True) -> None:
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a docstring or make this more explicit by calling the arg save_to_disk or similar?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Copy link
Member

@falexwolf falexwolf left a comment

Choose a reason for hiding this comment

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

Great, Sergei! Only very small changes requested from my side.

@Koncopd
Copy link
Member Author

Koncopd commented Sep 23, 2024

Thx, will address the comments.

@falexwolf falexwolf changed the title ♻️ Rework init for use in laminhub ♻️ Overhaul init for use in laminhub Sep 24, 2024
@falexwolf falexwolf changed the title ♻️ Overhaul init for use in laminhub ♻️ Overhaul init for more convenient use in laminhub Sep 24, 2024
@github-actions github-actions bot temporarily deployed to pull request September 24, 2024 09:37 Inactive
@falexwolf falexwolf self-requested a review September 24, 2024 10:10
@github-actions github-actions bot temporarily deployed to pull request September 24, 2024 11:05 Inactive
@github-actions github-actions bot temporarily deployed to pull request September 24, 2024 11:18 Inactive
@Koncopd Koncopd merged commit 6498329 into main Sep 24, 2024
12 of 13 checks passed
@Koncopd Koncopd deleted the rework_init branch September 24, 2024 11:18
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