Skip to content

Commit

Permalink
More ruff & pre-commit rules (#546)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Wei Ji <[email protected]>
  • Loading branch information
3 people authored Aug 27, 2024
1 parent 2790edd commit ee43461
Show file tree
Hide file tree
Showing 32 changed files with 92 additions and 57 deletions.
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@ repos:
- id: check-yaml
- id: check-added-large-files
args: ["--maxkb=5000"]
- id: check-case-conflict
- id: check-merge-conflict
- id: check-symlinks
- id: debug-statements
- id: name-tests-test
args: ["--pytest-test-first"]
- id: end-of-file-fixer
- id: mixed-line-ending
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
- id: requirements-txt-fixer

- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
Expand Down
4 changes: 1 addition & 3 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import icepyx


# -- Project information -----------------------------------------------------

project = "icepyx"
Expand Down Expand Up @@ -120,10 +119,9 @@ def setup(app):

# this should possibly be moved to the sphinxext directory as a standalone .py file
# -- custom style for pybtex output -------------------------------------------
from pybtex.style.formatting.unsrt import Style as UnsrtStyle

# from pybtex.style.labels.alpha import LabelStyle as AlphaLabelStyle
from pybtex.plugin import register_plugin
from pybtex.style.formatting.unsrt import Style as UnsrtStyle

# I seem to be unable to figure out how to control what is used for the label. It would
# make sense if it were fed into this function, which then just formatted it, but I can't figure out from where
Expand Down
3 changes: 2 additions & 1 deletion doc/source/tracking/pypistats/get_pypi_stats.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import pypistats

import pandas as pd
import pypistats

cwd = os.getcwd()

Expand Down
3 changes: 2 additions & 1 deletion doc/source/tracking/traffic/traffic_data_mgmt.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import matplotlib.pyplot as plt
import os

import matplotlib.pyplot as plt
import pandas as pd

cwd = os.getcwd()
Expand Down
Empty file modified doc/sphinxext/announce.py
100644 → 100755
Empty file.
8 changes: 4 additions & 4 deletions icepyx/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from icepyx.core.query import Query, GenQuery
from _icepyx_version import version as __version__

from icepyx.core.query import GenQuery, Query
from icepyx.core.read import Read
from icepyx.quest.quest import Quest
from icepyx.core.variables import Variables

from _icepyx_version import version as __version__
from icepyx.quest.quest import Quest
3 changes: 2 additions & 1 deletion icepyx/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import icepyx
import pytest

import icepyx


@pytest.fixture(autouse=True)
def add_ipx(doctest_namespace):
Expand Down
1 change: 0 additions & 1 deletion icepyx/core/APIformatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import datetime as dt


# ----------------------------------------------------------------------
# parameter-specific formatting for display
# or input to a set of API parameters (CMR or NSIDC)
Expand Down
3 changes: 1 addition & 2 deletions icepyx/core/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import datetime

import earthaccess

from icepyx.core.exceptions import DeprecationError


Expand All @@ -10,8 +11,6 @@ class AuthenticationError(Exception):
Raised when an error is encountered while authenticating Earthdata credentials
"""

pass


class EarthdataAuthMixin:
"""
Expand Down
4 changes: 0 additions & 4 deletions icepyx/core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@ class DeprecationError(Exception):
Class raised for use of functionality that is no longer supported by icepyx.
"""

pass


class QueryError(Exception):
"""
Base class for Query object exceptions
"""

pass


class NsidcQueryError(QueryError):
"""
Expand Down
9 changes: 5 additions & 4 deletions icepyx/core/granules.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import datetime
import requests
import time
import io
import re
import json
import numpy as np
import os
import pprint
import re
import time
from xml.etree import ElementTree as ET
import zipfile

import numpy as np
import requests

import icepyx.core.APIformatting as apifmt
from icepyx.core.auth import EarthdataAuthMixin
import icepyx.core.exceptions
Expand Down
7 changes: 3 additions & 4 deletions icepyx/core/is2ref.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import h5py
import json
import numpy as np
import requests
import warnings
from xml.etree import ElementTree as ET

import earthaccess

import h5py
import numpy as np
import requests

# ICESat-2 specific reference functions

Expand Down
5 changes: 3 additions & 2 deletions icepyx/core/query.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pprint

import geopandas as gpd
import matplotlib.pyplot as plt
import pprint

import icepyx.core.APIformatting as apifmt
from icepyx.core.auth import EarthdataAuthMixin
Expand Down Expand Up @@ -1131,8 +1132,8 @@ def visualize_spatial_extent(
gdf = self._spatial.extent_as_gdf

try:
from shapely.geometry import Polygon # noqa: F401
import geoviews as gv
from shapely.geometry import Polygon # noqa: F401

gv.extension("bokeh")

Expand Down
4 changes: 2 additions & 2 deletions icepyx/core/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,15 +432,15 @@ def _add_vars_to_ds(is2ds, ds, grp_path, wanted_groups_tiered, wanted_dict):
]

# handle delta_times with 1 or more dimensions
idx_range = range(0, len(ds.delta_time.data))
idx_range = range(len(ds.delta_time.data))
try:
photon_ids = (
idx_range
+ np.full_like(idx_range, np.max(is2ds.photon_idx), dtype="int64")
+ 1
)
except AttributeError:
photon_ids = range(0, len(ds.delta_time.data))
photon_ids = range(len(ds.delta_time.data))

hold_delta_times = ds.delta_time.data
ds = (
Expand Down
8 changes: 4 additions & 4 deletions icepyx/core/spatial.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import geopandas as gpd
import numpy as np
import os
from shapely.geometry import box, Polygon
from shapely.geometry.polygon import orient
import warnings

import geopandas as gpd
import numpy as np
from shapely.geometry import Polygon, box
from shapely.geometry.polygon import orient

# DevGoal: need to update the spatial_extent docstring to describe coordinate order for input

Expand Down
1 change: 0 additions & 1 deletion icepyx/core/temporal.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import datetime as dt
import warnings


"""
Helper functions for validation of dates
"""
Expand Down
1 change: 1 addition & 0 deletions icepyx/core/validate_inputs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime as dt
import warnings

import numpy as np


Expand Down
5 changes: 3 additions & 2 deletions icepyx/core/variables.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import numpy as np
import os

import numpy as np

from icepyx.core.auth import EarthdataAuthMixin
import icepyx.core.is2ref as is2ref
from icepyx.core.exceptions import DeprecationError
import icepyx.core.is2ref as is2ref
import icepyx.core.validate_inputs as val

# DEVGOAL: use h5py to simplify some of these tasks, if possible!
Expand Down
4 changes: 2 additions & 2 deletions icepyx/core/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
import dask.dataframe as dd
import datashader as ds
import holoviews as hv
from holoviews.operation.datashader import rasterize
import numpy as np
import pandas as pd
import requests
from holoviews.operation.datashader import rasterize
from tqdm import tqdm

import icepyx as ipx
import icepyx.core.is2ref as is2ref
import icepyx.core.granules as granules
import icepyx.core.is2ref as is2ref

hv.extension("bokeh")

Expand Down
1 change: 0 additions & 1 deletion icepyx/quest/quest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from icepyx.core.query import GenQuery, Query

from icepyx.quest.dataset_scripts.argo import Argo


Expand Down
3 changes: 2 additions & 1 deletion icepyx/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os
import pytest
from unittest import mock

import pytest


# PURPOSE: mock environmental variables
@pytest.fixture(scope="session", autouse=True)
Expand Down
1 change: 0 additions & 1 deletion icepyx/tests/test_APIformatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import icepyx.core.APIformatting as apifmt


# DevNote: is this a situation where you'd ideally build a test class,
# since you're just repeating the test function with different inputs?
# Especially for the _fmt_spaital, where there's >2 tests?
Expand Down
4 changes: 2 additions & 2 deletions icepyx/tests/test_Earthdata.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env python
"""
test icepyx.core.query.Query.earthdata_login function
"""

import netrc
import os
import pytest
import shutil

import pytest


# PURPOSE: test different authentication methods
@pytest.fixture(scope="module", autouse=True)
Expand Down
3 changes: 1 addition & 2 deletions icepyx/tests/test_auth.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import earthaccess
import pytest
import requests

import earthaccess

from icepyx.core.auth import EarthdataAuthMixin


Expand Down
2 changes: 1 addition & 1 deletion icepyx/tests/test_behind_NSIDC_API_login.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import json
import os

import pytest

import icepyx as ipx
import icepyx.core.is2ref as is2ref


# Misc notes and needed tests
# test avail data and subsetting success for each input type
# (kml, shp, list of coords, bbox)
Expand Down
5 changes: 3 additions & 2 deletions icepyx/tests/test_granules.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import pytest
import re

import pytest
import responses

import icepyx as ipx
from icepyx.core import granules as granules
from icepyx.core.granules import Granules as Granules
from icepyx.core.exceptions import NsidcQueryError
from icepyx.core.granules import Granules as Granules

# @pytest.fixture
# def reg_a():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import pytest

import icepyx as ipx

# Skip the whole module. See:
# https://docs.pytest.org/en/stable/reference/reference.html#globalvar-pytestmark
pytestmark = pytest.mark.skip("Legacy tests -- not sure if they ever passed!")


def test_CMRparams():
reg_a = ipx.Query("ATL06", [-64, 66, -55, 72], ["2019-02-22", "2019-02-28"])
Expand Down
2 changes: 1 addition & 1 deletion icepyx/tests/test_quest_argo.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import re

import pytest
import re

from icepyx.quest.quest import Quest

Expand Down
9 changes: 5 additions & 4 deletions icepyx/tests/test_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ def test_parse_source_no_files():
( # check list input
[
"./icepyx/core/is2ref.py",
"./icepyx/tests/is2class_query.py",
"./icepyx/tests/test_is2class_query.py",
],
sorted(
[
"./icepyx/core/is2ref.py",
"./icepyx/tests/is2class_query.py",
"./icepyx/tests/test_is2class_query.py",
]
),
),
Expand All @@ -45,11 +45,12 @@ def test_parse_source_no_files():
],
),
( # check filename string with glob pattern input
"./icepyx/**/is2*.py",
"./icepyx/**/*is2*.py",
sorted(
[
"./icepyx/core/is2ref.py",
"./icepyx/tests/is2class_query.py",
"./icepyx/tests/test_is2class_query.py",
"./icepyx/tests/test_is2ref.py",
]
),
),
Expand Down
6 changes: 3 additions & 3 deletions icepyx/tests/test_spatial.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from pathlib import Path
import re

import geopandas as gpd
import numpy as np
from pathlib import Path
import pytest
import re
from shapely.geometry import Polygon

import icepyx.core.spatial as spat


# ######### "Bounding Box" input tests ################################################################################
# (Note that these ALSO test the @property functions for the class for bounding boxes)

Expand Down
Loading

0 comments on commit ee43461

Please sign in to comment.