Skip to content

Commit

Permalink
Docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
teutoburg committed Dec 16, 2023
1 parent 8bcb35b commit e65e922
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions scopesim/server/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class PkgNotFoundError(Exception):


def get_base_url():
"""Get instrument package server URL from rc.__config__."""
return rc.__config__["!SIM.file.server_base_url"]


Expand Down Expand Up @@ -179,6 +180,7 @@ def get_all_package_versions(client=None) -> Dict[str, List[str]]:


def get_package_folders(client) -> Dict[str, str]:
"""Map package names to server locations."""
folders_dict = {pkg: path.strip("/")
for path, pkgs in dict(crawl_server_dirs(client)).items()
for pkg in pkgs}
Expand Down
8 changes: 8 additions & 0 deletions scopesim/server/download_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def _make_tqdm_kwargs(desc: str = ""):


def create_client(base_url, cached: bool = False, cache_name: str = ""):
"""Create httpx Client instance, should support cache at some point."""
if cached:
raise NotImplementedError("Caching not yet implemented with httpx.")

Check warning on line 41 in scopesim/server/download_utils.py

View check run for this annotation

Codecov / codecov/patch

scopesim/server/download_utils.py#L41

Added line #L41 was not covered by tests
transport = httpx.HTTPTransport(retries=5)
Expand All @@ -47,6 +48,7 @@ def handle_download(client, pkg_url: str,
save_path: Path, pkg_name: str,
padlen: int, chunk_size: int = 128,
disable_bar=False) -> None:
"""Perform a streamed download and write the content to disk."""
tqdm_kwargs = _make_tqdm_kwargs(f"Downloading {pkg_name:<{padlen}}")

stream = send_get(client, pkg_url, stream=True)
Expand Down Expand Up @@ -75,6 +77,7 @@ def handle_download(client, pkg_url: str,

def handle_unzipping(save_path: Path, save_dir: Path,
pkg_name: str, padlen: int) -> None:
"""Unpack a zipped folder, usually called right after downloading."""
with ZipFile(save_path, "r") as zip_ref:
namelist = zip_ref.namelist()
tqdm_kwargs = _make_tqdm_kwargs(f"Extracting {pkg_name:<{padlen}}")
Expand All @@ -83,6 +86,10 @@ def handle_unzipping(save_path: Path, save_dir: Path,


def send_get(client, sub_url, stream: bool = False):
"""Send a GET request (streamed or not) using an existing client.
The point of this function is mostly elaborate exception handling.
"""
try:
if stream:
response = client.stream("GET", sub_url)
Expand All @@ -106,6 +113,7 @@ def send_get(client, sub_url, stream: bool = False):

def get_server_folder_contents(client, dir_name: str,
unique_str: str = ".zip$") -> Iterator[str]:
"""Find all zip files in a given server folder."""
dir_name = dir_name + "/" if not dir_name.endswith("/") else dir_name
response = send_get(client, dir_name)

Expand Down
4 changes: 2 additions & 2 deletions scopesim/server/github_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

def create_github_url(url: str) -> None:
"""
From the given url, produce a URL that is compatible with Github's REST API.
From the given url, produce a URL compatible with Github's REST API.
Can handle blob or tree paths.
"""
Expand All @@ -46,7 +46,7 @@ def create_github_url(url: str) -> None:
def download_github_folder(repo_url: str,
output_dir: Union[Path, str] = "./") -> None:
"""
Downloads the files and directories in repo_url.
Download the files and directories in repo_url.
Re-written based on the on the download function
`here <https://github.com/sdushantha/gitdir/blob/f47ce9d85ee29f8612ce5ae804560a12b803ddf3/gitdir/gitdir.py#L55>`_
Expand Down

0 comments on commit e65e922

Please sign in to comment.