Skip to content

Commit

Permalink
Merge pull request #22 from wvenialbo/support/flake8-issues
Browse files Browse the repository at this point in the history
Support/flake8 issues
  • Loading branch information
wvenialbo authored Jan 29, 2025
2 parents dce9d3b + 80d3a0c commit 5fe3a2d
Show file tree
Hide file tree
Showing 26 changed files with 362 additions and 240 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/python-docsig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: DocSig

on: [workflow_dispatch]

jobs:
docsig:
name: Document method signature checking with DocSig
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade docsig
pip install -r requirements.txt
- name: Analysing the code with docsig
run: |
docsig "./src/GOES_DL"
2 changes: 1 addition & 1 deletion .github/workflows/python-flake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [workflow_dispatch]

jobs:
flake:
name: Code format checking with Flake8
name: Linting and style checking with Flake8
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down
65 changes: 64 additions & 1 deletion .github/workflows/python-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,71 @@ jobs:
run: |
autopep8 "./src/GOES_DL" --recursive --jobs 0 --diff --aggressive
pydocstyle:
name: Documentation linting with PyDocStyle
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade pydocstyle
pip install -r requirements.txt
- name: Analysing the code with pydocstyle
run: |
pydocstyle "./src/GOES_DL"
pydoclint:
name: Documentation linting with PyDocLint
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade pydoclint
pip install -r requirements.txt
- name: Analysing the code with pydoclint
run: |
pydoclint "./src/GOES_DL"
docsig:
name: Document method signature checking with DocSig
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade docsig
pip install -r requirements.txt
- name: Analysing the code with docsig
run: |
docsig "./src/GOES_DL"
flake:
name: Code format checking with Flake8
name: Linting and style checking with Flake8
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/python-pydoclint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: PyDocLint

on: [workflow_dispatch]

jobs:
pydoclint:
name: Documentation linting with PyDocLint
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade pydoclint
pip install -r requirements.txt
- name: Analysing the code with pydoclint
run: |
pydoclint "./src/GOES_DL"
25 changes: 25 additions & 0 deletions .github/workflows/python-pydocstyle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: PyDocStyle

on: [workflow_dispatch]

jobs:
pydocstyle:
name: Documentation linting with PyDocStyle
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade pydocstyle
pip install -r requirements.txt
- name: Analysing the code with pydocstyle
run: |
pydocstyle "./src/GOES_DL"
2 changes: 1 addition & 1 deletion scripts/toolchain.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ Write-Host ""
Write-Host "--- Running pydoctest {<file>|<dir>} [--parser {google|numpy|sphinx}]"
if ($isFolder) {
Push-Location -Path $project
pydoctest --parser numpy
#pydoctest --parser numpy
Pop-Location
}
else {
Expand Down
4 changes: 1 addition & 3 deletions src/GOES_DL/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Provide functionalities for downloading GOES and GridSat datasets.
"""
"""Provide functionalities for downloading GOES and GridSat datasets."""

__package_id__ = "GOES-DL"
__package_name__ = f"GOES Dataset Downloader - {__package_id__}"
Expand Down
50 changes: 30 additions & 20 deletions src/GOES_DL/dataset/base/locator_gg.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"""

from abc import abstractmethod
from collections.abc import Iterable
from datetime import datetime, timezone
from re import Match, findall, fullmatch
from typing import Iterable

from ..locator import ProductLocator

Expand Down Expand Up @@ -215,11 +215,14 @@ def timestamp_to_datetime(self, timestamp: str) -> datetime:
Notes
-----
The timestamp string extracted from the product's filename
are (or assumed to be) always in UTC timezone. Consumer of
product utilities should be aware of this assumption. The
user could convert the `datetime` object to the desired
timezone if needed.
The timestamp string extracted from the product's filename are
(or assumed to be) always in UTC timezone. Consumer of product
utilities should be aware of this assumption. The user could
convert the `datetime` object to the desired timezone if needed.
The framework raises `ValueError` if the timestamp does not
match the expected format or if the format specification is
ill-formed.
Parameters
----------
Expand All @@ -230,13 +233,6 @@ def timestamp_to_datetime(self, timestamp: str) -> datetime:
-------
datetime
The converted `datetime` object in UTC timezone.
Raises
------
ValueError
The framework raises an exception if the timestamp does not
match the expected format or if the format specification is
ill-formed.
"""
# File dates are always in UTC.
file_timestamp: str = f"{timestamp}+0000"
Expand Down Expand Up @@ -278,40 +274,54 @@ def _validate_set(

@classmethod
def _validate_channels(
cls, channel: str | Iterable[str], available_channels: Iterable[str]
cls: type["ProductLocatorGG"],
channel: str | Iterable[str],
available_channels: Iterable[str],
) -> None:
cls._validate_set("channel", channel, available_channels)

@classmethod
def _validate_datasource(
cls, datasource: str, available_datasources: Iterable[str]
cls: type["ProductLocatorGG"],
datasource: str,
available_datasources: Iterable[str],
) -> None:
cls._validate_entity("datasource", datasource, available_datasources)

@classmethod
def _validate_instrument(
cls, instrument: str, available_instruments: Iterable[str]
cls: type["ProductLocatorGG"],
instrument: str,
available_instruments: Iterable[str],
) -> None:
cls._validate_entity("instrument", instrument, available_instruments)

@classmethod
def _validate_level(cls, level: str, available_levels: set[str]) -> None:
def _validate_level(
cls: type["ProductLocatorGG"], level: str, available_levels: set[str]
) -> None:
cls._validate_entity("level", level, available_levels)

@classmethod
def _validate_origin(
cls, origin: str, available_origins: Iterable[str]
cls: type["ProductLocatorGG"],
origin: str,
available_origins: Iterable[str],
) -> None:
cls._validate_entity("origin", origin, available_origins)

@classmethod
def _validate_product(
cls, name: str, available_products: Iterable[str]
cls: type["ProductLocatorGG"],
name: str,
available_products: Iterable[str],
) -> None:
cls._validate_entity("product", name, available_products)

@classmethod
def _validate_scene(
cls, scene: str, available_scenes: Iterable[str]
cls: type["ProductLocatorGG"],
scene: str,
available_scenes: Iterable[str],
) -> None:
cls._validate_entity("scene", scene, available_scenes)
39 changes: 6 additions & 33 deletions src/GOES_DL/dataset/goes/locator.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,32 +56,6 @@ class GOESProductLocator(ProductLocatorGG):
Subclasses are responsible for initialising the attributes with the
appropriate values for the dataset and product details.
Attributes
----------
name : str
The name of the GOES-R Series imagery dataset product. Due to
how the dataset directories are organised, only a single product
can be provided.
level : str
The level of the GOES-R Series imagery dataset product, e.g.
"L1b" or "L2".
scene : str
The scene of the GOES-R Series imagery dataset product, e.g.
"F" or "C".
instrument : str
The instrument of the GOES-R Series imagery dataset product,
e.g. "ABI" or "GLM".
modes : list[str]
The list of modes of the GOES-R Series imagery dataset product,
e.g. "M3" or "M6".
channels : list[str]
The list of channels of the GOES-R Series imagery dataset
product, e.g. "C08" or "C13".
origin : str
The origin identifier of the GOES-R Series imagery dataset
product, e.g. "G16". Due to how the dataset directories are
organised, only a single origin may be provided.
Methods
-------
get_base_url(datasource: str)
Expand Down Expand Up @@ -132,7 +106,7 @@ class GOESProductLocator(ProductLocatorGG):
# Satellites in the GOES-R Series are identified by the following
# IDs:
AVAILABLE_ORIGINS: dict[str, str] = {
f"G{id:02d}": f"goes{id:02d}" for id in range(16, 19)
f"G{idn:02d}": f"goes{idn:02d}" for idn in range(16, 19)
}

# Supported instruments from the GOES-R series:
Expand Down Expand Up @@ -208,12 +182,11 @@ def __init__(
dataset directories are organised, only a single origin may
be provided.
Raises
------
ValueError
If the provided origin, level or instrument is invalid. Or
if an unexpected or unsupported setting is required for an
instrument that does not support it.
Notes
-----
ValueError is raised if the provided origin, level or instrument
is invalid. Or if an unexpected or unsupported setting is
required for an instrument that does not support it.
"""
# TODO: Too many positional arguments. Solve it by using
# the Builder or Factory methods, or patterns like
Expand Down
8 changes: 4 additions & 4 deletions src/GOES_DL/dataset/goes/locator_abi.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ def __init__(
dataset directories are organised, only a single origin may
be provided.
Raises
------
ValueError
If the provided origin, level or scene is invalid.
Notes
-----
ValueError is raised if the provided origin, level or scene is
invalid.
"""
# TODO: Too many positional arguments. Solve it by using
# the Builder or Factory methods, or patterns like
Expand Down
5 changes: 2 additions & 3 deletions src/GOES_DL/dataset/goes/locator_dc.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(
scene : str
The scene of the GOES-R Series imagery dataset product, e.g.
"F" or "C".
channels : list[str]
channels : str | list[str]
The list of channels of the GOES-R Series imagery dataset
ABI product, e.g. "C08" or "C13".
origin : str
Expand Down Expand Up @@ -112,7 +112,7 @@ def __init__(
scene : str
The scene of the GOES-R Series imagery dataset product, e.g.
"F" or "C".
channels : list[str]
channels : str | list[str]
The list of channels of the GOES-R Series imagery dataset
ABI product, e.g. "C08" or "C14".
origin : str
Expand Down Expand Up @@ -161,7 +161,6 @@ def __init__(self, scene: str, origin: str) -> None:
dataset directories are organised, only a single origin may
be provided.
"""

self.available_channels = self.WV_CHANNELS

super().__init__(
Expand Down
5 changes: 5 additions & 0 deletions src/GOES_DL/dataset/goes/locator_dp.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ def __init__(self, name: str, scene: str, origin: str) -> None:
namely a satellite identifier, e.g. "G16". Due to how the
dataset directories are organised, only a single origin may
be provided.
Raises
------
ValueError
If the provided scene or origin is invalid.
"""
self._validate_product(name, self.AVAILABLE_PRODUCTS)

Expand Down
Loading

0 comments on commit 5fe3a2d

Please sign in to comment.