scopesim.server.database module

Functions to download instrument packages and example data.

exception scopesim.server.database.PkgNotFoundError[source]

Bases: Exception

Unable to find given package or given release of that package.

scopesim.server.database.crawl_server_dirs(client=None) Iterator[tuple[str, set[str]]][source]

Search all folders on server for .zip files.

scopesim.server.database.download_package(pkg_path, save_dir=None, url=None, from_cache=None)[source]

DEPRECATED – only kept for backwards compatibility

Downloads a package to the local disk

Parameters:
pkg_pathstr, list

A .zip package path as given by list_packages()

save_dirstr

The place on the local disk where the .zip package is to be saved. If left as None, defaults to the value in scopesim.rc.__config__[“!SIM.file.local_packages_path”]

urlstr

The URL of the IRDB HTTP server. If left as None, defaults to the value in scopesim.rc.__config__[“!SIM.file.server_base_url”]

from_cachebool

Use the cached versions of the packages. If None, defaults to the RC value: !SIM.file.use_cached_downloads

Returns:
save_pathstr

The absolute path to the saved .zip package

scopesim.server.database.download_packages(pkg_names: Union[Iterable[str], str], release: str = 'stable', save_dir: Optional[str] = None) list[pathlib.Path][source]

Download one or more packages to the local disk.

  1. Download stable, dev

  2. Download specific version

  3. Download from github via url

Parameters:
pkg_namesstr, list

A list of package names, see list_packages()

releasestr, optional

By default, the most recent stable version of a package is downloaded. Other options are: - “stable” : the most recent stable version - “latest” : the latest development version to be published - a specific package filename as given by list_packages (see examples) - a github url for the specific branch and package (see examples)

save_dirstr, optional

The place on the local disk where the .zip package is to be saved. If left as None, defaults to the value in scopesim.rc.__config__[“!SIM.file.local_packages_path”]

from_cachebool, optional

Use the cached versions of the packages. If None, defaults to the RC value: !SIM.file.use_cached_downloads

Returns:
save_pathstr

The absolute path to the saved .zip package

Examples

::

from scopesim import download_packages, list_packages

# Stable release of a list of packages download_packages([“test_package”, “test_package”])

# Development release of a single package download_packages(“test_package”, release=”latest”)

# Specific version of the package list_packages(“test_package”) download_packages(“test_package”, release=”2022-04-09.dev”)

# Specific package from a Gtihub commit hash or branch/tag name (use “@” or “:”) download_packages(“ELT”, release=”github:728761fc76adb548696205139e4e9a4260401dfc”) download_packages(“ELT”, release=”github@728761fc76adb548696205139e4e9a4260401dfc”) download_packages(“ELT”, release=”github@dev_master”)

scopesim.server.database.get_all_latest(version_groups: Mapping[str, Iterable[str]]) Iterator[tuple[str, str]][source]

Yield the most recent stable (not “dev”) version of each package.

Parameters:
version_groupsMapping[str, Iterable[str]]

DESCRIPTION.

Yields:
Iterator[tuple[str, str]]

Iterator of package name - latest version pairs.

scopesim.server.database.get_all_package_versions(client=None) dict[str, list[str]][source]

Gather all versions for all packages present in any folder on server.

scopesim.server.database.get_all_packages_on_server() Iterator[tuple[str, set]][source]

Retrieve all unique package names present on server in known folders.

Currently hardcoded to look in folders “locations”, “telescopes” and “instruments”. Any packages not in these folders are not returned.

This generator function yields key-value pairs, containing the folder name as the key and the set of unique package names in value. Recommended useage is to turn the generator into a dictionary, i.e.:

::

package_dict = dict(get_all_packages_on_server())

Yields:
Iterator[tuple[str, set]]

Key-value pairs of folder and corresponding package names.

scopesim.server.database.get_all_stable(version_groups: Mapping[str, Iterable[str]]) Iterator[tuple[str, str]][source]

Yield the most recent version (stable or dev) of each package.

Parameters:
version_groupsMapping[str, Iterable[str]]

DESCRIPTION.

Yields:
Iterator[tuple[str, str]]

Iterator of package name - latest stable version pairs.

scopesim.server.database.get_base_url()[source]

Get instrument package server URL from rc.__config__.

scopesim.server.database.get_latest(versions: Iterable[str]) str[source]

Return the most recent version (stable or dev).

scopesim.server.database.get_package_folders(client) dict[str, str][source]

Map package names to server locations.

scopesim.server.database.get_server_folder_package_names(client, dir_name: str) set[str][source]

Retrieve all unique package names present on server in dir_name folder.

Parameters:
clienthttpx.Client

Pre-existing httpx Client context manager.

dir_namestr

Name of the folder on the server.

Returns:
package_namesset of str

Set of unique package names in dir_name folder.

Raises:
ValueError

Raised if no valid packages are found in the given folder.

scopesim.server.database.get_server_package_list()[source]
scopesim.server.database.get_stable(versions: Iterable[str]) str[source]

Return the most recent stable (not “dev”) version.

scopesim.server.database.group_package_versions(all_packages: Iterable[tuple[str, str]]) Iterator[tuple[str, list[str]]][source]

Group different versions of packages by package name.

scopesim.server.database.list_packages(pkg_name: Optional[str] = None) list[str][source]

List all packages, or all variants of a single package.

Parameters:
pkg_namestr, optional
  • None: lists all stable packages on the server

  • <PackageName>: lists all variants of <PackageName> on the server

Returns:
pkg_nameslist

Examples

::

from scopesim import list_packages

# list all stable packages on the server list_packages()

# list all variants of a specific package list_packages(“Armazones”)