Skip to content

Commit

Permalink
feat: port code from library-analyzer (#16)
Browse files Browse the repository at this point in the history
### Summary of Changes

* Moved API and docstring parser functionality from Library-Analyzer to
this project.
* Removed astroid and added mypy for file parsing and adjusted the AST
walker & visitor.
* Adjusted docstring parsers to work with mypy.
* Added snapshot testing for pytest.

---------

Co-authored-by: Lars Reimann <mail@larsreimann.com>
Co-authored-by: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com>
  • Loading branch information
3 people committed Oct 12, 2023
1 parent 0d8b701 commit 5e0b3b1
Show file tree
Hide file tree
Showing 63 changed files with 12,816 additions and 95 deletions.
1 change: 1 addition & 0 deletions .github/linters/.mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
disallow_incomplete_defs = true
disallow_untyped_defs = true
ignore_missing_imports = true
exclude = ["tests/data"]
2 changes: 2 additions & 0 deletions .github/linters/.ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ ignore = [
"TRY003",
]

extend-exclude = ["tests/data"]

[per-file-ignores]
"*test*.py" = [
# Undocumented declarations
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ __pycache__/
venv/

# Pytest outputs
.mypy_cache/
.pytest_cache/
htmlcov/
.coverage
Expand Down
2 changes: 1 addition & 1 deletion .mega-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
EXTENDS: https://raw.githubusercontent.com/lars-reimann/.github/main/.mega-linter.yml

# Config
FILTER_REGEX_EXCLUDE: (\.github/workflows/|mkdocs.yml)
FILTER_REGEX_EXCLUDE: (\.github/workflows/|mkdocs.yml|tests/data)

# Workaround to also run prettier on other supported file types. We deactivate it for Markdown compared to the extended
# configuration since it breaks admonitions of Material for MkDocs.
Expand Down
243 changes: 152 additions & 91 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ generate-safeds-stubs = "safeds_stubgen.main:main"
[tool.poetry.dependencies]
python = "^3.11"
mypy = "^1.5.1"
docstring-parser = "^0.15"
syrupy = "^4.5.0"

[tool.poetry.group.dev.dependencies]
pytest = "^7.4.2"
pytest-cov = "^4.0.0"
setuptools = "^68.0.0"

[tool.poetry.group.docs.dependencies]
mkdocs = "^1.5.3"
Expand All @@ -34,3 +37,4 @@ build-backend = "poetry.core.masonry.api"

[tool.black]
line-length = 120

2 changes: 2 additions & 0 deletions src/safeds_stubgen/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"""Safe-DS stubs generator."""
from __future__ import annotations
49 changes: 49 additions & 0 deletions src/safeds_stubgen/api_analyzer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""API-Analyzer for the Safe-DS stubs generator."""
from __future__ import annotations

from ._api import API, Attribute, Class, Function, Parameter, ParameterAssignment
from ._get_api import get_api
from ._mypy_helpers import get_classdef_definitions, get_funcdef_definitions, get_mypyfile_definitions
from ._package_metadata import distribution, distribution_version, package_root
from ._types import (
AbstractType,
BoundaryType,
DictType,
EnumType,
FinalType,
ListType,
LiteralType,
NamedType,
OptionalType,
SetType,
TupleType,
UnionType,
)

__all__ = [
"AbstractType",
"API",
"Attribute",
"BoundaryType",
"Class",
"DictType",
"distribution",
"distribution_version",
"EnumType",
"FinalType",
"Function",
"get_api",
"get_classdef_definitions",
"get_funcdef_definitions",
"get_mypyfile_definitions",
"ListType",
"LiteralType",
"NamedType",
"OptionalType",
"package_root",
"Parameter",
"ParameterAssignment",
"SetType",
"TupleType",
"UnionType",
]

0 comments on commit 5e0b3b1

Please sign in to comment.