Skip to content

Commit

Permalink
More docstrings cleanup (#1232)
Browse files Browse the repository at this point in the history
  • Loading branch information
carolineechen authored Sep 4, 2024
1 parent bfbb78a commit bbbd641
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 45 deletions.
4 changes: 2 additions & 2 deletions runhouse/resources/folders/gcs_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import shutil
import subprocess
from pathlib import Path
from typing import List, Optional
from typing import Dict, List, Optional

from runhouse.logger import get_logger

Expand All @@ -23,7 +23,7 @@ def __init__(self, dryrun: bool, **kwargs):
self._urlpath = "gs://"

@staticmethod
def from_config(config: dict, dryrun=False, _resolve_children=True):
def from_config(config: Dict, dryrun: bool = False, _resolve_children: bool = True):
"""Load config values into the object."""
return GCSFolder(**config, dryrun=dryrun)

Expand Down
13 changes: 9 additions & 4 deletions runhouse/resources/folders/s3_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import subprocess
import time
from pathlib import Path
from typing import List, Optional
from typing import Dict, List, Optional, Union

from runhouse.logger import get_logger

Expand All @@ -28,7 +28,7 @@ def __init__(self, dryrun: bool, **kwargs):
self._urlpath = "s3://"

@staticmethod
def from_config(config: dict, dryrun=False, _resolve_children=True):
def from_config(config: Dict, dryrun: bool = False, _resolve_children: bool = True):
"""Load config values into the object."""
return S3Folder(**config, dryrun=dryrun)

Expand Down Expand Up @@ -115,7 +115,12 @@ def _s3_copy(self, new_path):
Key=new_key,
)

def put(self, contents, overwrite=False, mode: str = "wb"):
def put(
self,
contents: Union["S3Folder", Dict],
overwrite: bool = False,
mode: str = "wb",
):
"""Put given contents in folder."""
self.mkdir()
if isinstance(contents, list):
Expand All @@ -131,7 +136,7 @@ def put(self, contents, overwrite=False, mode: str = "wb"):
contents.folder_path = key + "/" + contents.folder_path
return

if not isinstance(contents, dict):
if not isinstance(contents, Dict):
raise TypeError(
"`contents` argument must be a dict mapping filenames to file-like objects"
)
Expand Down
8 changes: 4 additions & 4 deletions runhouse/resources/functions/aws_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ def from_config(
def from_name(
cls,
name,
load_from_den=True,
dryrun=False,
_alt_options=None,
_resolve_children=True,
load_from_den: bool = True,
dryrun: bool = False,
_alt_options: Dict = None,
_resolve_children: bool = True,
):
config = rns_client.load_config(name=name, load_from_den=load_from_den)
if not config:
Expand Down
6 changes: 3 additions & 3 deletions runhouse/resources/functions/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ def __init__(
# ----------------- Constructor helper methods -----------------

@classmethod
def from_config(cls, config: dict, dryrun: bool = False, _resolve_children=True):
"""Create a Function object from a config dictionary."""
def from_config(
cls, config: dict, dryrun: bool = False, _resolve_children: bool = True
):
if isinstance(config["system"], dict):
config["system"] = Cluster.from_config(
config["system"], dryrun=dryrun, _resolve_children=_resolve_children
Expand All @@ -55,7 +56,6 @@ def from_config(cls, config: dict, dryrun: bool = False, _resolve_children=True)
return Function(**config, dryrun=dryrun)

def share(self, *args, visibility=None, **kwargs):
"""Share and grant access to the resource for the specified users."""
if visibility and not visibility == self.visibility:
self.visibility = visibility
super().remote.visibility = (
Expand Down
21 changes: 11 additions & 10 deletions runhouse/resources/hardware/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def __init__(
ssl_certfile: str = None,
domain: str = None,
den_auth: bool = False,
dryrun=False,
dryrun: bool = False,
**kwargs, # We have this here to ignore extra arguments when calling from from_config
):
"""
Expand Down Expand Up @@ -198,13 +198,14 @@ def default_env(self, env):
def from_name(
cls,
name,
load_from_den=True,
dryrun=False,
_alt_options=None,
_resolve_children=True,
load_from_den: bool = True,
dryrun: bool = False,
_alt_options: Dict = None,
_resolve_children: bool = True,
):
cluster = super().from_name(
name=name,
load_from_den=load_from_den,
dryrun=dryrun,
_alt_options=_alt_options,
_resolve_children=_resolve_children,
Expand Down Expand Up @@ -365,8 +366,8 @@ def endpoint(self, external: bool = False):
external (bool, optional): If ``True``, will only return the external url, and will return ``None``
otherwise (e.g. if a tunnel is required). If set to ``False``, will either return the external url
if it exists, or will set up the connection (based on connection_type) and return the internal url
(including the local connected port rather than the sever port). If cluster is not up, returns None.
(Default: ``False``)
(including the local connected port rather than the sever port). If cluster is not up, returns
`None``. (Default: ``False``)
"""
if not self.address or self.on_this_cluster():
return None
Expand Down Expand Up @@ -601,7 +602,7 @@ def install_packages(
env.to(self)

def get(self, key: str, default: Any = None, remote=False):
"""Get the result for a given key from the cluster's object store.`.
"""Get the result for a given key from the cluster's object store.
Args:
key (str): Key to get from the cluster's object store.
Expand Down Expand Up @@ -1114,8 +1115,8 @@ def stop_server(self, stop_ray: bool = True, env: Union[str, "Env"] = None):

@contextlib.contextmanager
def pause_autostop(self):
"""Context manager to temporarily pause autostop. Mainly for OnDemand clusters, for BYO cluster
there is no autostop."""
"""Context manager to temporarily pause autostop. Only for OnDemand clusters. There is no autostop
for static clusters."""
pass

def call(
Expand Down
20 changes: 10 additions & 10 deletions runhouse/resources/hardware/on_demand_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import time
import warnings
from pathlib import Path
from typing import Any, Dict
from typing import Any, Dict, List, Union

import requests

Expand Down Expand Up @@ -46,21 +46,21 @@ def __init__(
num_instances: int = None,
provider: str = None,
default_env: "Env" = None,
dryrun=False,
autostop_mins=None,
use_spot=False,
image_id=None,
memory=None,
disk_size=None,
open_ports=None,
server_host: str = None,
dryrun: bool = False,
autostop_mins: int = None,
use_spot: bool = False,
image_id: str = None,
memory: Union[int, str] = None,
disk_size: Union[int, str] = None,
open_ports: Union[int, str, List[int]] = None,
server_host: int = None,
server_port: int = None,
server_connection_type: str = None,
ssl_keyfile: str = None,
ssl_certfile: str = None,
domain: str = None,
den_auth: bool = False,
region=None,
region: str = None,
sky_kwargs: Dict = None,
**kwargs, # We have this here to ignore extra arguments when calling from from_config
):
Expand Down
5 changes: 4 additions & 1 deletion runhouse/resources/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ def __init__(
**kwargs,
):
"""
Runhouse Module object
Runhouse Module object.
.. note::
To create a Module, please use the factory method :func:`module`.
"""
super().__init__(name=name, dryrun=dryrun, **kwargs)
self._system = _get_cluster_from(
Expand Down
4 changes: 2 additions & 2 deletions runhouse/resources/packages/git_package.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from pathlib import Path
from typing import Union
from typing import Dict, Union

from runhouse.resources.envs.utils import run_setup_command

Expand Down Expand Up @@ -83,7 +83,7 @@ def _install(self, env: Union[str, "Env"] = None, cluster: "Cluster" = None):
super()._install(env, cluster=cluster)

@staticmethod
def from_config(config: dict, dryrun=False, _resolve_children=True):
def from_config(config: Dict, dryrun: bool = False, _resolve_children: bool = True):
return GitPackage(**config, dryrun=dryrun)


Expand Down
7 changes: 3 additions & 4 deletions runhouse/resources/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,9 @@ def share(
notify_users: bool = True,
headers: Optional[Dict] = None,
) -> Tuple[Dict[str, ResourceAccess], Dict[str, ResourceAccess]]:
"""Grant access to the resource for a list of users (or a single user). If a user has a Runhouse account they
will receive an email notifying them of their new access. If the user does not have a Runhouse account they will
also receive instructions on creating one, after which they will be able to have access to the Resource. If
``visibility`` is set to ``public``, users will not be notified.
"""Grant access to the resource for a list of users (or a single user). By default, the user will
receive an email notification of access (if they have a Runhouse account) or instructions on creating
an account to access the resource. If ``visibility`` is set to ``public``, users will not be notified.
.. note::
You can only grant access to other users if you have write access to the resource.
Expand Down
10 changes: 5 additions & 5 deletions runhouse/resources/secrets/secret.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def _write_shared_secret_to_local(config):
)

@staticmethod
def from_config(config: dict, dryrun: bool = False, _resolve_children=True):
def from_config(config: dict, dryrun: bool = False, _resolve_children: bool = True):
if "provider" in config:
from runhouse.resources.secrets.provider_secrets.providers import (
_get_provider_class,
Expand All @@ -115,10 +115,10 @@ def from_config(config: dict, dryrun: bool = False, _resolve_children=True):
def from_name(
cls,
name,
load_from_den=True,
dryrun=False,
_alt_options=None,
_resolve_children=True,
load_from_den: bool = True,
dryrun: bool = False,
_alt_options: Dict = None,
_resolve_children: bool = True,
):
try:
config = load_config(name, cls.USER_ENDPOINT)
Expand Down

0 comments on commit bbbd641

Please sign in to comment.