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

Use ruff as linter #405

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 7 additions & 7 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
- name: Set up python
uses: actions/setup-python@v4
- name: Check black style and linting
run: |
pip install black
black --check src tests
pip install flake8
flake8 src tests
pip install isort
isort --profile=black src tests
run: pip install ruff
- name: Ruff check
if: ${{ always() }}
run: ruff check .
- name: Ruff format
if: ${{ always() }}
run: ruff format . --check
27 changes: 14 additions & 13 deletions examples/s/d/nn/_project/aggregate_surfaces.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
"""Use fmu-dataio for aggregated surfaces created by an aggregation service."""
from __future__ import annotations

import logging
from pathlib import Path

import fmu.dataio
import numpy as np
import xtgeo
import yaml

import fmu.dataio


def main():
"""Aggregate one surface across X realizations from the example case and store the
Expand Down Expand Up @@ -56,9 +55,6 @@ def main():
# This is the ID we assign to this set of aggregations
aggregation_id = "something_very_unique" # IRL this will usually be a uuid

# We aggregate these source surfaces and collect results in list of dictionaries
aggregations = []

# Initialize an AggregatedData object for this set of aggregations
exp = fmu.dataio.AggregatedData(
source_metadata=source_metadata,
Expand All @@ -81,8 +77,8 @@ def main():

# ==============================================================================
# Example 2: We only want the metadata (e.g. we are in a cloud service)
metadata = exp.generate_metadata(aggregated_surface, operation=operation)
print(f"Example 2: Metadata generated")
exp.generate_metadata(aggregated_surface, operation=operation)
janbjorge marked this conversation as resolved.
Show resolved Hide resolved
print("Example 2: Metadata generated")

# At this point, we have the surface, the operation and the metadata
# These can be collected into e.g. a list or a dictionary for further usage,
Expand Down Expand Up @@ -128,8 +124,7 @@ def _parse_yaml(fname):
"""

with open(fname) as stream:
data = yaml.safe_load(stream)
return data
return yaml.safe_load(stream)


def _metadata_filename(fname):
Expand All @@ -152,7 +147,10 @@ def _get_realization_ids(casepath):


def _get_source_surfaces_from_disk(
casepath: Path, iter_name: str, realization_ids: list, relative_path: Path
casepath: Path,
iter_name: str,
realization_ids: list,
relative_path: Path,
):
"""Collect surfaces and metadata from disk.

Expand Down Expand Up @@ -192,7 +190,10 @@ def _get_source_surfaces_from_disk(


def _get_source_surfaces_from_sumo(
case_uuid: str, iter_name: str, realization_ids: list, relative_path: Path
case_uuid: str,
iter_name: str,
realization_ids: list,
relative_path: Path,
):
"""Collect surfaces and metadata from Sumo.

Expand All @@ -202,7 +203,7 @@ def _get_source_surfaces_from_sumo(

Not implemented.
"""
raise NotImplementedError()
raise NotImplementedError


if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import pathlib

import fmu.dataio as dataio
import xtgeo
from fmu.config import utilities as ut

import fmu.dataio as dataio

CFG = ut.yaml_load("../../fmuconfig/output/global_variables.yml")

FOLDER = pathlib.Path("../output/grids")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
"""
import pathlib

import fmu.dataio
import pandas as pd
from fmu.config import utilities as ut

import fmu.dataio

CFG = ut.yaml_load("../../fmuconfig/output/global_variables.yml")

IN_ROXAR = False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
"""
from pathlib import Path

import fmu.dataio as dataio
import xtgeo
from fmu.config import utilities as ut

import fmu.dataio as dataio

CFG = ut.yaml_load("../../fmuconfig/output/global_variables.yml")

FILES = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"""Export faultpolygons via dataio with metadata."""
from pathlib import Path

import fmu.dataio as dataio
import xtgeo
from fmu.config import utilities as utils

import fmu.dataio as dataio

CFG = utils.yaml_load("../../fmuconfig/output/global_variables.yml")

HORISONNAMES = CFG["rms"]["horizons"]["TOP_RES"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
"""
from pathlib import Path

import fmu.dataio as dataio
import xtgeo
from fmu.config import utilities as ut

import fmu.dataio as dataio

CFG = ut.yaml_load("../../fmuconfig/output/global_variables.yml")

# property attributes, the key is "pattern" and the value is generic name to be used:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
"""
from pathlib import Path

import fmu.dataio as dataio
import xtgeo
from fmu.config import utilities as ut

import fmu.dataio as dataio

CFG = ut.yaml_load("../../fmuconfig/output/global_variables.yml")

FILES = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
"""
from pathlib import Path

import fmu.dataio as dataio
import xtgeo
from fmu.config import utilities as ut

import fmu.dataio as dataio

CFG = ut.yaml_load("../../fmuconfig/output/global_variables.yml")

FILES = {
Expand Down
129 changes: 37 additions & 92 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ classifiers = [
]
dynamic = ["version"]
dependencies = [
"xtgeo>=2.16",
"PyYAML",
"pyarrow",
"fmu-config>=1.1.0",
"pandas",
"numpy",
"pandas",
"pyarrow",
"PyYAML",
"xtgeo>=2.16",
]

[project.urls]
Expand All @@ -46,64 +46,33 @@ Documentation = "https://fmu-dataio.readthedocs.io"

[project.optional-dependencies]
dev = [
"black",
"coverage>=4.1",
"flake8",
"isort",
"jsonschema",
"hypothesis",
"jsonschema",
"mypy",
"pylint",
"pytest",
"pytest-cov",
"pydocstyle",
"pytest-runner",
"pytest-cov",
"pytest-mock",
"termcolor",
"pytest-runner",
"pytest",
"rstcheck",
"ruff",
"termcolor",
]
docs = [
"pydocstyle",
"Sphinx<7",
"autoapi",
"sphinx-rtd-theme",
"pydocstyle",
"sphinx-autodoc-typehints<1.23",
"sphinxcontrib-apidoc",
"sphinx-rtd-theme",
"sphinx-togglebutton",
"Sphinx<7",
"sphinxcontrib-apidoc",
"urllib3<1.27",
]

[project.entry-points.ert]
dataio_case_metadata = "fmu.dataio.scripts.create_case_metadata"


[tool.black]
line-length = 88
target-version = ['py38', 'py39', 'py310', 'py311']
include = '\.pyi?$'
exclude = '''
/(
\.eggs
| \.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| _build
| buck-out
| build
| dist
# The following are specific to Black, you probably don't want those.
| blib2to3
| tests/data
| profiling
)/
'''

[tool.isort]
profile = "black"


[tool.setuptools_scm]
write_to = "src/fmu/dataio/version.py"

Expand All @@ -117,54 +86,30 @@ testpaths = "tests"
markers = ["integration: marks a test as an integration test"]
xfail_strict = true

[tool.mypy]
ignore_missing_imports = true

[tool.pydocstyle]
convention = "google"
match = '(?!(test_|_)).*\.py'

[tool.pylint.MASTER]
ignore = ["version.py", "conf.py"]

[tool.pylint.BASIC]
additional-builtins = ["_x", "_y", "_z", "_tmp1", "_tmp2"]
good-names = ["logger", "version", "i", "j", "k", "x", "y", "z", "_"]
variable-rgx = "^[a-z_][_a-z0-9]+((_[a-z0-9]+)*)?$"
argument-rgx = "^[a-z_][_a-z0-9]+((_[a-z0-9]+)*)?$"
dummy-variables-rgx = "^_+[a-z0-9]*?$|dummy"

[tool.pylint.TYPECHECK]
generated-members = ["np.*", "numpy.*", "pd.*", "pandas.*"]

[tool.pylint.FORMAT]
max-line-length = 88
max-module-lines = 3000

[tool.pylint.DESIGN]
max-attributes = 30
max-args = 20
max-locals = 30
max-branches = 15
max-bool-expr = 8

[tool.pylint.SIMILARITIES]
min-similarity-lines = 40
ignore-comments = "yes"
ignore-docstrings = "no"
ignore-imports = "yes"

[tool.pylint."MESSAGES CONTROL"]
disable = """
fixme,
missing-docstring,
protected-access,
C0330,
useless-object-inheritance,
import-outside-toplevel,
import-error,
no-name-in-module,
raise-missing-from,
unspecified-encoding,
wrong-import-order
"""
[tool.ruff]
ignore = [
"C901",
]
select = [
"C",
"E",
"F",
"I",
"PIE",
"Q",
"RET",
"RSE",
"SIM",
"W",
# "C90",
# "NPY",
# "PD",
# "PL",
]
line-length = 88
[tool.ruff.lint.isort]
combine-as-imports = true
3 changes: 1 addition & 2 deletions src/fmu/dataio/_design_kw.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ def unmatched_templates(line):
bracketpattern = re.compile("<.+?>")
if bracketpattern.search(line):
return bracketpattern.findall(line)
else:
return []
return []


def is_comment(line):
Expand Down
7 changes: 2 additions & 5 deletions src/fmu/dataio/_filedata_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,7 @@ def _get_filestem(self):
# treat norwegian special letters
stem = stem.replace("æ", "ae")
stem = stem.replace("ø", "oe")
stem = stem.replace("å", "aa")

return stem
return stem.replace("å", "aa")

def _get_path(self):
"""Construct and get the folder path(s)."""
Expand Down Expand Up @@ -211,8 +209,7 @@ def _get_path_generic(self, mode="realization", allow_forcefolder=True, info="")
"starting with '/'. This is strongly discouraged and is only "
"allowed if classvariable allow_forcefolder_absolute is set to True"
)
else:
warn("Using absolute paths in forcefolder is not recommended!")
warn("Using absolute paths in forcefolder is not recommended!")

# absolute if starts with "/", otherwise relative to outroot
dest = Path(self.dataio.forcefolder)
Expand Down
2 changes: 1 addition & 1 deletion src/fmu/dataio/_fmu_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def generate_ert2_metadata(self):
"Generate ERT2 metadata continues, and real ID %s", self.real_id
)

mreal = meta["realization"] = dict()
mreal = meta["realization"] = {}
mreal["id"] = self.real_id
mreal["uuid"] = real_uuid
mreal["name"] = self.real_name
Expand Down
Loading
Loading