Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More ruff & pre-commit rules #546

Merged
merged 25 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a14ab37
Add YAML checker
mfisher87 Aug 8, 2024
65e7ee4
Fix E711, E712, E714 lint errors with Ruff autofixer
mfisher87 Aug 8, 2024
8b3f79f
Fix F401 and F841 lint errors
mfisher87 Aug 8, 2024
2ca3021
Switch to ruff for linting and formatting
mfisher87 Aug 8, 2024
5688faa
Apply formatting
mfisher87 Aug 8, 2024
749cc55
Migrate GitHub Action to Ruff
mfisher87 Aug 8, 2024
84f2b1f
Remove vestigial flake8 config
mfisher87 Aug 8, 2024
bf61460
Enable a suite of additional Ruff rules
mfisher87 Aug 8, 2024
3d4959b
Fixes for new ruff rules
mfisher87 Aug 8, 2024
2bd77fd
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 8, 2024
b479d90
Make sphinx announce script executable
mfisher87 Aug 8, 2024
3e9c1d2
Add more pre-commit checks
mfisher87 Aug 8, 2024
8596ffc
Rename test file to follow convention
mfisher87 Aug 8, 2024
ae0644d
Apply formatter
mfisher87 Aug 8, 2024
b86a68a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 8, 2024
a93662d
Merge branch 'development' into more-ruff-rules
weiji14 Aug 13, 2024
fa768ed
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 13, 2024
5011535
More explicitly declare ruff rules
mfisher87 Aug 13, 2024
facfd46
Sort ruff linting rules alphabetically
mfisher87 Aug 13, 2024
3956ca7
Adjust tests to account for renaming legacy test module
mfisher87 Aug 14, 2024
a4cf9df
Clarify comment about high value rulesets
mfisher87 Aug 14, 2024
3d631bb
Merge branch 'development' into more-ruff-rules
mfisher87 Aug 27, 2024
0b7447f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 27, 2024
088139b
Switch to sorting alphabetically within import sections
mfisher87 Aug 27, 2024
3c22771
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
weiji14 marked this conversation as resolved.
Show resolved Hide resolved
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
- id: requirements-txt-fixer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't be needed if #552 goes ahead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯


- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.7
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.
2 changes: 1 addition & 1 deletion doc/sphinxext/contributors.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
branch as the end of the revision range.
"""

import git
from announce import build_components
from docutils import nodes
from docutils.parsers.rst import Directive
import git


class ContributorsDirective(Directive):
Expand Down
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

JessicaS11 marked this conversation as resolved.
Show resolved Hide resolved

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

import numpy as np
import requests

import icepyx.core.APIformatting as apifmt
from icepyx.core.auth import EarthdataAuthMixin
import icepyx.core.exceptions
from icepyx.core.auth import EarthdataAuthMixin
mfisher87 marked this conversation as resolved.
Show resolved Hide resolved


def info(grans):
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
11 changes: 6 additions & 5 deletions icepyx/core/query.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
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
from icepyx.core.exceptions import DeprecationError
import icepyx.core.granules as granules
from icepyx.core.granules import Granules
import icepyx.core.is2ref as is2ref
import icepyx.core.spatial as spat
import icepyx.core.temporal as tp
import icepyx.core.validate_inputs as val
from icepyx.core.auth import EarthdataAuthMixin
from icepyx.core.exceptions import DeprecationError
from icepyx.core.granules import Granules
from icepyx.core.variables import Variables as Variables
from icepyx.core.visualization import Visualize

Expand Down Expand Up @@ -1133,8 +1134,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
6 changes: 3 additions & 3 deletions icepyx/core/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import numpy as np
import xarray as xr

import icepyx.core.is2ref as is2ref
from icepyx.core.auth import EarthdataAuthMixin
from icepyx.core.exceptions import DeprecationError
import icepyx.core.is2ref as is2ref
from icepyx.core.variables import Variables as Variables
from icepyx.core.variables import list_of_dict_vals

Expand Down 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
7 changes: 4 additions & 3 deletions icepyx/core/variables.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import numpy as np
import os

from icepyx.core.auth import EarthdataAuthMixin
import numpy as np

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

# DEVGOAL: use h5py to simplify some of these tasks, if possible!

Expand Down
2 changes: 1 addition & 1 deletion icepyx/core/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
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
JessicaS11 marked this conversation as resolved.
Show resolved Hide resolved
File renamed without changes.
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
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 @@
import re
from pathlib import Path

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
Loading