Skip to content

Commit 1db78f4

Browse files
docs: added more docstrings
1 parent 2d0a5db commit 1db78f4

File tree

2 files changed

+34
-44
lines changed

2 files changed

+34
-44
lines changed

src/pydal2sql/cli.py

Lines changed: 13 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
"""
2+
Create the Typer cli.
3+
"""
4+
15
import sys
26
import typing
37
from typing import Annotated, Optional
@@ -85,7 +89,10 @@ def create(
8589
output_file: Optional[str] = None,
8690
) -> bool:
8791
"""
88-
todo: docs
92+
Build the CREATE statements for one or more pydal/typedal tables.
93+
94+
Todo:
95+
more docs
8996
9097
Examples:
9198
pydal2sql create models.py
@@ -128,7 +135,10 @@ def alter(
128135
output_file: Optional[str] = None,
129136
) -> bool:
130137
"""
131-
Todo: docs
138+
Create the migration statements from one state to the other, by writing CREATE, ALTER and DROP statements.
139+
140+
Todo:
141+
docs
132142
133143
Examples:
134144
> pydal2sql alter @b3f24091a9201d6 examples/magic.py
@@ -167,30 +177,6 @@ def alter(
167177
return False
168178

169179

170-
"""
171-
todo:
172-
- db type in config
173-
- models.py with db import or define_tables method.
174-
- `public.` prefix
175-
"""
176-
177-
"""
178-
def pin:
179-
pydal2sql pin 96de5b37b586e75b8ac053b9bef7647f544fe502 # -> default pin created
180-
pydal2sql alter myfile.py # should compare between pin/@latest and @current
181-
# replaces @current for Before, not for After in case of ALTER.
182-
pydal2sql pin --remove # -> default pin removed
183-
184-
pydal2sql pin 96de5b37b586e75b8ac053b9bef7647f544fe502 --name my_custom_name # -> pin '@my_custom_name' created
185-
pydal2sql pin 96de5b37b586e75b8ac053b9bef7647f544fe503 --name my_custom_name #-> pin '@my_custom_name' overwritten
186-
pydal2sql create myfile.py@my_custom_name
187-
pydal2sql pin 96de5b37b586e75b8ac053b9bef7647f544fe502 --remove -> pin '@my_custom_name' removed
188-
189-
pydal2sql pins
190-
# lists hash with name
191-
"""
192-
193-
194180
def show_config_callback() -> Never:
195181
"""
196182
--show-config requested!
@@ -218,16 +204,7 @@ def main(
218204
version: bool = False,
219205
) -> None:
220206
"""
221-
Todo: docs
222-
223-
Args:
224-
_: context to determine if a subcommand is passed, etc
225-
config: path to a different config toml file
226-
verbosity: level of detail to print out (1 - 3)
227-
228-
show_config: display current configuration?
229-
version: display current version?
230-
207+
This script can be used to generate the create or alter sql from pydal or typedal.
231208
"""
232209
if state.config:
233210
# if a config already exists, it's outdated, so we clear it.
@@ -241,7 +218,3 @@ def main(
241218
elif version:
242219
version_callback()
243220
# else: just continue
244-
245-
246-
# if __name__ == "__main__":
247-
# app()

src/pydal2sql/typer_support.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Cli-specific support
2+
Cli-specific support.
33
"""
44
import contextlib
55
import functools
@@ -36,17 +36,29 @@
3636

3737

3838
class ReprEnumMeta(EnumMeta):
39+
"""
40+
Give an Enum class a fancy repr.
41+
"""
42+
3943
def __repr__(cls) -> str: # sourcery skip
44+
"""
45+
Print all of the enum's members.
46+
"""
4047
options = typing.cast(typing.Iterable[Enum], cls.__members__.values()) # for mypy
4148
members_repr = ", ".join(f"{m.value!r}" for m in options)
4249
return f"{cls.__name__}({members_repr})"
4350

4451

4552
class DynamicEnum(Enum, metaclass=ReprEnumMeta):
46-
...
53+
"""
54+
Cmobine the enum class with the ReprEnumMeta metaclass.
55+
"""
4756

4857

4958
def create_enum_from_literal(name: str, literal_type: LiteralType) -> typing.Type[DynamicEnum]:
59+
"""
60+
Transform a typing.Literal statement into an Enum.
61+
"""
5062
literals: list[str] = []
5163

5264
if hasattr(literal_type, "__args__"):
@@ -266,7 +278,9 @@ class ApplicationState:
266278
config: MaybeConfig = None
267279

268280
def __post_init__(self) -> None:
269-
...
281+
"""
282+
Runs after the dataclass init.
283+
"""
270284

271285
def load_config(self, **overwrites: Any) -> Config:
272286
"""
@@ -315,7 +329,7 @@ def some_command(): ...
315329
316330
When calling a command from a different command, _suppress=True can be added to not raise an Exit exception.
317331
318-
See also:
332+
See Also:
319333
github.com:trialandsuccess/su6-checker
320334
"""
321335

@@ -355,6 +369,9 @@ def _is_debug() -> bool: # pragma: no cover
355369

356370

357371
def is_debug() -> bool: # pragma: no cover
372+
"""
373+
Returns whether IS_DEBUG = 1 in the .env.
374+
"""
358375
with contextlib.suppress(Exception):
359376
return _is_debug()
360377
return False

0 commit comments

Comments
 (0)