Skip to content

Commit

Permalink
Set up stubs for scipy and scikit-image as installable package (vreut…
Browse files Browse the repository at this point in the history
…er#1)

* first-pass at basic installable

* need stubs suffix as hyphen to point to real package, and to be detected as stubs-only

* try removing added files that shouldn't really be needed

* bundle scipy and skimage stubs for installation per PEP 561
  • Loading branch information
vreuter authored Mar 16, 2024
1 parent e328827 commit c0b6f06
Show file tree
Hide file tree
Showing 102 changed files with 3,100 additions and 1 deletion.
37 changes: 36 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
[tool.poetry]
name = "python-type-stubs"
version = "0.1dev"
description = "A set of type stubs for popular Python packages. These are works in progress from the Microsoft Python team and others, with the intent that they are contributed to typeshed or to the associated packages once sufficiently complete."
authors = [
"microsoft",
"Vince Reuter <[email protected]>",
]
readme = "README.md"
license = "MIT"
repository = "https://github.com/gerlichlab/python-type-stubs"
classifiers = [
"Development Status :: 1 - Planning",
"Programming Language :: Python",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Software Development",
"Topic :: Software Development :: Build Tools",
"Topic :: Software Development :: Quality Assurance",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Utilities",
]
packages = [
{ include = "scipy-stubs", from = "stubs" },
{ include = "skimage-stubs", from = "stub-dist" },
]

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.black]
line_length = 130
target_version = ["py37"]
Expand Down Expand Up @@ -85,4 +120,4 @@ strict_equality = true
# Configuring error messages
show_error_context = false
show_column_numbers = false
show_error_codes = true
show_error_codes = true
24 changes: 24 additions & 0 deletions stub-dist/skimage-stubs/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
__version__: str = ...

submodules: list = ...

from ._shared.version_requirements import ensure_python_version as ensure_python_version

from ._shared import lazy as lazy

__getattr__, __lazy_dir__, _ = ...

def __dir__(): ...

# Logic for checking for improper install and importing while in the source
# tree when package has not been installed inplace.
# Code adapted from scikit-learn's __check_build module.
_INPLACE_MSG: str = ...

_STANDARD_MSG: str = ...

def _raise_build_error(e): ...

from skimage._shared.tester import PytestTester as PytestTester # noqa

test = ...
Empty file.
3 changes: 3 additions & 0 deletions stub-dist/skimage-stubs/_shared/_dependency_checks.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .version_requirements import is_installed

has_mpl = ...
9 changes: 9 additions & 0 deletions stub-dist/skimage-stubs/_shared/_geometry.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
__all__ = ["polygon_clip", "polygon_area"]

import numpy as np

from .version_requirements import require

@require("matplotlib", ">=3.0.3")
def polygon_clip(rp, cp, r0, c0, r1, c1): ...
def polygon_area(pr, pc) -> float: ...
6 changes: 6 additions & 0 deletions stub-dist/skimage-stubs/_shared/_tempfile.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from tempfile import NamedTemporaryFile
from contextlib import contextmanager
import os

@contextmanager
def temporary_file(suffix: str = ""): ...
17 changes: 17 additions & 0 deletions stub-dist/skimage-stubs/_shared/_warnings.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from contextlib import contextmanager
import sys
import warnings
import re
import functools
import os

__all__ = ["all_warnings", "expected_warnings", "warn"]

# A version of `warnings.warn` with a default stacklevel of 2.
# functool is used so as not to increase the call stack accidentally
warn = ...

@contextmanager
def all_warnings(): ...
@contextmanager
def expected_warnings(matching): ...
13 changes: 13 additions & 0 deletions stub-dist/skimage-stubs/_shared/coord.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import numpy as np
from scipy.spatial import distance

def _ensure_spacing(coord, spacing, p_norm, max_out): ...
def ensure_spacing(
coords,
spacing: float = 1,
p_norm: float = ...,
min_split_size: int = 50,
max_out: int | None = None,
*,
max_split_size: int = 2000
): ...
24 changes: 24 additions & 0 deletions stub-dist/skimage-stubs/_shared/filters.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from skimage._typing import Scalar
from numpy.typing import ArrayLike, NDArray
from typing import Literal
from collections.abc import Iterable

import numpy as np
from scipy import ndimage as ndi

from .._shared import utils
from .._shared.utils import _supported_float_type, convert_to_float, warn

@utils.deprecate_multichannel_kwarg(multichannel_position=5)
def gaussian(
image: ArrayLike,
sigma=1,
output: ArrayLike | None = None,
mode: Literal["reflect", "constant", "nearest", "mirror", "wrap"] = "nearest",
cval: Scalar = 0,
multichannel=None,
preserve_range: bool = False,
truncate: float = 4.0,
*,
channel_axis: int | None = None
) -> NDArray: ...
12 changes: 12 additions & 0 deletions stub-dist/skimage-stubs/_shared/lazy.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from typing import Mapping
import importlib
import importlib.util
import os
import sys

def attach(
package_name: str,
submodules: set | None = None,
submod_attrs: Mapping | None = None,
): ...
def load(fullname: str): ...
7 changes: 7 additions & 0 deletions stub-dist/skimage-stubs/_shared/setup.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env python

import os

base_path = ...

def configuration(parent_package="", top_path=None): ...
19 changes: 19 additions & 0 deletions stub-dist/skimage-stubs/_shared/tester.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from numpy.typing import ArrayLike
from typing import Literal
import os
import sys

def _show_skimage_info(): ...

class PytestTester(object):
def __init__(self, module_name): ...
def __call__(
self,
label: Literal["fast", "full"] = "fast",
verbose: int = 1,
extra_argv: ArrayLike | None = None,
doctests: bool = False,
coverage: bool = False,
durations: int = ...,
tests=None,
) -> bool: ...
55 changes: 55 additions & 0 deletions stub-dist/skimage-stubs/_shared/testing.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from numpy.typing import ArrayLike

import os
import re
import struct
import threading
import functools
from tempfile import NamedTemporaryFile

import numpy as np
from numpy import testing
from numpy.testing import (
assert_array_equal,
assert_array_almost_equal,
assert_array_less,
assert_array_almost_equal_nulp,
assert_equal,
TestCase,
assert_allclose,
assert_almost_equal,
assert_,
assert_warns,
assert_no_warnings,
)

import warnings

from ..data._fetchers import _fetch
from ._warnings import expected_warnings

SKIP_RE = ...

skipif = ...
xfail = ...
parametrize = ...
raises = ...
fixture = ...

# true if python is running in 32bit mode
# Calculate the size of a void * pointer in bits
# https://docs.python.org/3/library/struct.html
arch32 = ...

_error_on_warnings = ...

def assert_less(a, b, msg=None): ...
def assert_greater(a, b, msg=None): ...
def doctest_skip_parser(func): ...
def roundtrip(image, plugin, suffix): ...
def color_check(plugin, fmt="png"): ...
def mono_check(plugin, fmt="png"): ...
def setup_test(): ...
def teardown_test(): ...
def fetch(data_filename): ...
def test_parallel(num_threads: int = 2, warnings_matching: ArrayLike | None = None): ...
110 changes: 110 additions & 0 deletions stub-dist/skimage-stubs/_shared/utils.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
from collections.abc import Iterable
from numpy.typing import ArrayLike, NDArray
from typing import Any, Mapping, Literal
import inspect
import functools
import sys
import warnings
from collections.abc import Iterable

import numpy as np
import scipy
from numpy.lib import NumpyVersion

from ._warnings import all_warnings, warn

__all__ = [
"deprecated",
"get_bound_method_class",
"all_warnings",
"safe_as_int",
"check_shape_equality",
"check_nD",
"warn",
"reshape_nd",
"identity",
"slice_at_axis",
]

class skimage_deprecation(Warning):
pass

def _get_stack_rank(func): ...
def _is_wrapped(func): ...
def _get_stack_length(func): ...

class _DecoratorBaseClass:

_stack_length: dict = ...

def get_stack_length(self, func): ...

class change_default_value(_DecoratorBaseClass):
def __init__(
self,
arg_name: str,
*,
new_value: Any,
changed_version: str,
warning_msg: str | None = None
): ...
def __call__(self, func): ...

class remove_arg(_DecoratorBaseClass):
def __init__(
self, arg_name: str, *, changed_version: str, help_msg: str | None = None
): ...
def __call__(self, func): ...

def docstring_add_deprecated(
func, kwarg_mapping: Mapping, deprecated_version: str
) -> str: ...

class deprecate_kwarg(_DecoratorBaseClass):
def __init__(
self,
kwarg_mapping: Mapping,
deprecated_version: str,
warning_msg: str | None = None,
removed_version: str | None = None,
): ...
def __call__(self, func): ...

class deprecate_multichannel_kwarg(deprecate_kwarg):
def __init__(self, removed_version: str = "1.0", multichannel_position=None): ...
def __call__(self, func): ...

class channel_as_last_axis:
def __init__(
self,
channel_arg_positions: tuple[int, ...] = ...,
channel_kwarg_names: tuple[str, ...] = ...,
multichannel_output: bool = True,
): ...
def __call__(self, func): ...

class deprecated:
def __init__(
self,
alt_func: str | None = None,
behavior: Literal["warn", "raise"] = "warn",
removed_version: str | None = None,
): ...
def __call__(self, func): ...

def get_bound_method_class(m): ...
def safe_as_int(val, atol: float = 1e-3): ...
def check_shape_equality(im1, im2): ...
def slice_at_axis(sl, axis: int): ...
def reshape_nd(arr, ndim: int, dim: int): ...
def check_nD(array: ArrayLike, ndim: int | Iterable[int], arg_name: str = "image"): ...
def convert_to_float(image: NDArray, preserve_range: bool) -> NDArray: ...
def _validate_interpolation_order(image_dtype, order): ...
def _to_np_mode(mode): ...
def _to_ndimage_mode(mode): ...
def _fix_ndimage_mode(mode): ...

new_float_type: dict = ...

def _supported_float_type(input_dtype, allow_complex=False): ...
def identity(image, *args, **kwargs): ...
10 changes: 10 additions & 0 deletions stub-dist/skimage-stubs/_shared/version_requirements.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import sys

from packaging import version as _version

def ensure_python_version(min_version): ...
def _check_version(actver, version, cmp_op): ...
def get_module_version(module_name): ...
def is_installed(name: str, version: str | None = None) -> bool: ...
def require(name: str, version: str | None = None): ...
def get_module(module_name: str, version: str | None = None): ...
25 changes: 25 additions & 0 deletions stub-dist/skimage-stubs/_typing.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import decimal
import io
import numpy.typing
import pandas as pd

Decimal = decimal.Decimal
PythonScalar = str | int | float | bool

ArrayLike = numpy.typing.ArrayLike
FileLike = io.IOBase
PathLike = str

PandasScalar = pd.Period | pd.Timestamp | pd.Timedelta | pd.Interval
Scalar = PythonScalar | PandasScalar

Color = tuple[float, float, float] | str

__all__ = [
"ArrayLike",
"Color",
"Decimal",
"FileLike",
"PathLike",
"Scalar",
]
3 changes: 3 additions & 0 deletions stub-dist/skimage-stubs/data/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .._shared import lazy as lazy

__getattr__, __dir__, __all__ = ...
Loading

0 comments on commit c0b6f06

Please sign in to comment.