diff --git a/earthaccess/__init__.py b/earthaccess/__init__.py index 6db81f92..8d399945 100644 --- a/earthaccess/__init__.py +++ b/earthaccess/__init__.py @@ -61,8 +61,7 @@ def __getattr__(name): # type: ignore - """ - Module-level getattr to handle automatic authentication when accessing + """Module-level getattr to handle automatic authentication when accessing `earthaccess.__auth__` and `earthaccess.__store__`. Other unhandled attributes raise as `AttributeError` as expected. diff --git a/earthaccess/api.py b/earthaccess/api.py index 5e82fd60..8522dbbb 100644 --- a/earthaccess/api.py +++ b/earthaccess/api.py @@ -268,7 +268,7 @@ def collection_query() -> CollectionQuery: def granule_query() -> GranuleQuery: - """Returns a query builder instance for data granules + """Returns a query builder instance for data granules. Returns: a query builder instance for data granules. diff --git a/earthaccess/auth.py b/earthaccess/auth.py index 9c103325..d8450c44 100644 --- a/earthaccess/auth.py +++ b/earthaccess/auth.py @@ -25,8 +25,7 @@ class SessionWithHeaderRedirection(requests.Session): - """ - Requests removes auth headers if the redirect happens outside the + """Requests removes auth headers if the redirect happens outside the original req domain. """ diff --git a/earthaccess/formatters.py b/earthaccess/formatters.py index d022e9ee..0317ee79 100644 --- a/earthaccess/formatters.py +++ b/earthaccess/formatters.py @@ -7,7 +7,7 @@ def _load_static_files() -> List[str]: - """Load styles""" + """Load styles.""" return [ importlib_resources.files("earthaccess.css").joinpath(fname).read_text("utf8") for fname in STATIC_FILES diff --git a/earthaccess/results.py b/earthaccess/results.py index 6d91ca7e..3cbe8bae 100644 --- a/earthaccess/results.py +++ b/earthaccess/results.py @@ -94,9 +94,10 @@ def summary(self) -> Dict[str, Any]: return summary_dict def get_umm(self, umm_field: str) -> Union[str, Dict[str, Any]]: - """ + """Placeholder. + Parameters: - umm_field: Valid UMM item, i.e. `TemporalExtent` + umm_field: Valid UMM item, i.e. `TemporalExtent`. Returns: The value of a given field inside the UMM (Unified Metadata Model). @@ -106,17 +107,16 @@ def get_umm(self, umm_field: str) -> Union[str, Dict[str, Any]]: return "" def concept_id(self) -> str: - """ - Returns: - A collection's `concept_id`. - This id is the most relevant search field on granule queries. + """Placeholder. + + Returns: A collection's `concept_id`.This id is the most relevant search field on granule queries. """ return self["meta"]["concept-id"] def data_type(self) -> str: - """ - Returns: - The collection data type, i.e. HDF5, CSV etc., if available. + """Placeholder. + + Returns: The collection data type, i.e. HDF5, CSV etc., if available. """ if "ArchiveAndDistributionInformation" in self["umm"]: return str( @@ -127,27 +127,27 @@ def data_type(self) -> str: return "" def version(self) -> str: - """ - Returns: - The collection's version. + """Placeholder. + + Returns: The collection's version. """ if "Version" in self["umm"]: return self["umm"]["Version"] return "" def abstract(self) -> str: - """ - Returns: - The abstract of a collection + """Placeholder. + + Returns:The abstract of a collection. """ if "Abstract" in self["umm"]: return self["umm"]["Abstract"] return "" def landing_page(self) -> str: - """ - Returns: - The first landing page for the collection (can be many), if available. + """Placeholder. + + Returns: The first landing page for the collection (can be many), if available. """ links = self._filter_related_links("LANDING PAGE") if len(links) > 0: @@ -155,18 +155,17 @@ def landing_page(self) -> str: return "" def get_data(self) -> List[str]: - """ - Returns: - The GET DATA links (usually a landing page link, a DAAC portal, or an FTP location). + """Placeholder. + + Returns: The GET DATA links (usually a landing page link, a DAAC portal, or an FTP location). """ links = self._filter_related_links("GET DATA") return links def s3_bucket(self) -> Dict[str, Any]: - """ - Returns: - The S3 bucket information if the collection has it. - (**cloud hosted collections only**) + """Placeholder. + + Returns: The S3 bucket information if the collection has it.(**cloud hosted collections only**). """ if "DirectDistributionInformation" in self["umm"]: return self["umm"]["DirectDistributionInformation"] @@ -214,9 +213,9 @@ def __init__( self.render_dict = self._filter_fields_(fields) def __repr__(self) -> str: - """ - Returns: - A basic representation of a data granule. + """Placeholder. + + Returns: A basic representation of a data granule. """ data_links = [link for link in self.data_links()] rep_str = f""" @@ -229,9 +228,9 @@ def __repr__(self) -> str: return rep_str def _repr_html_(self) -> str: - """ - Returns: - A rich representation for a data granule if we are in a Jupyter notebook. + """Placeholder. + + Returns: A rich representation for a data granule if we are in a Jupyter notebook. """ granule_html_repr = _repr_granule_html(self) return granule_html_repr @@ -243,9 +242,9 @@ def get_s3_credentials_endpoint(self) -> Union[str, None]: return None def size(self) -> float: - """ - Returns: - The total size for the granule in MB. + """Placeholder. + + Returns: The total size for the granule in MB. """ try: data_granule = self["umm"]["DataGranule"] @@ -284,7 +283,9 @@ def _derive_s3_link(self, links: List[str]) -> List[str]: def data_links( self, access: Optional[str] = None, in_region: bool = False ) -> List[str]: - """Returns the data links from a granule. + """Placeholder. + + Returns the data links from a granule. Parameters: access: direct or external. @@ -325,9 +326,9 @@ def data_links( return https_links def dataviz_links(self) -> List[str]: - """ - Returns: - The data visualization links, usually the browse images. + """Placeholder. + + Returns: The data visualization links, usually the browse images. """ links = self._filter_related_links("GET RELATED VISUALIZATION") return links diff --git a/earthaccess/search.py b/earthaccess/search.py index 13f8c315..b7fe941b 100644 --- a/earthaccess/search.py +++ b/earthaccess/search.py @@ -33,8 +33,7 @@ def get_results( query: Union[CollectionQuery, GranuleQuery], limit: int = 2000, ) -> List[Any]: - """ - Get all results up to some limit, even if spanning multiple pages. + """Get all results up to some limit, even if spanning multiple pages. ???+ Tip The default page size is 2000, if the supplied value is greater then the @@ -50,7 +49,6 @@ def get_results( Raises: RuntimeError: The CMR query failed. """ - page_size = min(limit, 2000) url = query._build_url() @@ -79,8 +77,8 @@ def get_results( class DataCollections(CollectionQuery): - """ - ???+ Info + """ + ???+ Info "Placeholder" The DataCollection class queries against https://cmr.earthdata.nasa.gov/search/collections.umm_json, the response has to be in umm_json to use the result classes. @@ -156,7 +154,6 @@ def get(self, limit: int = 2000) -> List[DataCollection]: Raises: RuntimeError: The CMR query failed. """ - return [ DataCollection(collection, self._fields) for collection in get_results(self.session, self, limit) @@ -442,7 +439,6 @@ def temporal( object; or `date_from` and `date_to` are both datetime objects (or parsable as such) and `date_from` is after `date_to`. """ - return super().temporal(date_from, date_to, exclude_boundary) @@ -481,7 +477,6 @@ def hits(self) -> int: Raises: RuntimeError: The CMR query failed. """ - url = self._build_url() response = self.session.get(url, headers=self.headers, params={"page_size": 0}) @@ -842,7 +837,6 @@ def temporal( object; or `date_from` and `date_to` are both datetime objects (or parsable as such) and `date_from` is after `date_to`. """ - return super().temporal(date_from, date_to, exclude_boundary) @override @@ -969,7 +963,6 @@ def doi(self, doi: str) -> Self: Raises: RuntimeError: The CMR query to get the collection for the DOI fails. """ - # TODO consider deferring this query until the search is executed collection = DataCollections().doi(doi).get() diff --git a/pyproject.toml b/pyproject.toml index f1d38a74..eccbc446 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -125,7 +125,12 @@ line-length = 88 src = ["earthaccess", "stubs", "tests"] [tool.ruff.lint] -extend-select = ["I", "T20"] +extend-select = ["I", "T20", "D"] +ignore = ["D1", "D205", "D401", "D417"] + +[tool.ruff.lint.pydocstyle] +convention = "google" + [tool.ruff.lint.isort] combine-as-imports = true diff --git a/tests/integration/test_cloud_download.py b/tests/integration/test_cloud_download.py index a9b9432c..4e8f9519 100644 --- a/tests/integration/test_cloud_download.py +++ b/tests/integration/test_cloud_download.py @@ -72,9 +72,8 @@ def get_sample_granules(granules, sample_size, max_granule_size): - """ - returns a list with sample granules and their size in MB if - the total size is less than the max_granule_size + """Returns a list with sample granules and their size in MB if + the total size is less than the max_granule_size. """ files_to_download = [] total_size = 0 @@ -98,9 +97,7 @@ def get_sample_granules(granules, sample_size, max_granule_size): @pytest.mark.parametrize("daac", daac_list) def test_earthaccess_can_download_cloud_collection_granules(daac): - """ - Tests that we can download cloud collections using HTTPS links - """ + """Tests that we can download cloud collections using HTTPS links.""" daac_shortname = daac["short_name"] collections_count = daac["collections_count"] collections_sample_size = daac["collections_sample_size"] diff --git a/tests/integration/test_cloud_open.py b/tests/integration/test_cloud_open.py index 78050f22..b69eba15 100644 --- a/tests/integration/test_cloud_open.py +++ b/tests/integration/test_cloud_open.py @@ -71,9 +71,8 @@ def get_sample_granules(granules, sample_size, max_granule_size): - """ - returns a list with sample granules and their size in MB if - the total size is less than the max_granule_size + """Returns a list with sample granules and their size in MB if + the total size is less than the max_granule_size. """ files_to_download = [] total_size = 0 @@ -104,9 +103,7 @@ def supported_collection(data_links): @pytest.mark.parametrize("daac", daacs_list) def test_earthaccess_can_open_onprem_collection_granules(daac): - """ - Tests that we can download cloud collections using HTTPS links - """ + """Tests that we can download cloud collections using HTTPS links.""" daac_shortname = daac["short_name"] collections_count = daac["collections_count"] collections_sample_size = daac["collections_sample_size"] diff --git a/tests/integration/test_onprem_download.py b/tests/integration/test_onprem_download.py index d54404c8..242a3c26 100644 --- a/tests/integration/test_onprem_download.py +++ b/tests/integration/test_onprem_download.py @@ -64,9 +64,8 @@ def get_sample_granules(granules, sample_size, max_granule_size): - """ - returns a list with sample granules and their size in MB if - the total size is less than the max_granule_size + """Returns a list with sample granules and their size in MB if + the total size is less than the max_granule_size. """ files_to_download = [] total_size = 0 @@ -97,9 +96,7 @@ def supported_collection(data_links): @pytest.mark.parametrize("daac", daacs_list) def test_earthaccess_can_download_onprem_collection_granules(daac): - """ - Tests that we can download cloud collections using HTTPS links - """ + """Tests that we can download cloud collections using HTTPS links.""" daac_shortname = daac["short_name"] collections_count = daac["collections_count"] collections_sample_size = daac["collections_sample_size"] diff --git a/tests/integration/test_onprem_open.py b/tests/integration/test_onprem_open.py index 02a2c60a..2a455c44 100644 --- a/tests/integration/test_onprem_open.py +++ b/tests/integration/test_onprem_open.py @@ -63,9 +63,8 @@ def get_sample_granules(granules, sample_size, max_granule_size): - """ - returns a list with sample granules and their size in MB if - the total size is less than the max_granule_size + """Returns a list with sample granules and their size in MB if + the total size is less than the max_granule_size. """ files_to_download = [] total_size = 0 @@ -96,9 +95,7 @@ def supported_collection(data_links): @pytest.mark.parametrize("daac", daacs_list) def test_earthaccess_can_open_onprem_collection_granules(daac): - """ - Tests that we can download cloud collections using HTTPS links - """ + """Tests that we can download cloud collections using HTTPS links.""" daac_shortname = daac["short_name"] collections_count = daac["collections_count"] collections_sample_size = daac["collections_sample_size"] diff --git a/tests/unit/test_results.py b/tests/unit/test_results.py index c669e8d7..b55fd32f 100644 --- a/tests/unit/test_results.py +++ b/tests/unit/test_results.py @@ -14,8 +14,7 @@ def unique_results(results): - """ - When we invoke a search request multiple times we want to ensure that we don't + """When we invoke a search request multiple times we want to ensure that we don't get the same results back. This is a one shot test as the results are preserved by VCR but still useful. """ @@ -120,10 +119,9 @@ def test_data_links(self): ) def test_get_more_than_2000(self): - """ - If we execute a get with a limit of more than 2000 + """If we execute a get with a limit of more than 2000 then we expect multiple invocations of a cmr granule search and - to not fetch back more results than we ask for + to not fetch back more results than we ask for. """ granules = earthaccess.search_data(short_name="MOD02QKM", count=3000) @@ -133,10 +131,9 @@ def test_get_more_than_2000(self): self.assertTrue(unique_results(granules)) def test_get(self): - """ - If we execute a get with no arguments then we expect + """If we execute a get with no arguments then we expect to get the maximum no. of granules from a single CMR call (2000) - in a single request + in a single request. """ granules = earthaccess.search_data(short_name="MOD02QKM", count=2000) @@ -146,10 +143,9 @@ def test_get(self): self.assertTrue(unique_results(granules)) def test_get_all_less_than_2k(self): - """ - If we execute a get_all then we expect multiple + """If we execute a get_all then we expect multiple invocations of a cmr granule search and - to not fetch back more results than we ask for + to not fetch back more results than we ask for. """ granules = earthaccess.search_data( short_name="TELLUS_GRAC_L3_JPL_RL06_LND_v04", count=2000 @@ -161,10 +157,9 @@ def test_get_all_less_than_2k(self): self.assertTrue(unique_results(granules)) def test_get_all_more_than_2k(self): - """ - If we execute a get_all then we expect multiple + """If we execute a get_all then we expect multiple invocations of a cmr granule search and - to not fetch back more results than we ask for + to not fetch back more results than we ask for. """ granules = earthaccess.search_data( short_name="CYGNSS_NOAA_L2_SWSP_25KM_V1.2", count=3000 @@ -182,10 +177,9 @@ def test_get_all_more_than_2k(self): self.assertTrue(unique_results(granules)) def test_collections_less_than_2k(self): - """ - If we execute a get_all then we expect multiple + """If we execute a get_all then we expect multiple invocations of a cmr granule search and - to not fetch back more results than we ask for + to not fetch back more results than we ask for. """ query = DataCollections().daac("PODAAC").cloud_hosted(True) collections = query.get(20) @@ -197,10 +191,9 @@ def test_collections_less_than_2k(self): self.assert_is_using_search_after(self.cassette) def test_collections_more_than_2k(self): - """ - If we execute a get_all then we expect multiple + """If we execute a get_all then we expect multiple invocations of a cmr granule search and - to not fetch back more results than we ask for + to not fetch back more results than we ask for. """ query = DataCollections() collections = query.get(3000)