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

feat: Added generation for Safe-DS stubs files #33

Merged
merged 122 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from 106 commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
bb1e449
Added stub generator and functionality for generating a module + impo…
Masara Oct 13, 2023
a7a067c
Stubs generator now generates global functions and enums; some small …
Masara Oct 13, 2023
d756015
Added superclasses & parameter default values to stub generator
Masara Oct 14, 2023
59d2732
Refactoring & some small fixes
Masara Oct 14, 2023
a2baa05
Refactoring
Masara Oct 14, 2023
50e18c0
Merge branch 'main' into stubs_generation
Masara Oct 17, 2023
4a3b8bd
fixes & refactoring
Masara Oct 17, 2023
975293b
Fixed a bug in the get_api call | Stub-Generator: some fixes and adde…
Masara Oct 20, 2023
519aaae
Added nested classes for the stubs generator
Masara Oct 20, 2023
78143ea
Refactoring stubs generator: Access to data of the API via API class,…
Masara Oct 20, 2023
aa6e543
some fixes
Masara Oct 20, 2023
5e51e2e
Fixed a bug in _get_api.py which prevented analysing packages with di…
Masara Oct 23, 2023
cfa90eb
Merge branch 'fixes-path_lengths-module_id' into stubs_generation
Masara Oct 23, 2023
3a61470
style: apply automated linter fixes
megalinter-bot Oct 23, 2023
87d8886
Created new package for stubs generation functions, created test file…
Masara Oct 23, 2023
3d8aee4
Added test cases for files, directories, classes, functions and attri…
Masara Oct 23, 2023
7201cda
Merge remote-tracking branch 'origin/fixes-path_lengths-module_id' in…
Masara Oct 23, 2023
7f4dd64
linter fix
Masara Oct 23, 2023
e5b023f
Merge branch 'fixes-path_lengths-module_id' into stubs_generation
Masara Oct 23, 2023
cbf2efa
Removed OPT_POS_ONLY from ParameterAssignment enum and added todos
Masara Nov 5, 2023
5ad4b69
Added tests for the stubs generation
Masara Nov 5, 2023
cf745d8
Added more test data and cases, added todos, refactoring
Masara Nov 6, 2023
e433458
Refactoring
Masara Nov 6, 2023
082b1b9
Merge branch 'main' into stubs_generation
Masara Nov 6, 2023
291e13c
Linter fix
Masara Nov 6, 2023
3872ee0
Added a TODO for stubs if a class has multiple inheritances, empty en…
Masara Nov 8, 2023
7c902f5
Added handling for methods with @classmethod decorator and adjusted t…
Masara Nov 8, 2023
37efa81
Refactoring
Masara Nov 8, 2023
3f008d4
(WIP) Refactoring, tiny bug fixes and adding todos
Masara Nov 10, 2023
3321666
Merge branch 'main' into stubs_generation
Masara Nov 13, 2023
852767f
Attributes, Parameter and Enum instances will be converted to camelCa…
Masara Nov 13, 2023
ef587b6
Refactoring
Masara Nov 13, 2023
d04c4f7
Test snapshot update
Masara Nov 13, 2023
541fd4d
Removed test packages and updated test snapshots
Masara Nov 13, 2023
79fd8a2
Adjusted test snapshots and removed enum imports for stub generator
Masara Nov 13, 2023
1cda792
Adjusted test snapshots and removed enum imports for stub generator
Masara Nov 13, 2023
9ec9516
Adjusted test snapshots
Masara Nov 13, 2023
507e3f0
Adjusted test snapshots and added escaping for keywords in imports
Masara Nov 13, 2023
912b6ca
api_analyzer: Fixed a bug where lists with multiple types would not b…
Masara Nov 13, 2023
35f0dd1
Added information for class methods to api analyzer and stubs generator
Masara Nov 14, 2023
164a416
Fixed create type function for stubs generator for None types in Unions
Masara Nov 14, 2023
c2f34fc
Removed automatic trailing whitespace trimming for .ambr (test snapsh…
Masara Nov 17, 2023
bc188d4
Issue #37 - Added new type "CallableType" for api_analyzer and stubs …
Masara Nov 17, 2023
804f86a
Updated test snapshots
Masara Nov 17, 2023
6cd1892
Updated test snapshots
Masara Nov 17, 2023
d29d3d4
Issue #34: Added inference for return, parameter and attribute types.
Masara Nov 18, 2023
b6a7051
Issue #34: Test fixes
Masara Nov 18, 2023
6b0e74e
Issue #34: Test and bug fixes
Masara Nov 18, 2023
46e75fe
Issue #34: Test and bug fixes
Masara Nov 18, 2023
fa6c5ab
Issue #34: Test and bug fixes
Masara Nov 18, 2023
9eb19f5
Issue #34: Added TODOs for the stub generator if parameters, attribut…
Masara Nov 20, 2023
69d421f
Issue #35 & #36 added variance parsing api_analyzer; added variance a…
Masara Nov 20, 2023
477a386
Fixed a bug for the stubs generator
Masara Nov 21, 2023
f1bf09f
Big overhaul of the tests: Removed redundant test data files and merg…
Masara Nov 21, 2023
fb2256b
[WIP] Added handling for @property and @abstractmethod decorators
Masara Nov 21, 2023
d0dac2b
[WIP] Stubs generator: ABC classes won't have a constructor
Masara Nov 22, 2023
7085ee0
Fixed bugs and adjusted test snapshots
Masara Nov 24, 2023
b7a7730
Stubs generator: Added @PythonModule annotation for package informati…
Masara Nov 24, 2023
6466dfb
AST Visitor: Parameter can have callables as type, fixed representati…
Masara Nov 27, 2023
4aea41e
Added handling for final type attributes and UpperCamelCase stub name…
Masara Nov 27, 2023
4bff2cb
Fixed bugs and tests, added qnames for some NamedTypes
Masara Nov 27, 2023
8b44fe6
Fixed a bug where attributes with call expressions as type hint would…
Masara Nov 27, 2023
efaab1f
fixed a test snapshot bug where return types would be unsorted and mi…
Masara Nov 27, 2023
f448d1e
Added more cases where NamedType get qname information and adjusted t…
Masara Nov 29, 2023
75df41e
Added more cases where NamedType get qname information and added more…
Masara Nov 29, 2023
684d40a
Adjusted test snapshots
Masara Nov 29, 2023
d6b8bf7
API-Analyzer: Better handling for Any types and illegal list and set …
Masara Nov 29, 2023
e171213
Added more test cases
Masara Nov 29, 2023
006f98b
Refactoring tests
Masara Nov 29, 2023
5bd771d
Added test case for snake_case to camelCase converter
Masara Nov 29, 2023
852d48f
Issue #39: The snake_case to camelCase converter can be toggled with …
Masara Nov 29, 2023
f0ffa79
Merge branch 'main' into stubs_generation
lars-reimann Nov 30, 2023
6b29c16
Mostly refactoring, fixing some bugs and adding test cases
Masara Nov 30, 2023
757b667
Merge remote-tracking branch 'origin/stubs_generation' into stubs_gen…
Masara Nov 30, 2023
b654b68
Removed OptionalType class, since it is not in use.
Masara Nov 30, 2023
0a2b3cf
Fixed a bug where "None" could not be set as the default value for pa…
Masara Nov 30, 2023
509fb30
Updated snapshot tests
Masara Nov 30, 2023
7e7eb94
Updated snapshot tests
Masara Nov 30, 2023
e5b5b1a
Linter and bug fixes
Masara Nov 30, 2023
794020d
Linter and bug fixes
Masara Nov 30, 2023
5f8bfc7
Changed test data directory and file names, since the GitHub test run…
Masara Nov 30, 2023
71090e4
Changed test data directory and file names, since the GitHub test run…
Masara Nov 30, 2023
c680399
Added .pytest.ini for pytest to ignore tests/data directory while sea…
Masara Nov 30, 2023
6a57205
Added a temporary raise for the github test runner
Masara Nov 30, 2023
d7bd3b9
Changed test for github test runner
Masara Nov 30, 2023
8a66557
Changed test for github test runner
Masara Nov 30, 2023
876cb95
Changed test for github test runner
Masara Nov 30, 2023
7053942
Changed test for github test runner
Masara Nov 30, 2023
3435a54
Linter fixes
Masara Nov 30, 2023
b9d8fa2
style: apply automated linter fixes
megalinter-bot Nov 30, 2023
944c863
style: apply automated linter fixes
megalinter-bot Nov 30, 2023
e78a3a5
codecov & refactoring
Masara Nov 30, 2023
f3604f1
Merge remote-tracking branch 'origin/stubs_generation' into stubs_gen…
Masara Nov 30, 2023
bd4a5ff
codecov & refactoring
Masara Nov 30, 2023
df1a986
codecov & refactoring
Masara Nov 30, 2023
64e26a2
codecov & refactoring
Masara Nov 30, 2023
93bc3cc
codecov & refactoring
Masara Nov 30, 2023
6de83ce
chore: swap two config sections
lars-reimann Dec 1, 2023
2be7ef4
chore: move pytest config into `pyproject.toml`
lars-reimann Dec 1, 2023
599dbad
Merge branch 'main' into stubs_generation
lars-reimann Dec 1, 2023
cb9d9d9
[Refactoring] Renamed Variance class to TypeParameter and removed fro…
Masara Dec 4, 2023
3609a29
Merge remote-tracking branch 'origin/stubs_generation' into stubs_gen…
Masara Dec 4, 2023
09c2586
[Refactoring] Removed the is_abstract constructor field from the Clas…
Masara Dec 4, 2023
077f192
[Refactoring] Removed the default_is_none constructor field from the …
Masara Dec 4, 2023
d058b83
[Refactoring] Fixed typos
Masara Dec 4, 2023
1afef9f
[Refactoring] Changed call argument from -ci to -nc
Masara Dec 4, 2023
01864b8
[Refactoring]
Masara Dec 4, 2023
566e929
Refactoring and bug fixing
Masara Dec 4, 2023
d7ff691
bug fix
Masara Dec 4, 2023
032027c
Removed unused is_type_inferred information
Masara Dec 5, 2023
77c4be8
LiteralTypes are joined for stubs
Masara Dec 5, 2023
2fe4bb8
Added test data for codecov
Masara Dec 5, 2023
8dcb2e2
refactoring
Masara Dec 5, 2023
779e87c
style: apply automated linter fixes
megalinter-bot Dec 5, 2023
09fb9cd
Fixing tests
Masara Dec 5, 2023
936a557
Merge remote-tracking branch 'origin/stubs_generation' into stubs_gen…
Masara Dec 5, 2023
2df5093
fixing a bug where None default values would not correctly be parsed,…
Masara Dec 6, 2023
63c7d03
codecov and linter fixes
Masara Dec 6, 2023
64ad07f
style: apply automated linter fixes
megalinter-bot Dec 6, 2023
a08450d
style: apply automated linter fixes
megalinter-bot Dec 6, 2023
0c26c80
codecov
Masara Dec 6, 2023
20282b0
Merge remote-tracking branch 'origin/stubs_generation' into stubs_gen…
Masara Dec 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.ambr]
trim_trailing_whitespace = false

[{*.yaml,*.yml}]
indent_size = 2
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ packages = [
]

[tool.poetry.scripts]
generate-safeds-stubs = "safeds_stubgen.main:main"
safe-ds-stubgen = "safeds_stubgen.main:main"

[tool.poetry.dependencies]
python = "^3.11"
Expand All @@ -34,5 +34,8 @@ mkdocs-material = "^9.4.7"
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.pytest.ini_options]
addopts = "--ignore=./tests/data"

[tool.black]
line-length = 120
26 changes: 23 additions & 3 deletions src/safeds_stubgen/api_analyzer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
"""API-Analyzer for the Safe-DS stubs generator."""

from __future__ import annotations

from ._api import API, Attribute, Class, Function, Parameter, ParameterAssignment
from ._api import (
API,
Attribute,
Class,
Enum,
Function,
Module,
Parameter,
ParameterAssignment,
QualifiedImport,
Result,
VarianceKind,
WildcardImport,
)
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,
CallableType,
DictType,
EnumType,
FinalType,
ListType,
LiteralType,
NamedType,
OptionalType,
SetType,
TupleType,
UnionType,
Expand All @@ -25,10 +39,12 @@
"API",
"Attribute",
"BoundaryType",
"CallableType",
"Class",
"DictType",
"distribution",
"distribution_version",
"Enum",
"EnumType",
"FinalType",
"Function",
Expand All @@ -38,12 +54,16 @@
"get_mypyfile_definitions",
"ListType",
"LiteralType",
"Module",
"NamedType",
"OptionalType",
"package_root",
"Parameter",
"ParameterAssignment",
"QualifiedImport",
"Result",
"SetType",
"TupleType",
"UnionType",
"VarianceKind",
"WildcardImport",
]
38 changes: 35 additions & 3 deletions src/safeds_stubgen/api_analyzer/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def to_dict(self) -> dict[str, Any]:
class Class:
id: str
name: str
superclasses: list[Class]
superclasses: list[str]
is_public: bool
docstring: ClassDocstring
constructor: Function | None = None
Expand All @@ -174,6 +174,7 @@ class Class:
attributes: list[Attribute] = field(default_factory=list)
methods: list[Function] = field(default_factory=list)
classes: list[Class] = field(default_factory=list)
type_parameters: list[TypeParameter] = field(default_factory=list)

def to_dict(self) -> dict[str, Any]:
return {
Expand All @@ -187,8 +188,13 @@ def to_dict(self) -> dict[str, Any]:
"attributes": [attribute.id for attribute in self.attributes],
"methods": [method.id for method in self.methods],
"classes": [class_.id for class_ in self.classes],
"type_parameters": [type_parameter.to_dict() for type_parameter in self.type_parameters],
}

@property
def is_abstract(self) -> bool:
return "abc.ABC" in self.superclasses

def add_method(self, method: Function) -> None:
self.methods.append(method)

Expand All @@ -210,6 +216,7 @@ class Attribute:
is_static: bool
type: AbstractType | None
docstring: AttributeDocstring
is_type_inferred: bool

def to_dict(self) -> dict[str, Any]:
return {
Expand All @@ -219,6 +226,7 @@ def to_dict(self) -> dict[str, Any]:
"is_public": self.is_public,
"is_static": self.is_static,
"type": self.type.to_dict() if self.type is not None else None,
"is_type_inferred": self.is_type_inferred,
}


Expand All @@ -229,6 +237,8 @@ class Function:
docstring: FunctionDocstring
is_public: bool
is_static: bool
is_class_method: bool
is_property: bool
results: list[Result] = field(default_factory=list)
reexported_by: list[Module] = field(default_factory=list)
parameters: list[Parameter] = field(default_factory=list)
Expand All @@ -240,6 +250,8 @@ def to_dict(self) -> dict[str, Any]:
"docstring": self.docstring.to_dict(),
"is_public": self.is_public,
"is_static": self.is_static,
"is_class_method": self.is_class_method,
"is_property": self.is_property,
"results": [result.id for result in self.results],
"reexported_by": [module.id for module in self.reexported_by],
"parameters": [parameter.id for parameter in self.parameters],
Expand All @@ -254,7 +266,8 @@ class Parameter:
default_value: str | bool | int | float | None
assigned_by: ParameterAssignment
docstring: ParameterDocstring
type: AbstractType
type: AbstractType | None
is_type_inferred: bool
Masara marked this conversation as resolved.
Show resolved Hide resolved

@property
def is_required(self) -> bool:
Expand All @@ -275,7 +288,8 @@ def to_dict(self) -> dict[str, Any]:
"is_optional": self.is_optional,
"default_value": self.default_value,
"assigned_by": self.assigned_by.name,
"type": self.type.to_dict(),
"type": self.type.to_dict() if self.type is not None else None,
"is_type_inferred": self.is_type_inferred,
}


Expand All @@ -297,11 +311,28 @@ class ParameterAssignment(PythonEnum):
NAMED_VARARG = "NAMED_VARARG"


@dataclass(frozen=True)
class TypeParameter:
name: str
type: AbstractType
Masara marked this conversation as resolved.
Show resolved Hide resolved
variance: VarianceKind

def to_dict(self) -> dict[str, Any]:
return {"name": self.name, "type": self.type.to_dict(), "variance_type": self.variance.name}


class VarianceKind(PythonEnum):
CONTRAVARIANT = "CONTRAVARIANT"
COVARIANT = "COVARIANT"
INVARIANT = "INVARIANT"


@dataclass(frozen=True)
class Result:
id: str
name: str
type: AbstractType | None
is_type_inferred: bool
lars-reimann marked this conversation as resolved.
Show resolved Hide resolved
docstring: ResultDocstring

def to_dict(self) -> dict[str, Any]:
Expand All @@ -310,6 +341,7 @@ def to_dict(self) -> dict[str, Any]:
"name": self.name,
"docstring": self.docstring.to_dict(),
"type": self.type.to_dict() if self.type is not None else None,
"is_type_inferred": self.is_type_inferred,
}


Expand Down
Loading
Loading