Skip to content

Commit

Permalink
Stubs need to be checked in (#171)
Browse files Browse the repository at this point in the history
Check-in stub files and add option to check that existing stubs match
checked in
versions.

As a result of isolated builds running any kind of python script with
the module
dependencies requires a lot of customisation that goes against python
build
tools
  • Loading branch information
robert3005 authored Oct 3, 2023
1 parent 35eddc4 commit e356037
Show file tree
Hide file tree
Showing 16 changed files with 496 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ jobs:
run: poetry run black .
- name: Pytest
run: poetry run pytest
- name: Check generated stubs
run: poetry run python -m ziglang build --build-file pytest.build.zig generate-stubs -Dcheck-stubs=true

- name: Zig Docs Build
run: poetry run python -m ziglang build docs
Expand Down
1 change: 0 additions & 1 deletion example/.gitignore

This file was deleted.

7 changes: 7 additions & 0 deletions example/buffers.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from __future__ import annotations

def sum(buf, /): ...

class ConstantBuffer:
def __init__(elem, length, /):
pass
50 changes: 50 additions & 0 deletions example/classes.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from __future__ import annotations

class Animal:
def species(self, /): ...

class ConstructableClass:
def __init__(count, /):
pass

class Counter:
def __init__():
pass
def increment(self, /): ...

count: ...

class Hash:
def __init__(x, /):
pass
def __hash__(self, /):
"""
Return hash(self).
"""
...

class Math:
def add(x, y, /): ...

class SomeClass:
"""
Some class defined in Zig accessible from Python
"""

class User:
def __init__(name, /):
pass
@property
def email(self): ...
@property
def greeting(self): ...

class ZigOnlyMethod:
def __init__(x, /):
pass
def reexposed(self, /): ...

class Dog(Animal):
def __init__(breed, /):
pass
def breed(self, /): ...
4 changes: 4 additions & 0 deletions example/exceptions.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from __future__ import annotations

def raise_custom_error(): ...
def raise_value_error(message, /): ...
4 changes: 4 additions & 0 deletions example/functions.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from __future__ import annotations

def double(x, /): ...
def with_kwargs(x, /, *, y=42.0): ...
3 changes: 3 additions & 0 deletions example/hello.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from __future__ import annotations

def hello(): ...
19 changes: 19 additions & 0 deletions example/iterators.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from __future__ import annotations

class Range:
def __init__(lower, upper, step, /):
pass
def __iter__(self, /):
"""
Implement iter(self).
"""
...

class RangeIterator:
def __init__(next, stop, step, /):
pass
def __next__(self, /):
"""
Implement next(self).
"""
...
4 changes: 4 additions & 0 deletions example/memory.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from __future__ import annotations

def append(left, /): ...
def concat(left, /): ...
16 changes: 16 additions & 0 deletions example/modules.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
Zig multi-line strings make it easy to define a docstring...
..with lots of lines!
P.S. I'm sure one day we'll hook into Zig's AST and read the Zig doc comments ;)
"""
from __future__ import annotations

def count(): ...
def hello(name, /): ...
def increment(): ...
def whoami(): ...

class submod:
def world(): ...
Loading

0 comments on commit e356037

Please sign in to comment.