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

Add mypy Pre-Commit Hook for files Pt.2 #661

Merged
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ce10f95
config file update
daralynnrhode Jun 25, 2024
e9e81fb
pyproject update to only tests files, cdf, and ccsd folder/files
daralynnrhode Jun 25, 2024
7b8f85b
cli.py file updates
daralynnrhode Jun 25, 2024
64db399
utils.py update
daralynnrhode Jun 25, 2024
65e50b9
mypy update
daralynnrhode Jun 25, 2024
848bcf0
update
daralynnrhode Jun 25, 2024
ee1cdcc
test fix
daralynnrhode Jun 25, 2024
99d036a
test update
daralynnrhode Jun 25, 2024
076ec2e
reformating
daralynnrhode Jun 25, 2024
e330994
changes from Maxine
daralynnrhode Jun 25, 2024
548c2ad
Merge branch 'dev' into add_mypy_files
daralynnrhode Jun 26, 2024
ed2f00b
fixing merge conflict
daralynnrhode Jun 26, 2024
d8c09e9
ignore errors fixes
daralynnrhode Jun 26, 2024
0e00f41
fixing tests fail
daralynnrhode Jun 26, 2024
5315a12
Apply suggestions from code review
daralynnrhode Jun 26, 2024
68cb9dc
updates
daralynnrhode Jun 26, 2024
ea8c6c2
Merge branch 'add_mypy_files' of github.com:daralynnrhode/imap_proces…
daralynnrhode Jun 26, 2024
c2eb1ea
Merge branch 'dev' into add_mypy_files
daralynnrhode Jun 27, 2024
57a12ea
merge fixes
daralynnrhode Jun 27, 2024
8635d9f
last clean up
daralynnrhode Jun 28, 2024
dfcaffe
Merge branch 'dev' into add_mypy_files
daralynnrhode Jul 2, 2024
9533527
fixing merge issue
daralynnrhode Jul 2, 2024
144fef1
Merge branch 'dev' of github.com:daralynnrhode/imap_processing into a…
daralynnrhode Jul 3, 2024
c525108
Merge branch 'dev' into add_mypy_files
daralynnrhode Jul 4, 2024
46d3cde
removing docs from check
daralynnrhode Jul 4, 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
11 changes: 10 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,13 @@ repos:
hooks:
- id: numpydoc-validation
exclude: '^imap_processing/tests/|.*test.*'

- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.10.0'
hooks:
- id: mypy
pass_filenames: false
args: [., --strict, --explicit-package-bases,
--disable-error-code, import-untyped,
--disable-error-code, import-not-found,
--disable-error-code, no-untyped-call,
--disable-error-code, type-arg]
21 changes: 14 additions & 7 deletions imap_processing/cdf/cdf_attribute_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ def __init__(self, data_dir: Path):
self.global_attributes = CdfAttributeManager._load_yaml_data(
self.source_dir / DEFAULT_GLOBAL_CDF_ATTRS_FILE
)
self.variable_attributes = dict()
self.variable_attributes = dict() # type: ignore[var-annotated]
# Todo Change, Need type annotation for "variable_attributes"
# (hint: "variable_attributes: dict[<type>, <type>] = ...")
daralynnrhode marked this conversation as resolved.
Show resolved Hide resolved

def _load_default_global_attr_schema(self) -> dict:
"""
Expand All @@ -93,7 +95,9 @@ def _load_default_global_attr_schema(self) -> dict:
self.source_dir / "shared" / DEFAULT_GLOBAL_CDF_ATTRS_SCHEMA_FILE
)
# Load the Schema
return CdfAttributeManager._load_yaml_data(default_schema_path)
return CdfAttributeManager._load_yaml_data(default_schema_path) # type: ignore[no-any-return]
daralynnrhode marked this conversation as resolved.
Show resolved Hide resolved

# TODO Change, Returning Any from function declared to return "dict[Any, Any]"

def _load_default_variable_attr_schema(self) -> dict:
"""
Expand All @@ -108,9 +112,11 @@ def _load_default_variable_attr_schema(self) -> dict:
self.source_dir / "shared" / DEFAULT_VARIABLE_CDF_ATTRS_SCHEMA_FILE
)
# Load the Schema
return CdfAttributeManager._load_yaml_data(default_schema_path)
return CdfAttributeManager._load_yaml_data(default_schema_path) # type: ignore[no-any-return]

# TODO Change Returning Any from function declared to return "dict[Any, Any]"

def load_global_attributes(self, file_path: str):
def load_global_attributes(self, file_path: str) -> None:
"""
Update the global attributes property with the attributes from the file.

Expand Down Expand Up @@ -148,7 +154,7 @@ def add_global_attribute(self, attribute_name: str, attribute_value: str) -> Non
self.global_attributes[attribute_name] = attribute_value

@staticmethod
def _load_yaml_data(file_path: str | Path) -> dict:
def _load_yaml_data(file_path: str | Path) -> yaml:
daralynnrhode marked this conversation as resolved.
Show resolved Hide resolved
"""
Load a yaml file from the provided path.

Expand Down Expand Up @@ -236,10 +242,11 @@ def get_variable_attributes(self, variable_name: str) -> dict:
Returns
-------
dict
I have no idea todo check.
Dictionary of variable attributes.
"""
# TODO: Create a variable attribute schema file, validate here
if variable_name in self.variable_attributes:
return self.variable_attributes[variable_name]
return self.variable_attributes[variable_name] # type: ignore[no-any-return]
# TODO Change, Returning Any from function declared to return "dict[Any, Any]"
# TODO: throw an error?
return {}
6 changes: 3 additions & 3 deletions imap_processing/cdf/imap_cdf_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
class ImapCdfAttributes(CdfAttributeManager):
"""Contains IMAP specific tools and settings for CDF management."""

def __init__(self):
def __init__(self) -> None:
"""Set the path to the config directory."""
super().__init__(Path(__file__).parent / "config")

def add_instrument_global_attrs(self, instrument: str):
def add_instrument_global_attrs(self, instrument: str) -> None:
"""
Add instrument specific global attributes.

Expand All @@ -29,7 +29,7 @@ def add_instrument_global_attrs(self, instrument: str):
# Looks for file named "imap_{instrument}_global_cdf_attrs.yaml"
self.load_global_attributes(f"imap_{instrument}_global_cdf_attrs.yaml")

def add_instrument_variable_attrs(self, instrument: str, level: str):
def add_instrument_variable_attrs(self, instrument: str, level: str) -> None:
"""
Add instrument specific variable attributes.

Expand Down
12 changes: 8 additions & 4 deletions imap_processing/cdf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from cdflib.xarray.cdf_to_xarray import ISTP_TO_XARRAY_ATTRS

import imap_processing
from imap_processing._version import __version__, __version_tuple__ # noqa: F401

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -76,7 +77,10 @@ def load_cdf(
"""
# TODO: remove this when cdflib is updated to version >1.3.0
if "to_datetime" not in kwargs:
kwargs["to_datetime"] = True
kwargs["to_datetime"] = True # type: ignore[assignment]
# ToDO Change
# Incompatible types in assignment
# (expression has type "bool", target has type "dict[Any, Any]")
daralynnrhode marked this conversation as resolved.
Show resolved Hide resolved
dataset = cdf_to_xarray(file_path, kwargs)

# cdf_to_xarray converts single-value attributes to lists
Expand All @@ -97,7 +101,7 @@ def load_cdf(
return dataset


def write_cdf(dataset: xr.Dataset):
def write_cdf(dataset: xr.Dataset) -> Path:
"""
Write the contents of "data" to a CDF file using cdflib.xarray_to_cdf.

Expand All @@ -115,7 +119,7 @@ def write_cdf(dataset: xr.Dataset):

Returns
-------
file_path : pathlib.Path
file_path : list[Path]
daralynnrhode marked this conversation as resolved.
Show resolved Hide resolved
Path to the file created.
"""
# Create the filename from the global attributes
Expand Down Expand Up @@ -153,7 +157,7 @@ def write_cdf(dataset: xr.Dataset):
# The Logical_file_id is always the name of the file without the extension
dataset.attrs["Logical_file_id"] = file_path.stem
# Add the processing version to the dataset attributes
dataset.attrs["ground_software_version"] = imap_processing.__version__
dataset.attrs["ground_software_version"] = imap_processing._version.__version__

# Convert the xarray object to a CDF
xarray_to_cdf(
Expand Down
Loading
Loading