GithubHelp home page GithubHelp logo

gramster / docs2stubs Goto Github PK

View Code? Open in Web Editor NEW
4.0 4.0 2.0 551 KB

A tool to generate stubs for Python packages using numpydoc-format docstrings and monkeytype traces

License: MIT License

Python 99.50% Shell 0.50%

docs2stubs's People

Contributors

gramster avatar lagru avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

danibene lagru

docs2stubs's Issues

How to install

Hi! Thank you very much for developing this and making it available. I had a question concerning the installation instructions in the README:

docs2stubs/README.md

Lines 6 to 10 in 9d238f1

See CONTRIBUTING.md for build instructions, or install from PyPI with:
```
python -m pip install docs2stubs
```

When trying to run the command, I got the following error:

python -m pip install docs2stubs

ERROR: Could not find a version that satisfies the requirement docs2stubs (from versions: none)
ERROR: No matching distribution found for docs2stubs

I also wasn't able to find the project on https://pypi.org/ searching docs2stubs. Do you have any suggestions on how to proceed with the installation?

Errors when running docs2stubs on scikit-image

Adding context here again: At scikit-image we are currently looking for a solution to add and maintain stubs and want to take the type descriptions in our docstrings into account. Long-term we'd like to have one source of truth, so generating stubs from docstrings seem like a natural approach. However, up until now I've had trouble getting docs2stubs to run.

I've tried invoking docs2stubs in several ways on a local development version of skimage but usually get a traceback:

docs2stubs analyze package skimage

Traceback (most recent call last):
File "/home/lg/.local/lib/micromamba/envs/test-docs2stubs/lib/python3.11/site-packages/docs2stubs/analyzing_transformer.py", line 215, in _analyze
cstree.visit(patcher)
File "/home/lg/.local/lib/micromamba/envs/test-docs2stubs/lib/python3.11/site-packages/libcst/_nodes/module.py", line 89, in visit
result = super(Module, self).visit(visitor)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/lg/.local/lib/micromamba/envs/test-docs2stubs/lib/python3.11/site-packages/libcst/_nodes/base.py", line 227, in visit
_CSTNodeSelfT, self._visit_and_replace_children(visitor)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/lg/.local/lib/micromamba/envs/test-docs2stubs/lib/python3.11/site-packages/libcst/_nodes/module.py", line 74, in _visit_and_replace_children
body=visit_body_sequence(self, "body", self.body, visitor),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/lg/.local/lib/micromamba/envs/test-docs2stubs/lib/python3.11/site-packages/libcst/_nodes/internal.py", line 227, in visit_body_sequence
return tuple(visit_body_iterable(parent, fieldname, children, visitor))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/lg/.local/lib/micromamba/envs/test-docs2stubs/lib/python3.11/site-packages/libcst/_nodes/internal.py", line 193, in visit_body_iterable
new_child = child.visit(visitor)
^^^^^^^^^^^^^^^^^^^^
File "/home/lg/.local/lib/micromamba/envs/test-docs2stubs/lib/python3.11/site-packages/libcst/_nodes/base.py", line 218, in visit
should_visit_children = visitor.on_visit(self)
^^^^^^^^^^^^^^^^^^^^^^
File "/home/lg/.local/lib/micromamba/envs/test-docs2stubs/lib/python3.11/site-packages/libcst/_visitors.py", line 44, in on_visit
retval = visit_func(node)
^^^^^^^^^^^^^^^^
File "/home/lg/.local/lib/micromamba/envs/test-docs2stubs/lib/python3.11/site-packages/docs2stubs/analyzing_transformer.py", line 156, in visit_FunctionDef
self._trace_sigs[context] = get_toplevel_function_signature(self._modname, name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/lg/.local/lib/micromamba/envs/test-docs2stubs/lib/python3.11/site-packages/docs2stubs/traces.py", line 186, in get_toplevel_function_signature
stubs = _get_module_stubs(_dbpath, _pkg, module)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/lg/.local/lib/micromamba/envs/test-docs2stubs/lib/python3.11/site-packages/docs2stubs/traces.py", line 174, in _get_module_stubs
raise Exception("get_module_traces called before init_trace_loader")
Exception: get_module_traces called before init_trace_loader

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/lg/.local/lib/micromamba/envs/test-docs2stubs/bin/docs2stubs", line 8, in <module>
sys.exit(main())
^^^^^^
File "/home/lg/.local/lib/micromamba/envs/test-docs2stubs/lib/python3.11/site-packages/docs2stubs/__init__.py", line 88, in main
analyze_module(n, include_submodules=include_submodules, dump_all=dump_all)
File "/home/lg/.local/lib/micromamba/envs/test-docs2stubs/lib/python3.11/site-packages/docs2stubs/analyzing_transformer.py", line 278, in analyze_module
if process_module("Analyzing", m, state,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/lg/.local/lib/micromamba/envs/test-docs2stubs/lib/python3.11/site-packages/docs2stubs/utils.py", line 164, in process_module
result = processor(mod, m, file, source, state, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/lg/.local/lib/micromamba/envs/test-docs2stubs/lib/python3.11/site-packages/docs2stubs/analyzing_transformer.py", line 217, in _analyze
raise Exception(f"Failed to analyze file: {fname}: {e}")
Exception: Failed to analyze file: /home/lg/.local/lib/micromamba/envs/test-docs2stubs/lib/python3.11/site-packages/skimage/__init__.py: get_module_traces called before init_trace_loader

docs2stubs stub package skimage

Traceback (most recent call last):
File "/home/lg/.local/lib/micromamba/envs/test-docs2stubs/lib/python3.11/site-packages/docs2stubs/analyzing_transformer.py", line 215, in _analyze
cstree.visit(patcher)
File "/home/lg/.local/lib/micromamba/envs/test-docs2stubs/lib/python3.11/site-packages/libcst/_nodes/module.py", line 89, in visit
result = super(Module, self).visit(visitor)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/lg/.local/lib/micromamba/envs/test-docs2stubs/lib/python3.11/site-packages/libcst/_nodes/base.py", line 227, in visit
_CSTNodeSelfT, self._visit_and_replace_children(visitor)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/lg/.local/lib/micromamba/envs/test-docs2stubs/lib/python3.11/site-packages/libcst/_nodes/module.py", line 74, in _visit_and_replace_children
body=visit_body_sequence(self, "body", self.body, visitor),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/lg/.local/lib/micromamba/envs/test-docs2stubs/lib/python3.11/site-packages/libcst/_nodes/internal.py", line 227, in visit_body_sequence
return tuple(visit_body_iterable(parent, fieldname, children, visitor))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/lg/.local/lib/micromamba/envs/test-docs2stubs/lib/python3.11/site-packages/libcst/_nodes/internal.py", line 193, in visit_body_iterable
new_child = child.visit(visitor)
^^^^^^^^^^^^^^^^^^^^
File "/home/lg/.local/lib/micromamba/envs/test-docs2stubs/lib/python3.11/site-packages/libcst/_nodes/base.py", line 218, in visit
should_visit_children = visitor.on_visit(self)
^^^^^^^^^^^^^^^^^^^^^^
File "/home/lg/.local/lib/micromamba/envs/test-docs2stubs/lib/python3.11/site-packages/libcst/_visitors.py", line 44, in on_visit
retval = visit_func(node)
^^^^^^^^^^^^^^^^
File "/home/lg/.local/lib/micromamba/envs/test-docs2stubs/lib/python3.11/site-packages/docs2stubs/analyzing_transformer.py", line 156, in visit_FunctionDef
self._trace_sigs[context] = get_toplevel_function_signature(self._modname, name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/lg/.local/lib/micromamba/envs/test-docs2stubs/lib/python3.11/site-packages/docs2stubs/traces.py", line 186, in get_toplevel_function_signature
stubs = _get_module_stubs(_dbpath, _pkg, module)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/lg/.local/lib/micromamba/envs/test-docs2stubs/lib/python3.11/site-packages/docs2stubs/traces.py", line 177, in _get_module_stubs
traces = _load_module_traces(f'{dbpath}/{pkg}.sqlite3', module, sys.stderr)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/lg/.local/lib/micromamba/envs/test-docs2stubs/lib/python3.11/site-packages/docs2stubs/traces.py", line 142, in _load_module_traces
thunks = SQLiteDedupStore.make_store(db).filter(module)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/lg/.local/lib/micromamba/envs/test-docs2stubs/lib/python3.11/site-packages/docs2stubs/traces.py", line 93, in make_store
conn = sqlite3.connect(connection_string)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sqlite3.OperationalError: unable to open database file

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/lg/.local/lib/micromamba/envs/test-docs2stubs/bin/docs2stubs", line 8, in <module>
sys.exit(main())
^^^^^^
File "/home/lg/.local/lib/micromamba/envs/test-docs2stubs/lib/python3.11/site-packages/docs2stubs/__init__.py", line 94, in main
stub_module(n, include_submodules=include_submodules, \
File "/home/lg/.local/lib/micromamba/envs/test-docs2stubs/lib/python3.11/site-packages/docs2stubs/stubbing_transformer.py", line 756, in stub_module
state = analyze_module(m, include_submodules=include_submodules)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/lg/.local/lib/micromamba/envs/test-docs2stubs/lib/python3.11/site-packages/docs2stubs/analyzing_transformer.py", line 278, in analyze_module
if process_module("Analyzing", m, state,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/lg/.local/lib/micromamba/envs/test-docs2stubs/lib/python3.11/site-packages/docs2stubs/utils.py", line 164, in process_module
result = processor(mod, m, file, source, state, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/lg/.local/lib/micromamba/envs/test-docs2stubs/lib/python3.11/site-packages/docs2stubs/analyzing_transformer.py", line 217, in _analyze
raise Exception(f"Failed to analyze file: {fname}: {e}")
Exception: Failed to analyze file: /home/lg/.local/lib/micromamba/envs/test-docs2stubs/lib/python3.11/site-packages/skimage/__init__.py: unable to open database file

I'm using an environment with Python 3.11.

I'd love to try this tools on scikit-image and I'd be grateful for your insights. Perhaps I am missing something.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.