Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.

Commit 2c7f368

Browse files
authored
fix: display of math blocks (#421)
* refactor: minor changes * fix: keep newlines in description * fix: update scikit-learn data * style: apply automatic fixes of linters * fix: tests * style: apply automatic fixes of linters Co-authored-by: lars-reimann <[email protected]>
1 parent 392f672 commit 2c7f368

File tree

9 files changed

+28371
-14176
lines changed

9 files changed

+28371
-14176
lines changed

api-editor/client/src/features/packageData/selectionView/DocumentationText.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@ const DocumentationText: React.FC<DocumentationTextProps> = function ({
4343
inputText = '',
4444
}) {
4545
const preprocessedText = inputText
46+
// replace single new-lines by spaces
4647
.replaceAll(/(?<!\n)\n(?!\n)/gu, ' ')
48+
// replace inline math elements
4749
.replaceAll(/:math:`([^`]*)`/gu, '$$1$')
50+
// replace block math elements
4851
.replaceAll(/\.\. math::\s*(\S.*)\n\n/gu, '$$\n$1\n$$\n\n');
4952

5053
const shortenedText = preprocessedText.split('\n\n')[0];

api-editor/data/scikit-learn__sklearn__1.0.1__api.json renamed to api-editor/data/scikit-learn__sklearn__1.0.2__api.json

+28,313-14,116
Large diffs are not rendered by default.

package-parser/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# library-analyzer
1+
# package-parser
22

3-
A tool to analyzer client and API code written in Python.
3+
A tool to analyze client and API code written in Python.
44

55
## Usage
66

package-parser/package_parser/commands/get_api/__init__.py

+8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
from ._get_api import get_api
22
from ._model import (
33
API,
4+
Action,
5+
APIDependencies,
46
Class,
7+
Condition,
8+
Dependency,
59
FromImport,
610
Function,
711
Import,
812
Module,
913
Parameter,
1014
ParameterAndResultDocstring,
1115
ParameterAssignment,
16+
ParameterHasValue,
17+
ParameterIsIgnored,
18+
ParameterIsIllegal,
19+
ParameterIsNone,
1220
Result,
1321
)
1422
from ._package_metadata import (

package-parser/package_parser/commands/get_api/_ast_visitor.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,11 @@ def __description(numpydoc: NumpyDocString) -> str:
160160

161161
result = ""
162162
if has_summary:
163-
result += " ".join(numpydoc["Summary"])
163+
result += "\n".join(numpydoc["Summary"])
164164
if has_summary and has_extended_summary:
165165
result += "\n\n"
166166
if has_extended_summary:
167-
result += " ".join(numpydoc["Extended Summary"])
167+
result += "\n".join(numpydoc["Extended Summary"])
168168
return result
169169

170170
@staticmethod

package-parser/package_parser/commands/get_api/_model.py

+33-47
Original file line numberDiff line numberDiff line change
@@ -167,29 +167,29 @@ def to_json(self) -> Any:
167167
}
168168

169169

170+
@dataclass
170171
class Import:
172+
module_name: str
173+
alias: Optional[str]
174+
171175
@staticmethod
172176
def from_json(json: Any) -> Import:
173177
return Import(json["module"], json["alias"])
174178

175-
def __init__(self, module_name: str, alias: Optional[str]):
176-
self.module: str = module_name
177-
self.alias: Optional[str] = alias
178-
179179
def to_json(self) -> Any:
180-
return {"module": self.module, "alias": self.alias}
180+
return {"module": self.module_name, "alias": self.alias}
181181

182182

183+
@dataclass
183184
class FromImport:
185+
module_name: str
186+
declaration_name: str
187+
alias: Optional[str]
188+
184189
@staticmethod
185190
def from_json(json: Any) -> FromImport:
186191
return FromImport(json["module"], json["declaration"], json["alias"])
187192

188-
def __init__(self, module_name: str, declaration_name: str, alias: Optional[str]):
189-
self.module_name: str = module_name
190-
self.declaration_name: str = declaration_name
191-
self.alias: Optional[str] = alias
192-
193193
def to_json(self) -> Any:
194194
return {
195195
"module": self.module_name,
@@ -256,7 +256,17 @@ def to_json(self) -> Any:
256256
}
257257

258258

259+
@dataclass
259260
class Function:
261+
qname: str
262+
decorators: list[str]
263+
parameters: list[Parameter]
264+
results: list[Result]
265+
is_public: bool
266+
description: str
267+
docstring: str
268+
source_code: str
269+
260270
@staticmethod
261271
def from_json(json: Any) -> Function:
262272
return Function(
@@ -273,26 +283,6 @@ def from_json(json: Any) -> Function:
273283
json["source_code"],
274284
)
275285

276-
def __init__(
277-
self,
278-
qname: str,
279-
decorators: list[str],
280-
parameters: list[Parameter],
281-
results: list[Result],
282-
is_public: bool,
283-
description: str,
284-
docstring: str,
285-
source_code: str,
286-
) -> None:
287-
self.qname: str = qname
288-
self.decorators: list[str] = decorators
289-
self.parameters: list[Parameter] = parameters
290-
self.results: list[Result] = results
291-
self.is_public: bool = is_public
292-
self.description: str = description
293-
self.docstring: str = inspect.cleandoc(docstring or "")
294-
self.source_code: str = source_code
295-
296286
@property
297287
def name(self) -> str:
298288
return self.qname.split(".")[-1]
@@ -370,7 +360,7 @@ def from_docstring(cls, docstring: ParameterAndResultDocstring) -> RefinedType:
370360

371361
def __init__(
372362
self,
373-
ref_type: Optional[Union[UnionType, BoundaryType, EnumType, NamedType]] = None,
363+
ref_type: Union[UnionType, BoundaryType, EnumType, NamedType, None] = None,
374364
) -> None:
375365
self.ref_type = ref_type
376366

@@ -423,34 +413,30 @@ class ParameterAssignment(Enum):
423413
NAME_ONLY = (auto(),)
424414

425415

416+
@dataclass
426417
class Result:
418+
name: str
419+
docstring: ParameterAndResultDocstring
420+
427421
@staticmethod
428422
def from_json(json: Any) -> Result:
429423
return Result(
430424
json["name"], ParameterAndResultDocstring.from_json(json["docstring"])
431425
)
432426

433-
def __init__(self, name: str, docstring: ParameterAndResultDocstring) -> None:
434-
self.name: str = name
435-
self.docstring = docstring
436-
437427
def to_json(self) -> Any:
438428
return {"name": self.name, "docstring": self.docstring.to_json()}
439429

440430

431+
@dataclass
441432
class ParameterAndResultDocstring:
433+
type: str
434+
description: str
435+
442436
@classmethod
443437
def from_json(cls, json: Any):
444438
return cls(json["type"], json["description"])
445439

446-
def __init__(
447-
self,
448-
type_: str,
449-
description: str,
450-
) -> None:
451-
self.type: str = type_
452-
self.description: str = description
453-
454440
def to_json(self) -> Any:
455441
return {"type": self.type, "description": self.description}
456442

@@ -529,10 +515,10 @@ class Dependency:
529515
@classmethod
530516
def from_json(cls, json: Any):
531517
return cls(
532-
Parameter.from_json(["hasDependentParameter"]),
533-
Parameter.from_json(["isDependingOn"]),
534-
Condition.from_json(["hasCondition"]),
535-
Action.from_json(["hasAction"]),
518+
Parameter.from_json(json["hasDependentParameter"]),
519+
Parameter.from_json(json["isDependingOn"]),
520+
Condition.from_json(json["hasCondition"]),
521+
Action.from_json(json["hasAction"]),
536522
)
537523

538524
def to_json(self) -> Dict:

package-parser/package_parser/commands/get_dependencies/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Dependency Extaction
1+
# Dependency Extraction
22

33
## How do we imagine a Dependency
44

@@ -16,13 +16,13 @@ Parsing a dependency subtree in an InOrder traversal, we can rebuild a sentence
1616

1717
### Dependency Tree Example
1818

19-
![Alt text](../../../package_parser/commands/get_dependencies/dependency_tree_example.png "Dependency Tree Example")
19+
![Alt text](dependency_tree_example.png "Dependency Tree Example")
2020

2121

2222
## Where to continue work?
2323
* Development of more patterns in _dependency_patterns.py, see [Dependency Parser](https://spacy.io/usage/linguistic-features#dependency-parse), [Dependency Matcher](https://spacy.io/usage/rule-based-matching#dependencymatcher)
2424
* Look into pattern matching over multiple sentences. Have a more theoretical understanding of the meaning of a dependency in the english language.
25-
* Better classification of the subclasses of Actions, Condtions. These classes are found in __../get_api/_model.py__.
25+
* Better classification of the subclasses of Actions, Conditions. These classes are found in __../get_api/_model.py__.
2626

2727
### How to continue work?
2828
It is currently constructed such that for each pattern, there exists a corresponding function __extract_(pattern_name)__ within the class DependencyExtractor. This is due to the assumption that different types of dependency patterns will have different structured sentences, and thus require slightly different combinations of methods to extract the wanted information.

package-parser/package_parser/commands/get_dependencies/_get_dependency.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from spacy.tokens.doc import Doc
77
from spacy.tokens.span import Span
88

9-
from ..get_api._model import (
9+
from ..get_api import (
1010
API,
1111
Action,
1212
APIDependencies,
@@ -61,7 +61,7 @@ def extract_action(action_token: Token, condition_token: Token) -> Action:
6161
if token != condition_token:
6262
action_tokens.extend(extract_lefts_and_rights(token))
6363

64-
# Remove trailing punctiation
64+
# Remove trailing punctuation
6565
if any(p == action_tokens[-1] for p in [",", "."]):
6666
del action_tokens[-1]
6767
action_text = " ".join(action_tokens)

package-parser/tests/commands/get_dependencies/test_get_dependency.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
Dependency,
66
Parameter,
77
ParameterAndResultDocstring,
8+
ParameterAssignment,
89
ParameterHasValue,
910
ParameterIsIgnored,
1011
ParameterIsIllegal,
@@ -99,18 +100,18 @@ def test_extract_dependencies_from_docstring_pattern_adverbial_clause():
99100
name="random_state",
100101
default_value=None,
101102
is_public=True,
102-
assigned_by="NAME_ONLY",
103+
assigned_by=ParameterAssignment.NAME_ONLY,
103104
docstring=ParameterAndResultDocstring(
104-
type_="param possible types", description=param_docstring_nlp.text
105+
type="param possible types", description=param_docstring_nlp.text
105106
),
106107
)
107108
dependee_param = Parameter(
108109
name="probability",
109110
default_value=None,
110111
is_public=True,
111-
assigned_by="NAME_ONLY",
112+
assigned_by=ParameterAssignment.NAME_ONLY,
112113
docstring=ParameterAndResultDocstring(
113-
type_="param possible types", description="param probability docstring"
114+
type="param possible types", description="param probability docstring"
114115
),
115116
)
116117
pattern_parameter_subordinating_conjunction = nlp(

0 commit comments

Comments
 (0)