Skip to content

Commit

Permalink
Fix up the included docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
Matevz Morato committed May 23, 2024
1 parent cc91732 commit 73544bd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
18 changes: 15 additions & 3 deletions generate_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,18 @@
print(f'Could not import depthai: {ex}')

print(f'PYTHONPATH set to {env["PYTHONPATH"]}')
subprocess.check_call(['stubgen', '--include-docstrings', '-p', MODULE_NAME, '-o', f'{DIRECTORY}'], cwd=DIRECTORY, env=env)
# Check if stubgen has the `--include-docstrings` flag
includeDocstrings = False
output = subprocess.check_output(['stubgen', '--help'], env=env)
if b'--include-docstrings' in output:
includeDocstrings = True
print("Will include docstrings in stubs")
else:
print("Will not include docstrings in stubs")
parameters = ['stubgen', '-p', MODULE_NAME, '-o', f'{DIRECTORY}']
if includeDocstrings:
parameters.insert(1, '--include-docstrings')
subprocess.check_call(parameters, cwd=DIRECTORY, env=env)

# Add py.typed
open(f'{DIRECTORY}/depthai/py.typed', 'a').close()
Expand Down Expand Up @@ -67,8 +78,9 @@
final_lines.append(' @overload')
final_lines.append(' def create(self, arg0: Type[T], *args, **kwargs) -> T: ...')
continue
if ' def getCvFrame(self) -> object: ...' in line:
final_lines.append(' def getCvFrame(self) -> numpy.ndarray: ...')
match = re.match(r'^( def getCvFrame\(self\) -> )object(:.*)$', line)
if match:
final_lines.append(f"{match.group(1)}numpy.ndarray{match.group(2)}")
continue
final_lines.append(line)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[build-system]
requires = ["setuptools", "wheel", "mypy==1.8.0", "cmake==3.25"]
requires = ["setuptools", "wheel", "mypy<=1.3.0", "cmake==3.25"]

0 comments on commit 73544bd

Please sign in to comment.