Skip to content

Commit

Permalink
use getattr
Browse files Browse the repository at this point in the history
  • Loading branch information
dilpath committed Jul 1, 2024
1 parent 22e1bc2 commit be09065
Show file tree
Hide file tree
Showing 16 changed files with 8 additions and 164 deletions.
5 changes: 0 additions & 5 deletions petab/C.py

This file was deleted.

69 changes: 7 additions & 62 deletions petab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,81 +2,26 @@
PEtab global
============
.. warning::
All functions in here are deprecated. Use the respective functions from
:mod:`petab.v1` instead.
Attributes:
ENV_NUM_THREADS:
Name of environment variable to set number of threads or processes
PEtab should use for operations that can be performed in parallel.
By default, all operations are performed sequentially.
"""
import functools
import inspect
import sys
import warnings
import importlib
from warnings import warn

# deprecated imports
from petab.v1 import * # noqa: F403, F401, E402

from .v1.format_version import __format_version__ # noqa: F401, E402

# __all__ = [
# 'ENV_NUM_THREADS',
# ]

ENV_NUM_THREADS = "PETAB_NUM_THREADS"


class DeprecatedProblem(Problem):
deprecated_use = True


Problem = DeprecatedProblem

def __getattr__(name):
if attr := globals().get(name):
return attr

def _deprecated_v1(func):
"""Decorator for deprecation warnings for functions."""

@functools.wraps(func)
def new_func(*args, **kwargs):
warnings.warn(
f"petab.{func.__name__} is deprecated, "
f"please use petab.v1.{func.__name__} instead.",
category=DeprecationWarning,
stacklevel=2,
)
return func(*args, **kwargs)

return new_func


def _deprecated_import_v1(module_name: str):
"""Decorator for deprecation warnings for modules."""
warn(
f"The '{module_name}' module is deprecated and will be removed "
f"in the next major release. Please use "
f"'petab.v1.{module_name.removeprefix('petab.')}' "
"instead.",
f"Accessing `petab.{name}` is deprecated and will be removed in "
f"the next major release. Please use `petab.v1.{name}` instead.",
DeprecationWarning,
stacklevel=3,
)


__all__ = [
x
for x in dir(sys.modules[__name__])
if not x.startswith("_")
and x not in {"sys", "warnings", "functools", "warn", "inspect"}
]


# apply decorator to all functions in the module
for name in __all__:
obj = globals().get(name)
if callable(obj) and inspect.isfunction(obj):
globals()[name] = _deprecated_v1(obj)
del name, obj
return getattr(importlib.import_module("petab.v1"), name)
7 changes: 0 additions & 7 deletions petab/calculate.py

This file was deleted.

7 changes: 0 additions & 7 deletions petab/composite_problem.py

This file was deleted.

8 changes: 0 additions & 8 deletions petab/conditions.py

This file was deleted.

7 changes: 0 additions & 7 deletions petab/core.py

This file was deleted.

9 changes: 0 additions & 9 deletions petab/lint.py

This file was deleted.

7 changes: 0 additions & 7 deletions petab/mapping.py

This file was deleted.

7 changes: 0 additions & 7 deletions petab/measurements.py

This file was deleted.

8 changes: 0 additions & 8 deletions petab/observables.py

This file was deleted.

7 changes: 0 additions & 7 deletions petab/parameter_mapping.py

This file was deleted.

7 changes: 0 additions & 7 deletions petab/parameters.py

This file was deleted.

7 changes: 0 additions & 7 deletions petab/simplify.py

This file was deleted.

8 changes: 0 additions & 8 deletions petab/simulate.py

This file was deleted.

2 changes: 1 addition & 1 deletion petab/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from pathlib import Path

from petab.C import FORMAT_VERSION
from petab.v1 import Problem as V1Problem
from petab.v1.C import FORMAT_VERSION
from petab.v1.yaml import load_yaml
from petab.v2 import Problem as V2Problem

Expand Down
7 changes: 0 additions & 7 deletions petab/yaml.py

This file was deleted.

0 comments on commit be09065

Please sign in to comment.