Skip to content

Commit

Permalink
Minor shuffle around and cleanup. (#365)
Browse files Browse the repository at this point in the history
This just makes #363 a  bit easier to read.
  • Loading branch information
Carreau authored Dec 25, 2023
2 parents 9995fee + 32548d7 commit 1873f10
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 44 deletions.
62 changes: 32 additions & 30 deletions examples/numpy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,41 @@
module = 'numpy'

exclude = [
'numpy:tensordot',
'numpy:tensordot',
# See https://github.com/jupyter/papyri/issues/361'
'numpy.ma.core:MaskedArray.resize',
]

execute_exclude_patterns = [
'numpy._',
'numpy.testing._priv',
'numpy.errstate',
'numpy.seterr',
'numpy.bincount',
'numpy.core._multiarray_umath.bincount',
'numpy.core._multiarray_umath.datetime_as_string',
'numpy.core._multiarray_umath.normalize_axis_index',
'numpy.core._multiarray_umath.shares_memory',
'numpy.datetime_as_string',
'numpy.shares_memory',
'numpy.squeeze',
'numpy.average',
'numpy.ctypeslib',
'numpy.append',
'numpy.ma.core',
'numpy.core.umath_tests',
# try to create a pager that waits for input
'numpy.lookfor',
# write directly to stdout
'numpy.info',
# Misc
'numpy.distutils',
'numpy.char.multiply',
'numpy.polynomial.chebyshev.chebinterpolate',
'numpy.lib.npyio._read',
'numpy.polynomial._polybase:ABCPolyBase',
'numpy.distutils.misc_util:Configuration.__init__',
'numpy.ma.core:MaskedArray.resize', # First line of docstring is a directive; breaks parsing
'numpy._',
'numpy.testing._priv',
'numpy.errstate',
'numpy.seterr',
'numpy.bincount',
'numpy.core._multiarray_umath.bincount',
'numpy.core._multiarray_umath.datetime_as_string',
'numpy.core._multiarray_umath.normalize_axis_index',
'numpy.core._multiarray_umath.shares_memory',
'numpy.datetime_as_string',
'numpy.shares_memory',
'numpy.squeeze',
'numpy.average',
'numpy.ctypeslib',
'numpy.append',
'numpy.ma.core',
'numpy.core.umath_tests',
# try to create a pager that waits for input
'numpy.lookfor',
# write directly to stdout
'numpy.info',
# Misc
'numpy.distutils',
'numpy.char.multiply',
'numpy.polynomial.chebyshev.chebinterpolate',
'numpy.lib.npyio._read',
'numpy.polynomial._polybase:ABCPolyBase',
'numpy.distutils.misc_util:Configuration.__init__',
'numpy.ma.core:MaskedArray.resize', # First line of docstring is a directive; breaks parsing
]

submodules = [
Expand Down
15 changes: 1 addition & 14 deletions papyri/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import dataclasses
import datetime
import importlib
import inspect
import json
import logging
Expand Down Expand Up @@ -80,6 +79,7 @@
full_qual,
pos_to_nl,
progress,
obj_from_qualname,
)
from .vref import NumpyDocString

Expand Down Expand Up @@ -189,19 +189,6 @@ def _jedi_set_cache(text, value):
_cache.write_text(json.dumps(value))


def obj_from_qualname(name):
mod_name, sep, objs = name.partition(":")
module = importlib.import_module(mod_name)
if not sep:
return module
else:
obj = module
parts = objs.split(".")
for p in parts:
obj = getattr(obj, p)
return obj


def parse_script(
script: str, ns: Dict, prev, config, *, where=None
) -> Optional[List[Tuple[str, Optional[str]]]]:
Expand Down
14 changes: 14 additions & 0 deletions papyri/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import time
import typing
import importlib
from datetime import timedelta
from textwrap import dedent
from typing import Tuple, NewType
Expand Down Expand Up @@ -226,3 +227,16 @@ def pos_to_nl(script: str, pos: int) -> Tuple[int, int]:
else:
return ln, rest
raise RuntimeError


def obj_from_qualname(name):
mod_name, sep, objs = name.partition(":")
module = importlib.import_module(mod_name)
if not sep:
return module
else:
obj = module
parts = objs.split(".")
for p in parts:
obj = getattr(obj, p)
return obj

0 comments on commit 1873f10

Please sign in to comment.