Skip to content

Commit

Permalink
Fix style (#1378)
Browse files Browse the repository at this point in the history
* style: change to double quotes

fix: switch from `python-version` to `target-version` and set to minimum
Python 3.8

* fix: escape regex backslash

* style: black enforces single newline before imports

* style: fix up tests

* fix: add missing star for keyword arguments unpacking
  • Loading branch information
Midnighter authored Feb 18, 2024
1 parent 79a16d4 commit 893593d
Show file tree
Hide file tree
Showing 33 changed files with 41 additions and 58 deletions.
24 changes: 12 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
[build-system]
requires = [
'setuptools>=40.6.0',
'wheel'
"setuptools>=40.6.0",
"wheel"
]
build-backend = "setuptools.build_meta"

[tool.black]
line-length = 88
python-version = ['py36']
include = '\.pyi?$'
exclude = '''
target-version = ["py38"]
include = "\\.pyi?$"
exclude = """
(
/(
\.eggs # exclude a few common directories in the
| \.git # root of the project
| \.hg
| \.mypy_cache
| \.tox
| \.venv
\\.eggs # exclude a few common directories in the
| \\.git # root of the project
| \\.hg
| \\.mypy_cache
| \\.tox
| \\.venv
| _build
| buck-out
| build
Expand All @@ -27,4 +27,4 @@ exclude = '''
| benchmarks
)/
)
'''
"""
1 change: 0 additions & 1 deletion src/cobra/core/configuration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Provide a global configuration object."""


import logging
import pathlib
import types
Expand Down
1 change: 0 additions & 1 deletion src/cobra/core/species.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Define the Species class, used as a base for Gene and Metabolite."""


from copy import deepcopy
from typing import TYPE_CHECKING, FrozenSet, Optional

Expand Down
1 change: 1 addition & 0 deletions src/cobra/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module for shared exceptions in the Cobra package."""

import optlang.interface


Expand Down
1 change: 0 additions & 1 deletion src/cobra/flux_analysis/gapfilling.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Provide the base class and utility function for gap filling."""


import logging
from typing import TYPE_CHECKING, Dict, List, Optional, Union

Expand Down
1 change: 0 additions & 1 deletion src/cobra/flux_analysis/loopless.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Provide functions to remove thermodynamically infeasible loops."""


from typing import TYPE_CHECKING, Dict, Optional, Union

import numpy as np
Expand Down
1 change: 0 additions & 1 deletion src/cobra/flux_analysis/variability.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Provide variability based methods such as flux variability or gene essentiality."""


import logging
from typing import TYPE_CHECKING, List, Optional, Set, Tuple, Union
from warnings import warn
Expand Down
1 change: 0 additions & 1 deletion src/cobra/io/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Provide functions for loading and saving metabolic models."""


from cobra.io.dict import model_from_dict, model_to_dict
from cobra.io.json import from_json, load_json_model, save_json_model, to_json
from cobra.io.mat import load_matlab_model, save_matlab_model
Expand Down
3 changes: 2 additions & 1 deletion src/cobra/io/json.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Provide functions for I/O in JSON format."""

from pathlib import Path
from typing import IO, TYPE_CHECKING, Any, Union

Expand Down Expand Up @@ -72,7 +73,7 @@ def save_json_model(
filename: Union[str, Path, IO],
sort: bool = False,
pretty: bool = False,
**kwargs: Any
**kwargs: Any,
) -> None:
"""Write the cobra model to a file in JSON format.
Expand Down
30 changes: 18 additions & 12 deletions src/cobra/io/mat.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,19 +213,23 @@ def _cell_to_str_list(
"""
if str_prefix and pattern_split:
return [
[
str_prefix + str_found if str_prefix not in str_found else str_found
for str_found in pattern_split.findall(str(each_cell[0][0]))
]
if np.size(each_cell[0])
else empty_value
(
[
str_prefix + str_found if str_prefix not in str_found else str_found
for str_found in pattern_split.findall(str(each_cell[0][0]))
]
if np.size(each_cell[0])
else empty_value
)
for each_cell in m_cell
]
elif pattern_split:
return [
pattern_split.findall(str(each_cell[0][0]))
if np.size(each_cell[0])
else empty_value
(
pattern_split.findall(str(each_cell[0][0]))
if np.size(each_cell[0])
else empty_value
)
for each_cell in m_cell
]
else:
Expand Down Expand Up @@ -481,9 +485,11 @@ def mat_parse_notes(
# things like PMC or OMIM, but those are placed as string in notes.
_notes = _cell_to_str_list(mat_struct[caseunfold[mat_key]][0, 0])
notes[name] = [
_pubmed_re.sub("", x).strip()
if x and len(_pubmed_re.sub("", x).strip())
else None
(
_pubmed_re.sub("", x).strip()
if x and len(_pubmed_re.sub("", x).strip())
else None
)
for x in _notes
]
elif mat_key == "rxnConfidenceScores".casefold():
Expand Down
6 changes: 3 additions & 3 deletions src/cobra/io/sbml.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,9 +614,9 @@ def _sbml_to_model(
{
"familyName": c.getFamilyName() if c.isSetFamilyName() else None,
"givenName": c.getGivenName() if c.isSetGivenName() else None,
"organisation": c.getOrganisation()
if c.isSetOrganisation()
else None,
"organisation": (
c.getOrganisation() if c.isSetOrganisation() else None
),
"email": c.getEmail() if c.isSetEmail() else None,
}
)
Expand Down
1 change: 0 additions & 1 deletion src/cobra/io/web/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Provide functionality to access remote model repositories."""


from .abstract_model_repository import AbstractModelRepository
from .bigg_models_repository import BiGGModels
from .biomodels_repository import BioModels
Expand Down
1 change: 0 additions & 1 deletion src/cobra/io/web/abstract_model_repository.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Provide an abstract base class that describes a remote model repository."""


from abc import ABC, abstractmethod
from typing import Union

Expand Down
1 change: 0 additions & 1 deletion src/cobra/io/web/bigg_models_repository.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Provide a concrete implementation of the BioModels repository interface."""


from io import BytesIO

import httpx
Expand Down
1 change: 0 additions & 1 deletion src/cobra/io/web/biomodels_repository.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Provide functions for loading metabolic models over the wire."""


import gzip
from io import BytesIO
from typing import List
Expand Down
1 change: 0 additions & 1 deletion src/cobra/io/web/cobrapy_repository.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Provide functions for loading metabolic models from local package data."""


import importlib_resources

import cobra.data
Expand Down
1 change: 0 additions & 1 deletion src/cobra/io/web/load.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Provide a function ``load_model`` to access remote model repositories."""


import gzip
import logging
from typing import TYPE_CHECKING, Iterable
Expand Down
1 change: 1 addition & 0 deletions src/cobra/manipulation/delete.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Provide functions for pruning reactions, metabolites and genes."""

import logging
from ast import And, BoolOp, Name, NodeTransformer
from functools import partial
Expand Down
2 changes: 1 addition & 1 deletion src/cobra/sampling/achr.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def __init__(
thinning: int = 100,
nproj: Optional[int] = None,
seed: Optional[int] = None,
**kwargs
**kwargs,
) -> None:
"""Initialize a new ACHRSampler."""
super().__init__(model, thinning, nproj=nproj, seed=seed, **kwargs)
Expand Down
5 changes: 2 additions & 3 deletions src/cobra/sampling/optgp.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Provide the OptGP sampler class and helper functions."""


from typing import TYPE_CHECKING, Dict, Optional, Tuple

import numpy as np
Expand Down Expand Up @@ -110,10 +109,10 @@ def __init__(
processes: Optional[int] = None,
nproj: Optional[int] = None,
seed: Optional[int] = None,
**kwargs
**kwargs,
) -> None:
"""Initialize a new OptGPSampler."""
super().__init__(model, thinning, nproj=nproj, seed=seed, *kwargs)
super().__init__(model, thinning, nproj=nproj, seed=seed, **kwargs)
self.generate_fva_warmup()

if processes is None:
Expand Down
1 change: 0 additions & 1 deletion src/cobra/summary/metabolite_summary.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Provide the metabolite summary class."""


import logging
from operator import attrgetter
from textwrap import shorten
Expand Down
1 change: 0 additions & 1 deletion src/cobra/summary/model_summary.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Provide the model summary class."""


import logging
from operator import attrgetter
from typing import TYPE_CHECKING, Dict, List, Optional, Union
Expand Down
1 change: 0 additions & 1 deletion src/cobra/summary/reaction_summary.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Provide the reaction summary class."""


import logging
from textwrap import dedent, shorten
from typing import TYPE_CHECKING, Optional, Union
Expand Down
1 change: 0 additions & 1 deletion src/cobra/summary/summary.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Provide the abstract base summary class."""


import logging
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, Optional, Union
Expand Down
3 changes: 1 addition & 2 deletions src/cobra/util/process_pool.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Provide a process pool with enhanced performance on Windows."""


import multiprocessing
import os
import pickle
Expand Down Expand Up @@ -30,7 +29,7 @@ def __init__(
initializer: Optional[Callable] = None,
initargs: Tuple = (),
maxtasksperchild: Optional[int] = None,
**kwargs
**kwargs,
) -> None:
"""
Initialize a process pool.
Expand Down
1 change: 0 additions & 1 deletion tests/test_core/test_gene.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Test functions of gene.py ."""


from cobra.core import Model


Expand Down
1 change: 0 additions & 1 deletion tests/test_core/test_group.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Test functions of group via model.py."""


import pytest

from cobra import Model
Expand Down
1 change: 0 additions & 1 deletion tests/test_flux_analysis/test_deletion.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Test functionalities of reaction and gene deletions."""


import math
import os
from typing import Callable, List
Expand Down
1 change: 0 additions & 1 deletion tests/test_medium/test_boundary_types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Test functionalities of boundary type detection functions."""


import pytest

from cobra.core import Metabolite, Model, Reaction
Expand Down
1 change: 0 additions & 1 deletion tests/test_summary/test_metabolite_summary.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Unit test the MetaboliteSummary class."""


import pytest

from cobra.flux_analysis import flux_variability_analysis, pfba
Expand Down
1 change: 0 additions & 1 deletion tests/test_summary/test_model_summary.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Unit test the model summary."""


import pytest

from cobra.flux_analysis import flux_variability_analysis, pfba
Expand Down
1 change: 0 additions & 1 deletion tests/test_summary/test_reaction_summary.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Unit test the ReactionSummary class."""


import pytest

from cobra.flux_analysis import flux_variability_analysis, pfba
Expand Down
1 change: 0 additions & 1 deletion tests/test_util/test_process_pool.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Test the behaviour of the ProcessPool class."""


import os
from typing import Iterable, Tuple

Expand Down

0 comments on commit 893593d

Please sign in to comment.