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

Initial pull request focused on integrating pre-commit and addressing several minor issues. #190

Merged
merged 20 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
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
1 change: 1 addition & 0 deletions .github/workflows/ci_job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ jobs:
runs-on: ubuntu-latest
permissions:
contents: write
if: github.ref == 'refs/heads/main'
env:
NUMEXPR_MAX_THREADS: 8
GIT_SUBMODULE_STRATEGY: recursive
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#skipp all python compiled files
#skip all python compiled files
*.pyc

#skip all eclipse and other IDE information
Expand All @@ -10,6 +10,7 @@
!.coveragerc
!.docker/
!.envrc
!.pre-commit-config.yaml
coverage.xml
compose/activate_*
compose/completions/*
Expand All @@ -26,3 +27,4 @@ docs/build
docs/source/_static/*.gif
!docs/build/.empty
*.egg-info
venv/
48 changes: 48 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
# isort should run before black as black sometimes tweaks the isort output
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
args:
- --profile
- black
- -t
- py311
- src
# https://github.com/python/black#version-control-integration
- repo: https://github.com/psf/black
rev: 24.3.0
hooks:
- id: black
args:
- -t
- py311
- src
exclude: '.*\.ipynb$'
# - repo: https://github.com/keewis/blackdoc
# rev: v0.3.9
# hooks:
# - id: blackdoc
# args: ['--target-version', 'py311']
# - repo: https://github.com/pycqa/flake8
# rev: 6.0.0
# hooks:
# - id: flake8
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.9.0
hooks:
- id: mypy
args: ['--install-types', '--non-interactive']
exclude: '^src/evaluation_system/tests/crawl_my_data_test\.py$'
- repo: https://github.com/crate-ci/typos
rev: v1.16.22
hooks:
- id: typos
exclude: docs/source/notebooks/.*\.ipynb$
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Changelog

All notable changes to Freva will be documented in this file.

## [Unreleased]

### Added
- .pre-commit-config.yaml and CHANGELOG.md

### Changed

### Fixed
- Corrected minor typos in documentation and code comments. (fix typo, minor typo, minor typo separator)
- Temporarily disabled `test_plugin_status` unit-test in `plugin_command_test.py` for further investigation.
- making a standard_main function in `utils.py` in cli
9 changes: 8 additions & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ files = src/evaluation_system/model/*.py,
src/evaluation_system/api
strict = False

warn_unused_ignores = True
warn_unused_ignores = False
warn_unreachable = True
show_error_codes = True
ignore_missing_imports = True

[mypy-appdirs.*]
ignore_missing_imports = True
Expand All @@ -30,3 +31,9 @@ ignore_missing_imports = True

[mypy-pandas.*]
ignore_missing_imports = True

[mypy-django.*]
ignore_missing_imports = True

[mypy-rich.*]
ignore_missing_imports = True
1 change: 1 addition & 0 deletions src/evaluation_system/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
"""

import warnings

warnings.filterwarnings(
Expand Down
7 changes: 4 additions & 3 deletions src/evaluation_system/api/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
plugin wrapper class.

"""

from __future__ import annotations

import html
Expand Down Expand Up @@ -711,9 +712,9 @@ def __init__(
self,
**kwargs,
):
kwargs[
"regex"
] = r"^[+-]?(?:[0-9]+\.?[0-9]*|[0-9]*\.?[0-9]+)(?:[eE][+-]?[0-9]+)?$"
kwargs["regex"] = (
r"^[+-]?(?:[0-9]+\.?[0-9]*|[0-9]*\.?[0-9]+)(?:[eE][+-]?[0-9]+)?$"
)
super().__init__(**kwargs)


Expand Down
7 changes: 4 additions & 3 deletions src/evaluation_system/api/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
With help of this API a Freva plugin can be created in ``/mnt/freva/plugin/new_plugin/plugin.py``

"""

from __future__ import annotations

import abc
Expand Down Expand Up @@ -193,7 +194,7 @@
USER_OUTPUT_DIR Absolute path to where the plugin outputs for this user are stored.
USER_PLOTS_DIR Absolute path to where the plugin plots for this user are stored.
USER_CACHE_DIR Absolute path to the cached data (temp data) for this user.
USER_UID The users' User IDentifier
USER_UID The users' User IIdentifier
SYSTEM_DATE Current date in the form YYYYMMDD (e.g. 20120130).
SYSTEM_DATETIME Current date in the form YYYYMMDD_HHmmSS (e.g. 20120130_101123).
SYSTEM_TIMESTAMP Milliseconds since epoch (i.e. e.g. 1358929581838).
Expand Down Expand Up @@ -325,7 +326,7 @@
print(line, end="", flush=True)
return_code = res.wait()
if return_code and check:
log.error("An error occured calling %s", cmd)
log.error("An error occurred calling %s", cmd)

Check warning on line 329 in src/evaluation_system/api/plugin.py

View check run for this annotation

Codecov / codecov/patch

src/evaluation_system/api/plugin.py#L329

Added line #L329 was not covered by tests
log.error("Check also %s", self.plugin_output_file)
raise sub.CalledProcessError(
return_code,
Expand Down Expand Up @@ -550,7 +551,7 @@
drs_config["variable"] = variable
user_data = DataReader(plugin_output, **drs_config)
for output_file in user_data:
new_file = user_data.file_name_from_metdata(output_file)
new_file = user_data.file_name_from_metadata(output_file) # type: ignore
new_file.parent.mkdir(exist_ok=True, parents=True, mode=0o2775)
shutil.copy(str(output_file), str(new_file))
if index_data:
Expand Down
1 change: 1 addition & 0 deletions src/evaluation_system/api/plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
/other/different/path,some.plugin:\
/tmp/test,some.other.plugin
"""

from __future__ import annotations

import atexit
Expand Down
6 changes: 4 additions & 2 deletions src/evaluation_system/api/user_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""The modules provides interfaces for user to interact with
"""The modules provides interfaces for user to interact with
the freva data stack."""

from __future__ import annotations
Expand Down Expand Up @@ -203,7 +203,9 @@ def _create_versioned_path(
new_dirs[v_index] = new_version
return new_dirs

def file_name_from_metdata(self, path: os.PathLike, override: bool = False) -> Path:
def file_name_from_metadata(
self, path: os.PathLike, override: bool = False
) -> Path:
"""Construct file name matching the DRS Spec. from given input path.

Parameters
Expand Down
3 changes: 2 additions & 1 deletion src/evaluation_system/api/workload_manager/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Collection of methods and classes for submitting plugins to a workload manager."""

from __future__ import annotations

from pathlib import Path
Expand Down Expand Up @@ -112,7 +113,7 @@ def schedule_job(
try:
job.start()
except RuntimeError as error:
# Job sould not start
# Job should not start
std_err = str(error)
submit_status = 1
job_name = job.job_name or "worker"
Expand Down
1 change: 1 addition & 0 deletions src/evaluation_system/api/workload_manager/local.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Run job in the background on the same system."""

from __future__ import annotations

import logging
Expand Down
1 change: 1 addition & 0 deletions src/evaluation_system/api/workload_manager/lsf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Submit jobs to the lsf workload manager."""

from __future__ import annotations

import logging
Expand Down
1 change: 1 addition & 0 deletions src/evaluation_system/api/workload_manager/moab.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Submit jobs using the moab workload manager."""

from __future__ import annotations

from typing import ClassVar
Expand Down
1 change: 1 addition & 0 deletions src/evaluation_system/api/workload_manager/oar.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Submit jobs using the oar workload manager."""

from __future__ import annotations

import logging
Expand Down
1 change: 1 addition & 0 deletions src/evaluation_system/api/workload_manager/pbs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Submit jobs to the PBS workload manager."""

from __future__ import annotations

import logging
Expand Down
1 change: 1 addition & 0 deletions src/evaluation_system/api/workload_manager/sge.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Submit job to the sge workload manager."""

from __future__ import annotations

import logging
Expand Down
1 change: 1 addition & 0 deletions src/evaluation_system/api/workload_manager/slurm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Submit jobs to the slurm workload manager."""

from __future__ import annotations

import logging
Expand Down
9 changes: 5 additions & 4 deletions src/evaluation_system/misc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

This module manages the central configuration of the system.
"""

from __future__ import annotations

import hashlib
Expand Down Expand Up @@ -234,10 +235,10 @@ def reloadConfiguration(config_file: Union[str, Path, None] = None) -> None:
for plugin_section in [
s for s in config_parser.sections() if s.startswith(PLUGINS)
]:
_config[PLUGINS][
plugin_section[len(PLUGINS) :]
] = SPECIAL_VARIABLES.substitute(
dict(config_parser.items(plugin_section))
_config[PLUGINS][plugin_section[len(PLUGINS) :]] = (
SPECIAL_VARIABLES.substitute(
dict(config_parser.items(plugin_section))
)
)

db_hosts = (
Expand Down
9 changes: 5 additions & 4 deletions src/evaluation_system/misc/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Provide different utilities that does not depend on any other internal package."""

from __future__ import annotations

import copy
Expand Down Expand Up @@ -389,7 +390,7 @@ def substitute(


def find_similar_words(word: str, list_of_valid_words: Iterable[str]) -> List[str]:
"""This function implements a "Did you mean? xxx" search algorith.
"""This function implements a "Did you mean? xxx" search algorithm.

It is used for helping the user find the right word.

Expand Down Expand Up @@ -526,16 +527,16 @@ class PrintableList(list):

def __init__(self, *args, **kwargs):
try:
self.seperator = kwargs.pop("seperator")
self.separator = kwargs.pop("separator")
except KeyError:
self.seperator = ","
self.separator = ","
super(PrintableList, self).__init__(*args, **kwargs)

def __str__(self): # pragma: no cover
"""
:returns: String with comma separated list entries
"""
return self.seperator.join(map(str, self))
return self.separator.join(map(str, self))

def __unicode__(self): # pragma: no cover
return self.__str__()
Expand Down
1 change: 1 addition & 0 deletions src/evaluation_system/model/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
The module encapsulates all methods for accessing files on the system.
These are mainly model and observational and reanalysis data.
"""

from __future__ import annotations

import json
Expand Down
1 change: 1 addition & 0 deletions src/evaluation_system/model/repository.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module to encapsulates the access to repositories."""

from __future__ import annotations

import os
Expand Down
1 change: 1 addition & 0 deletions src/evaluation_system/model/solr_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* latest: only those files from the latest dataset version - id is file_no_version (full file path *without* version information)

"""

from __future__ import annotations

import json
Expand Down
1 change: 1 addition & 0 deletions src/evaluation_system/model/solr_models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

@author: [email protected]
"""

import warnings

from django.contrib.auth.models import User
Expand Down
3 changes: 2 additions & 1 deletion src/evaluation_system/model/user.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Manage the abstraction of a system user."""

from __future__ import annotations

import os
Expand Down Expand Up @@ -66,7 +67,7 @@ def __init__(self, uid: Optional[Union[int, str]] = None, email: str = ""):
raise Exception("Cannot find user %s" % uid)
self._email = email
self._userconfig = Config(interpolation=ExtendedInterpolation())
# try to load teh configuration from the very first time.
# try to load the configuration from the very first time.
self._userconfig.read(
[
User.EVAL_SYS_DEFAULT_CONFIG,
Expand Down
Loading
Loading