Skip to content

Commit 5f6d6b4

Browse files
committed
NPI-4443 update some type hints
1 parent b04f527 commit 5f6d6b4

1 file changed

Lines changed: 20 additions & 21 deletions

File tree

gnssanalysis/gn_download.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,11 @@ def __call__(self, bytes_transferred):
9494
_sys.stdout.flush()
9595

9696

97-
98-
def get_earthdata_credentials(username: str = None, password: str = None) -> Tuple[str, str]:
97+
def get_earthdata_credentials(username: Optional[str] = None, password: Optional[str] = None) -> Tuple[str, str]:
9998
"""
10099
Get NASA Earthdata credentials from .netrc file or direct parameters.
101-
:param str username: Directly provided username (highest priority)
102-
:param str password: Directly provided password (highest priority)
100+
:param Optional[str] username: Directly provided username (highest priority)
101+
:param Optional[str] password: Directly provided password (highest priority)
103102
:return Tuple[str, str]: Username and password tuple
104103
:raises ValueError: If no credentials can be obtained
105104
"""
@@ -774,17 +773,17 @@ def ftp_tls(url: str, **kwargs) -> Generator[Any, Any, Any]:
774773

775774
def download_file_from_cddis(
776775
filename: str,
777-
ftp_folder: Optional[str] = None, # deprecated
778-
url_folder: Optional[str] = None, # preferred
776+
ftp_folder: Optional[str] = None, # deprecated
777+
url_folder: Optional[str] = None, # preferred
779778
output_folder: _Path = _Path("."),
780779
max_retries: int = 3,
781780
decompress: bool = True,
782781
if_file_present: str = "prompt_user",
783-
username: str = None,
784-
password: str = None,
782+
username: Optional[str] = None,
783+
password: Optional[str] = None,
785784
note_filetype: Optional[str] = None,
786785
) -> Union[_Path, None]:
787-
""" Download a single file from the CDDIS HTTPS archive using NASA Earthdata authentication
786+
"""Download a single file from the CDDIS HTTPS archive using NASA Earthdata authentication
788787
789788
:param str filename: Name of the file to download
790789
:param str ftp_folder: (Deprecated) Legacy folder path on the CDDIS FTP server. Use url_folder instead
@@ -794,8 +793,8 @@ def download_file_from_cddis(
794793
:param bool decompress: If true, decompresses files on download, defaults to True
795794
:param str if_file_present: What to do if file already present: "replace", "dont_replace", defaults to "prompt_user"
796795
:param str note_filetype: How to label the file for STDOUT messages, defaults to None
797-
:param str username: NASA Earthdata username (optional, will try .netrc if not provided).
798-
:param str password: NASA Earthdata password (optional, will try .netrc if not provided).
796+
:param Optional[str] username: NASA Earthdata username (optional, will try .netrc if not provided).
797+
:param Optional[str] password: NASA Earthdata password (optional, will try .netrc if not provided).
799798
:raises ValueError: If no credentials can be obtained.
800799
:raises requests.RequestException: If the file cannot be downloaded after retries.
801800
:return _Path or None: The pathlib.Path of the downloaded file (or decompressed output of it).
@@ -872,11 +871,11 @@ def download_file_from_cddis(
872871

873872
def download_multiple_files_from_cddis(
874873
files: List[str],
875-
ftp_folder: Optional[str] = None, # deprecated
876-
url_folder: Optional[str] = None, # preferred
874+
ftp_folder: Optional[str] = None, # deprecated
875+
url_folder: Optional[str] = None, # preferred
877876
output_folder: _Path = _Path("."),
878-
username: str = None,
879-
password: str = None,
877+
username: Optional[str] = None,
878+
password: Optional[str] = None,
880879
) -> None:
881880
"""
882881
Download multiple files from the CDDIS HTTPS archive concurrently, using a thread pool.
@@ -885,8 +884,8 @@ def download_multiple_files_from_cddis(
885884
:param str ftp_folder: (Deprecated) Legacy folder path on the CDDIS FTP server. Use url_folder instead.
886885
:param str url_folder: Folder path (relative to CDDIS HTTPS archive root).
887886
:param _Path output_folder: Local folder to store the output files.
888-
:param str username: NASA Earthdata username (optional, will try .netrc if not provided).
889-
:param str password: NASA Earthdata password (optional, will try .netrc if not provided).
887+
:param Optional[str] username: NASA Earthdata username (optional, will try .netrc if not provided).
888+
:param Optional[str] password: NASA Earthdata password (optional, will try .netrc if not provided).
890889
:raises ValueError: If both ftp_folder and url_folder are provided.
891890
:return None: Runs downloads in parallel, does not return values. Each file is handled independently.
892891
"""
@@ -939,8 +938,8 @@ def download_product_from_cddis(
939938
project_type: str = "OPS",
940939
timespan: _datetime.timedelta = _datetime.timedelta(days=2),
941940
if_file_present: str = "prompt_user",
942-
username: str = None,
943-
password: str = None,
941+
username: Optional[str] = None,
942+
password: Optional[str] = None,
944943
) -> List[_Path]:
945944
"""Download the file/s from CDDIS based on start and end epoch, to the download directory (download_dir)
946945
@@ -957,8 +956,8 @@ def download_product_from_cddis(
957956
:param str project_type: Project type of file to download (e.g. ), defaults to "OPS"
958957
:param _datetime.timedelta timespan: Timespan of the file/s to download, defaults to _datetime.timedelta(days=2)
959958
:param str if_file_present: What to do if file already present: "replace", "dont_replace", defaults to "prompt_user"
960-
:param str username: NASA Earthdata username (optional, will try .netrc if not provided).
961-
:param str password: NASA Earthdata password (optional, will try .netrc if not provided).
959+
:param Optional[str] username: NASA Earthdata username (optional, will try .netrc if not provided).
960+
:param Optional[str] password: NASA Earthdata password (optional, will try .netrc if not provided).
962961
:raises FileNotFoundError: Raise error if the specified file cannot be found on CDDIS
963962
:raises Exception: If a file fails to download after all retries.
964963
:return List[_Path]: List of pathlib.Path objects to downloaded (or decompressed) files.

0 commit comments

Comments
 (0)