Skip to content

Commit

Permalink
Merge pull request #2641 from mraspaud/add-ruff-D
Browse files Browse the repository at this point in the history
Add "A" and "D" checks to ruff config
  • Loading branch information
mraspaud committed Nov 28, 2023
2 parents 726cc3e + 33f354f commit ed220be
Show file tree
Hide file tree
Showing 43 changed files with 89 additions and 79 deletions.
2 changes: 1 addition & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def __getattr__(cls, name):

# General information about the project.
project = u"Satpy"
copyright = u"2009-{}, The PyTroll Team".format(datetime.utcnow().strftime("%Y"))
copyright = u"2009-{}, The PyTroll Team".format(datetime.utcnow().strftime("%Y")) # noqa: A001

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
4 changes: 4 additions & 0 deletions doc/source/doi_role.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@


def doi_role(typ, rawtext, text, lineno, inliner, options=None, content=None):
"""Create a doi role."""
if options is None:
options = {}
if content is None:
Expand All @@ -34,6 +35,7 @@ def doi_role(typ, rawtext, text, lineno, inliner, options=None, content=None):


def arxiv_role(typ, rawtext, text, lineno, inliner, options=None, content=None):
"""Create an arxive role."""
if options is None:
options = {}
if content is None:
Expand All @@ -48,12 +50,14 @@ def arxiv_role(typ, rawtext, text, lineno, inliner, options=None, content=None):


def setup_link_role(app):
"""Set up the role link."""
app.add_role("doi", doi_role, override=True)
app.add_role("DOI", doi_role, override=True)
app.add_role("arXiv", arxiv_role, override=True)
app.add_role("arxiv", arxiv_role, override=True)


def setup(app):
"""Set up the app."""
app.connect("builder-inited", setup_link_role)
return {"version": "0.1", "parallel_read_safe": True}
2 changes: 1 addition & 1 deletion doc/source/reader_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def rst_table_row(columns=None):
return row


def rst_table_header(name=None, header=None, header_rows=1, widths="auto"):
def rst_table_header(name=None, header=None, header_rows=1, widths="auto"): # noqa: D417
"""Create header for rst table.
Args:
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ line_length = 120

[tool.ruff]
# See https://docs.astral.sh/ruff/rules/
# In the future, add "A", "B", "S", "N", "D"
select = ["E", "W", "F", "I", "PT", "TID", "C90", "Q", "T10", "T20"]
# In the future, add "B", "S", "N"
select = ["A", "D", "E", "W", "F", "I", "PT", "TID", "C90", "Q", "T10", "T20"]
line-length = 120

[tool.ruff.per-file-ignores]
Expand Down
14 changes: 7 additions & 7 deletions satpy/composites/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def __init__(self, name, prerequisites=None, optional_prerequisites=None, **kwar
self.attrs = kwargs

@property
def id(self):
def id(self): # noqa: A003
"""Return the DataID of the object."""
try:
return self.attrs["_satpy_id"]
Expand Down Expand Up @@ -343,7 +343,7 @@ class CategoricalDataCompositor(CompositeBase):
res = [[20, 40, 30], [50, 30, 10]]
"""

def __init__(self, name, lut=None, **kwargs):
def __init__(self, name, lut=None, **kwargs): # noqa: D417
"""Get look-up-table used to recategorize data.
Args:
Expand Down Expand Up @@ -381,7 +381,7 @@ class GenericCompositor(CompositeBase):

modes = {1: "L", 2: "LA", 3: "RGB", 4: "RGBA"}

def __init__(self, name, common_channel_mask=True, **kwargs):
def __init__(self, name, common_channel_mask=True, **kwargs): # noqa: D417
"""Collect custom configuration values.
Args:
Expand Down Expand Up @@ -679,7 +679,7 @@ class DayNightCompositor(GenericCompositor):
of the image (night or day). See the documentation below for more details.
"""

def __init__(self, name, lim_low=85., lim_high=88., day_night="day_night", include_alpha=True, **kwargs):
def __init__(self, name, lim_low=85., lim_high=88., day_night="day_night", include_alpha=True, **kwargs): # noqa: D417
"""Collect custom configuration values.
Args:
Expand Down Expand Up @@ -1013,7 +1013,7 @@ def __call__(self, projectables, *args, **kwargs):
class CloudCompositor(GenericCompositor):
"""Detect clouds based on thresholding and use it as a mask for compositing."""

def __init__(self, name, transition_min=258.15, transition_max=298.15,
def __init__(self, name, transition_min=258.15, transition_max=298.15, # noqa: D417
transition_gamma=3.0, **kwargs):
"""Collect custom configuration values.
Expand Down Expand Up @@ -1356,7 +1356,7 @@ class StaticImageCompositor(GenericCompositor, DataDownloadMixin):
"""

def __init__(self, name, filename=None, url=None, known_hash=None, area=None,
def __init__(self, name, filename=None, url=None, known_hash=None, area=None, # noqa: D417
**kwargs):
"""Collect custom configuration values.
Expand Down Expand Up @@ -1734,7 +1734,7 @@ def _get_flag_value(mask, val):
class LongitudeMaskingCompositor(SingleBandCompositor):
"""Masks areas outside defined longitudes."""

def __init__(self, name, lon_min=None, lon_max=None, **kwargs):
def __init__(self, name, lon_min=None, lon_max=None, **kwargs): # noqa: D417
"""Collect custom configuration values.
Args:
Expand Down
2 changes: 1 addition & 1 deletion satpy/composites/abi.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SimulatedGreen(GenericCompositor):
"""

def __init__(self, name, fractions=(0.465, 0.465, 0.07), **kwargs):
def __init__(self, name, fractions=(0.465, 0.465, 0.07), **kwargs): # noqa: D417
"""Initialize fractions for input channels.
Args:
Expand Down
2 changes: 1 addition & 1 deletion satpy/composites/agri.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SimulatedRed(GenericCompositor):
"""

def __init__(self, name, fractions=(1.0, 0.13, 0.87), **kwargs):
def __init__(self, name, fractions=(1.0, 0.13, 0.87), **kwargs): # noqa: D417
"""Initialize fractions for input channels.
Args:
Expand Down
2 changes: 1 addition & 1 deletion satpy/composites/glm.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class HighlightCompositor(GenericCompositor):
"""

def __init__(self, name, min_highlight=0.0, max_highlight=10.0,
def __init__(self, name, min_highlight=0.0, max_highlight=10.0, # noqa: D417
max_factor=(0.8, 0.8, -0.8, 0), **kwargs):
"""Initialize composite with highlight factor options.
Expand Down
4 changes: 2 additions & 2 deletions satpy/dataset/data_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def get_best_dataset_key(key, choices):
return [choice for choice, distance in zip(sorted_choices, distances) if distance == distances[0]]


def get_key(key, key_container, num_results=1, best=True, query=None,
def get_key(key, key_container, num_results=1, best=True, query=None, # noqa: D417
**kwargs):
"""Get the fully-specified key best matching the provided key.
Expand Down Expand Up @@ -139,7 +139,7 @@ def keys(self, names=False, wavelengths=False):
else:
return keys

def get_key(self, match_key, num_results=1, best=True, **dfilter):
def get_key(self, match_key, num_results=1, best=True, **dfilter): # noqa: D417
"""Get multiple fully-specified keys that match the provided query.
Args:
Expand Down
8 changes: 4 additions & 4 deletions satpy/dependency_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def _create_subtree_from_reader(self, dataset_key, query):
LOG.trace("Found reader provided dataset:\n\tRequested: {}\n\tFound: {}".format(dataset_key, node.name))
return node

def _find_reader_node(self, dataset_key, query):
def _find_reader_node(self, dataset_key, query): # noqa: D417
"""Attempt to find a `DataID` in the available readers.
Args:
Expand Down Expand Up @@ -517,7 +517,7 @@ def get_modifier(self, comp_id):

raise KeyError("Could not find modifier '{}'".format(modifier))

def _create_required_subtrees(self, parent, prereqs, query=None):
def _create_required_subtrees(self, parent, prereqs, query=None): # noqa: D417
"""Determine required prerequisite Nodes for a composite.
Args:
Expand All @@ -531,7 +531,7 @@ def _create_required_subtrees(self, parent, prereqs, query=None):
raise MissingDependencies(unknown_datasets)
return prereq_nodes

def _create_optional_subtrees(self, parent, prereqs, query=None):
def _create_optional_subtrees(self, parent, prereqs, query=None): # noqa: D417
"""Determine optional prerequisite Nodes for a composite.
Args:
Expand All @@ -549,7 +549,7 @@ def _create_optional_subtrees(self, parent, prereqs, query=None):

return prereq_nodes

def _create_prerequisite_subtrees(self, parent, prereqs, query=None):
def _create_prerequisite_subtrees(self, parent, prereqs, query=None): # noqa: D417
"""Determine prerequisite Nodes for a composite.
Args:
Expand Down
10 changes: 5 additions & 5 deletions satpy/enhancements/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def wrapper(data, **kwargs):
return on_dask_array(wrapper)


def piecewise_linear_stretch(
def piecewise_linear_stretch( # noqa: D417
img: XRImage,
xp: ArrayLike,
fp: ArrayLike,
Expand Down Expand Up @@ -229,7 +229,7 @@ def _cira_stretch(band_data):
return band_data


def reinhard_to_srgb(img, saturation=1.25, white=100, **kwargs):
def reinhard_to_srgb(img, saturation=1.25, white=100, **kwargs): # noqa: D417
"""Stretch method based on the Reinhard algorithm, using luminance.
Args:
Expand Down Expand Up @@ -293,7 +293,7 @@ def _lookup_table(band_data, luts=None, index=-1):
return lut[band_data]


def colorize(img, **kwargs):
def colorize(img, **kwargs): # noqa: D417
"""Colorize the given image.
Args:
Expand Down Expand Up @@ -365,7 +365,7 @@ def _merge_colormaps(kwargs, img=None):
return full_cmap


def create_colormap(palette, img=None):
def create_colormap(palette, img=None): # noqa: D417
"""Create colormap of the given numpy file, color vector, or colormap.
Args:
Expand Down Expand Up @@ -525,7 +525,7 @@ def _three_d_effect_delayed(band_data, kernel, mode):
return new_data.reshape((1, band_data.shape[0], band_data.shape[1]))


def btemp_threshold(img, min_in, max_in, threshold, threshold_out=None, **kwargs):
def btemp_threshold(img, min_in, max_in, threshold, threshold_out=None, **kwargs): # noqa: D417
"""Scale data linearly in two separate regions.
This enhancement scales the input data linearly by splitting the data
Expand Down
2 changes: 1 addition & 1 deletion satpy/modifiers/_crefl.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ReflectanceCorrector(ModifierBase, DataDownloadMixin):
Uses a python rewrite of the C CREFL code written for VIIRS and MODIS.
"""

def __init__(self, *args, dem_filename=None, dem_sds="averaged elevation",
def __init__(self, *args, dem_filename=None, dem_sds="averaged elevation", # noqa: D417
url=None, known_hash=None, **kwargs):
"""Initialize the compositor with values from the user or from the configuration file.
Expand Down
2 changes: 1 addition & 1 deletion satpy/modifiers/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class Median(ModifierBase):
"""Apply a median filter to the band."""

def __init__(self, median_filter_params, **kwargs):
def __init__(self, median_filter_params, **kwargs): # noqa: D417
"""Create the instance.
Args:
Expand Down
8 changes: 4 additions & 4 deletions satpy/modifiers/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
class SunZenithCorrectorBase(ModifierBase):
"""Base class for sun zenith correction modifiers."""

def __init__(self, max_sza=95.0, **kwargs):
def __init__(self, max_sza=95.0, **kwargs): # noqa: D417
"""Collect custom configuration values.
Args:
Expand Down Expand Up @@ -96,7 +96,7 @@ class SunZenithCorrector(SunZenithCorrectorBase):
"""

def __init__(self, correction_limit=88., **kwargs):
def __init__(self, correction_limit=88., **kwargs): # noqa: D417
"""Collect custom configuration values.
Args:
Expand Down Expand Up @@ -142,7 +142,7 @@ class EffectiveSolarPathLengthCorrector(SunZenithCorrectorBase):
"""

def __init__(self, correction_limit=88., **kwargs):
def __init__(self, correction_limit=88., **kwargs): # noqa: D417
"""Collect custom configuration values.
Args:
Expand Down Expand Up @@ -177,7 +177,7 @@ class SunZenithReducer(SunZenithCorrectorBase):
"""

def __init__(self, correction_limit=55., max_sza=90, strength=1.5, **kwargs):
def __init__(self, correction_limit=55., max_sza=90, strength=1.5, **kwargs): # noqa: D417
"""Collect custom configuration values.
Args:
Expand Down
2 changes: 1 addition & 1 deletion satpy/modifiers/parallax.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def __init__(self, base_area,
self.debug_mode = debug_mode
self.diagnostics = {}

def __call__(self, cth_dataset, **kwargs):
def __call__(self, cth_dataset, **kwargs): # noqa: D417
"""Apply parallax correction to dataset.
Args:
Expand Down
4 changes: 2 additions & 2 deletions satpy/modifiers/spectral.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class NIRReflectance(ModifierBase):
TERMINATOR_LIMIT = 85.0
MASKING_LIMIT = 88.0

def __init__(self, sunz_threshold=TERMINATOR_LIMIT,
def __init__(self, sunz_threshold=TERMINATOR_LIMIT, # noqa: D417
masking_limit=MASKING_LIMIT, **kwargs):
"""Collect custom configuration values.
Expand Down Expand Up @@ -139,7 +139,7 @@ def _init_reflectance_calculator(self, metadata):
class NIREmissivePartFromReflectance(NIRReflectance):
"""Get the emissive part of NIR bands."""

def __init__(self, sunz_threshold=None, **kwargs):
def __init__(self, sunz_threshold=None, **kwargs): # noqa: D417
"""Collect custom configuration values.
Args:
Expand Down
2 changes: 1 addition & 1 deletion satpy/multiscene/_multiscene.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def first_scene(self):
return self._scene_gen.first

@classmethod
def from_files(
def from_files( # noqa: D417
cls,
files_to_sort: Collection[str],
reader: str | Collection[str] | None = None,
Expand Down
8 changes: 4 additions & 4 deletions satpy/readers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def group_files(files_to_sort, reader=None, time_threshold=10,
return list(_filter_groups(groups, missing=missing))


def _assign_files_to_readers(files_to_sort, reader_names,
def _assign_files_to_readers(files_to_sort, reader_names, # noqa: D417
reader_kwargs):
"""Assign files to readers.
Expand Down Expand Up @@ -190,7 +190,7 @@ def _get_file_keys_for_reader_files(reader_files, group_keys=None):
return file_keys


def _get_sorted_file_groups(all_file_keys, time_threshold):
def _get_sorted_file_groups(all_file_keys, time_threshold): # noqa: D417
"""Get sorted file groups.
Get a list of dictionaries, where each list item consists of a dictionary
Expand Down Expand Up @@ -673,7 +673,7 @@ class FSFile(os.PathLike):
"""

def __init__(self, file, fs=None):
def __init__(self, file, fs=None): # noqa: D417
"""Initialise the FSFile instance.
Args:
Expand Down Expand Up @@ -705,7 +705,7 @@ def __repr__(self):
"""Representation of the object."""
return '<FSFile "' + str(self._file) + '">'

def open(self, *args, **kwargs):
def open(self, *args, **kwargs): # noqa: A003
"""Open the file.
This is read-only.
Expand Down
3 changes: 1 addition & 2 deletions satpy/readers/atms_sdr_hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@

# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
Reader for the ATMS SDR format.
"""Reader for the ATMS SDR format.
A reader for Advanced Technology Microwave Sounder (ATMS) SDR data as it
e.g. comes out of the CSPP package for processing Direct Readout data.
Expand Down

0 comments on commit ed220be

Please sign in to comment.