Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fixed the stubs generator #108

Merged
merged 18 commits into from
Apr 25, 2024
Merged

Conversation

Masara
Copy link
Contributor

@Masara Masara commented Apr 11, 2024

Closes #80

Summary of Changes

Fixed the stub generator, it should now run with the Library project.

To run the script, use the following command:
safe-ds-stubgen -p "Library" -o "path/to/out" -nc -s "path/to/Library/src" --docstyle NUMPYDOC

@Masara Masara linked an issue Apr 11, 2024 that may be closed by this pull request
@Masara
Copy link
Contributor Author

Masara commented Apr 11, 2024

@lars-reimann The src.safeds.data.tabular.containers._column.Column.all, src.safeds.data.tabular.containers._column.Column.any and src.safeds.data.tabular.containers._column.Column.none methods have Callable[[T], bool]) as type for the predicate parameter. The type is written wrong b/c of the ) at the end of the type.

# Conflicts:
#	src/safeds_stubgen/docstring_parsing/_docstring_parser.py
Copy link

github-actions bot commented Apr 11, 2024

🦙 MegaLinter status: ✅ SUCCESS

Descriptor Linter Files Fixed Errors Elapsed time
✅ MARKDOWN markdown-link-check 1 0 1.82s
✅ PYTHON black 14 0 0 1.54s
✅ PYTHON mypy 14 0 6.42s
✅ PYTHON ruff 14 0 0 0.05s
✅ REPOSITORY git_diff yes no 0.03s

See detailed report in MegaLinter reports
Set VALIDATE_ALL_CODEBASE: true in mega-linter.yml to validate all sources, not only the diff

MegaLinter is graciously provided by OX Security

Copy link

codecov bot commented Apr 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.53%. Comparing base (6665186) to head (e610cd4).
Report is 44 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #108      +/-   ##
==========================================
+ Coverage   99.30%   99.53%   +0.22%     
==========================================
  Files          22       22              
  Lines        2291     2341      +50     
==========================================
+ Hits         2275     2330      +55     
+ Misses         16       11       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lars-reimann
Copy link
Member

lars-reimann commented Apr 11, 2024

Feel free to report that in the library repo.

@Masara Masara force-pushed the 80-cannot-create-stubs-for-safe-ds branch from d774b5c to 86ae2b8 Compare April 11, 2024 21:34
@Masara Masara marked this pull request as ready for review April 11, 2024 21:34
@Masara Masara requested a review from a team as a code owner April 11, 2024 21:34
@Masara
Copy link
Contributor Author

Masara commented Apr 13, 2024

Could you merge this next? I need the fixes here for the remaining issue.

@lars-reimann
Copy link
Member

lars-reimann commented Apr 17, 2024

I'm still getting this error for Safe-DS/Library@e01ad89:

Traceback (most recent call last):
  File "C:\Users\Lars\AppData\Local\pypoetry\Cache\virtualenvs\safe-ds-stubgen-VELKLkPa-py3.12\Scripts\\safe-ds-stubgen", line 6, in <module>
    sys.exit(main())
             ^^^^^^
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\main.py", line 14, in main
    cli()
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\cli\_cli.py", line 20, in cli
    _run_api_command(args.package, args.src, args.out, args.docstyle, args.testrun, args.naming_convert)
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\cli\_cli.py", line 96, in _run_api_command
    api = get_api(package, src_dir_path, docstring_style, is_test_run)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_get_api.py", line 72, in get_api
    walker.walk(tree=tree)
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_walker.py", line 30, in walk
    self.__walk(tree, set())
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_walker.py", line 68, in __walk
    self.__walk(child_node, visited_nodes)
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_walker.py", line 42, in __walk
    self.__enter(node)
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_walker.py", line 74, in __enter
    method(node)
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_visitor.py", line 264, in enter_funcdef
    results = self._parse_results(node, function_id, result_docstrings)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_visitor.py", line 446, in _parse_results
    ret_type = self.mypy_type_to_abstract_type(node_ret_type, unanalyzed_ret_type)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_visitor.py", line 1004, in mypy_type_to_abstract_type
    raise ValueError("Unexpected type.")  # pragma: no cover
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: Unexpected type.

… exceptions; removed the -p argument since we can get the package name through the source path; adjusted how aliases are searched for
@Masara
Copy link
Contributor Author

Masara commented Apr 19, 2024

@lars-reimann I removed the raises like you said and instead added the unknown type. I also removed the -p (package name) argument, since we don't really need it. Could you check again if it works for you?

@Masara
Copy link
Contributor Author

Masara commented Apr 19, 2024

@lars-reimann Could you also check the linter error?

❌ Linted [MARKDOWN] files with [markdown-link-check]: Found 1 error(s) - (3.07s) (expand for details)
  - Using [markdown-link-check v3.11.2] https://megalinter.io/7.10.0/descriptors/markdown_markdown_link_check
  - MegaLinter key: [MARKDOWN_MARKDOWN_LINK_CHECK]
  - Rules config: [/github/workspace/.github/linters/.markdown-link-check.json]
  - Number of files analyzed: [1]
  --Error detail:
  (node:56) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
  (Use `node --trace-deprecation ...` to show where the warning was created)
  
    ERROR: 1 dead links found in docs/README.md !
    [✖] https://dsl.safeds.com/en/stable/language/stub-language/ → Status: 404

@lars-reimann
Copy link
Member

@Masara You can replace the link with https://dsl.safeds.com/en/stable/stub-language/.

@Masara
Copy link
Contributor Author

Masara commented Apr 20, 2024

I added a # pragma: no cover for the function safeds_stubgen.api_analyzer._get_api._get_nearest_init_dirs since I don't know how to test it. The glob searches every file and is usually sorted the way we want, but we have to make sure anyway if it's the file we need, since we can't be 100% sure that glob always does what we want. But I can't write tests for test coverage, since the glob sorts the files for us.

Copy link
Member

@lars-reimann lars-reimann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works beautifully now, thank you.

@lars-reimann lars-reimann merged commit 9ad6df6 into main Apr 25, 2024
8 checks passed
@lars-reimann lars-reimann deleted the 80-cannot-create-stubs-for-safe-ds branch April 25, 2024 10:02
lars-reimann pushed a commit that referenced this pull request May 4, 2024
## [0.3.0](v0.2.0...v0.3.0) (2024-05-04)

### Features

* Added handling for sequence classes ([#127](#127)) ([cb061ab](cb061ab)), closes [#126](#126)
* DocString result names for Safe-DS stub results ([#101](#101)) ([fe163e3](fe163e3)), closes [#100](#100)
* Examples from docstrings are also taken over to stub docstrings ([#116](#116)) ([6665186](6665186)), closes [#115](#115)
* Replace the docstring_parser library with Griffe ([#79](#79)) ([9b2f802](9b2f802))

### Bug Fixes

* `Self` types as results are translated to class names  ([#110](#110)) ([4554a56](4554a56)), closes [#86](#86)
* Creating stubs with relative paths for source and output directories ([#128](#128)) ([b4493c9](b4493c9)), closes [#125](#125)
* Docstrings have the correct indentation for nested classes (stubs) ([#114](#114)) ([c7b8550](c7b8550)), closes [#113](#113)
* Fixed a bug where double ? would be generated for stubs ([#103](#103)) ([c35c6ac](c35c6ac)), closes [#87](#87) [#87](#87)
* Fixed a bug where imports would not check reexports for shortest path ([#112](#112)) ([48c5367](48c5367)), closes [#82](#82)
* Fixed a bug where results in stubs would not be named ([#131](#131)) ([4408c84](4408c84)), closes [#100](#100)
* Fixed a bug which prevented mypy version update ([#107](#107)) ([501d2cd](501d2cd))
* Fixed the stubs generator ([#108](#108)) ([9ad6df6](9ad6df6)), closes [#80](#80)
* Generated names of callback results start with result, not with param ([#104](#104)) ([6e696e9](6e696e9)), closes [#85](#85)
* Include lines of examples that start with `...` ([#130](#130)) ([3477b4a](3477b4a)), closes [#129](#129)
* No "// TODO ..." if return type is explicitly `None` ([#111](#111)) ([08e345f](08e345f)), closes [#83](#83)
* Removed the Epydoc parser ([#89](#89)) ([684a101](684a101))
* Replaced tabs with 4 spaces ([#105](#105)) ([8e7aa5d](8e7aa5d)), closes [#84](#84)
* The file structure of stubs resembles the "package" path. ([#106](#106)) ([ff1800e](ff1800e)), closes [#81](#81)
* Translation of callable ([#102](#102)) ([c581e6a](c581e6a)), closes [#88](#88) [#88](#88)
@lars-reimann
Copy link
Member

🎉 This PR is included in version 0.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@lars-reimann lars-reimann added the released Included in a release label May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released Included in a release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot create stubs for safe-ds
3 participants