-
Notifications
You must be signed in to change notification settings - Fork 34
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
Add typehints to much of the core code. #379
Changes from all commits
c322c68
e637292
1c38127
2a9ad46
3cb3b9c
0a74eef
6251bd0
d843847
1a45b92
c2ca736
bd3eb2f
2af829b
10d3a12
734f76d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ repos: | |
rev: 5.12.0 | ||
hooks: | ||
- id: isort | ||
|
||
- repo: https://github.com/pycqa/flake8 | ||
rev: 6.1.0 | ||
hooks: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
import os | ||
import subprocess | ||
from typing import Dict, Optional, Tuple, Type | ||
|
||
from rubicon_ml.exceptions import RubiconException | ||
from rubicon_ml.repository import LocalRepository, MemoryRepository, S3Repository | ||
from rubicon_ml.repository import ( | ||
BaseRepository, | ||
LocalRepository, | ||
MemoryRepository, | ||
S3Repository, | ||
) | ||
|
||
|
||
class Config: | ||
|
@@ -29,18 +35,22 @@ class Config: | |
""" | ||
|
||
PERSISTENCE_TYPES = ["filesystem", "memory"] | ||
REPOSITORIES = { | ||
REPOSITORIES: Dict[str, Type[BaseRepository]] = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we need the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ahh gotcha, makes sense |
||
"memory-memory": MemoryRepository, | ||
"filesystem-local": LocalRepository, | ||
"filesystem-s3": S3Repository, | ||
} | ||
|
||
def __init__( | ||
self, persistence=None, root_dir=None, is_auto_git_enabled=False, **storage_options | ||
self, | ||
persistence: Optional[str] = None, | ||
root_dir: Optional[str] = None, | ||
is_auto_git_enabled: bool = False, | ||
**storage_options, | ||
): | ||
self.storage_options = storage_options | ||
if storage_options is not None and "composite_config" in storage_options: | ||
composite_config = storage_options.get("composite_config") | ||
composite_config = storage_options.get("composite_config", []) | ||
repositories = [] | ||
for config in composite_config: | ||
self.persistence, self.root_dir, self.is_auto_git_enabled = self._load_config( | ||
|
@@ -62,7 +72,9 @@ def _check_is_in_git_repo(self): | |
"Not a `git` repo: Falied to locate the '.git' directory in this or any parent directories." | ||
) | ||
|
||
def _load_config(self, persistence, root_dir, is_auto_git_enabled): | ||
def _load_config( | ||
self, persistence: Optional[str], root_dir: Optional[str], is_auto_git_enabled: bool | ||
) -> Tuple[str, Optional[str], bool]: | ||
"""Get the configuration values.""" | ||
persistence = os.environ.get("PERSISTENCE", persistence) | ||
if persistence not in self.PERSISTENCE_TYPES: | ||
|
@@ -77,7 +89,7 @@ def _load_config(self, persistence, root_dir, is_auto_git_enabled): | |
|
||
return (persistence, root_dir, is_auto_git_enabled) | ||
|
||
def _get_protocol(self): | ||
def _get_protocol(self) -> str: | ||
"""Get the file protocol of the configured root directory.""" | ||
if self.persistence == "memory": | ||
return "memory" | ||
|
@@ -89,7 +101,7 @@ def _get_protocol(self): | |
|
||
return "custom" # catch-all for external backends | ||
|
||
def _get_repository(self): | ||
def _get_repository(self) -> BaseRepository: | ||
"""Get the repository for the configured persistence type.""" | ||
protocol = self._get_protocol() | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have to look into why the
config
is optional - that doesn't seem rightThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the default value here is
None
, do we need to make it required?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not in this PR, maybe in the future. I think its a remnant of the fact that
Rubicon
used to extend theBase
and didn't take in a config since it generated it. I'll verify that's the case and if so make an issue to fix it