-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from PrefectHQ/cruft-update
Cruft update + update block docstring examples
- Loading branch information
Showing
8 changed files
with
168 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,94 @@ | ||
"Copies README.md to index.md." | ||
""" | ||
Copies README.md to index.md. Also discovers all blocks and | ||
generates a list of them in the docs under the Blocks Catalog heading. | ||
""" | ||
|
||
from pathlib import Path | ||
from textwrap import dedent | ||
|
||
import mkdocs_gen_files | ||
from prefect.blocks.core import Block | ||
from prefect.utilities.dispatch import get_registry_for_type | ||
from prefect.utilities.importtools import to_qualified_name | ||
|
||
COLLECTION_SLUG = "prefect_airbyte" | ||
|
||
|
||
def find_module_blocks(): | ||
blocks = get_registry_for_type(Block) | ||
collection_blocks = [ | ||
block | ||
for block in blocks.values() | ||
if to_qualified_name(block).startswith(COLLECTION_SLUG) | ||
] | ||
module_blocks = {} | ||
for block in collection_blocks: | ||
block_name = block.__name__ | ||
module_nesting = tuple(to_qualified_name(block).split(".")[1:-1]) | ||
if module_nesting not in module_blocks: | ||
module_blocks[module_nesting] = [] | ||
module_blocks[module_nesting].append(block_name) | ||
return module_blocks | ||
|
||
|
||
def insert_blocks_catalog(generated_file): | ||
module_blocks = find_module_blocks() | ||
generated_file.write("## Blocks Catalog\n") | ||
generated_file.write( | ||
dedent( | ||
f""" | ||
Below is a list of Blocks available for registration in | ||
`prefect-airbyte`. | ||
To register blocks in this module to | ||
[view and edit them](https://orion-docs.prefect.io/ui/blocks/) | ||
on Prefect Cloud: | ||
```bash | ||
prefect block register -m {COLLECTION_SLUG} | ||
``` | ||
""" | ||
) | ||
) | ||
generated_file.write( | ||
"Note, to use the `load` method on Blocks, you must already have a block document " # noqa | ||
"[saved through code](https://orion-docs.prefect.io/concepts/blocks/#saving-blocks) " # noqa | ||
"or [saved through the UI](https://orion-docs.prefect.io/ui/blocks/).\n" | ||
) | ||
for module_nesting, block_names in module_blocks.items(): | ||
module_path = " ".join(module_nesting) | ||
module_title = module_path.replace("_", " ").title() | ||
generated_file.write(f"### {module_title} Module\n") | ||
for block_name in block_names: | ||
generated_file.write( | ||
f"**[{block_name}][{COLLECTION_SLUG}.{module_path}.{block_name}]**\n" | ||
) | ||
generated_file.write( | ||
dedent( | ||
f""" | ||
To load the {block_name}: | ||
```python | ||
from prefect import flow | ||
from {COLLECTION_SLUG}.{module_path} import {block_name} | ||
@flow | ||
def my_flow(): | ||
my_block = {block_name}.load("MY_BLOCK_NAME") | ||
my_flow() | ||
``` | ||
""" | ||
) | ||
) | ||
|
||
|
||
readme_path = Path("README.md") | ||
docs_index_path = Path("index.md") | ||
|
||
with open(readme_path, "r") as readme: | ||
with mkdocs_gen_files.open(docs_index_path, "w") as generated_file: | ||
for line in readme: | ||
if line.startswith("## Resources"): | ||
insert_blocks_catalog(generated_file) | ||
generated_file.write(line) | ||
|
||
mkdocs_gen_files.set_edit_path(Path(docs_index_path), readme_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
from . import _version | ||
|
||
from prefect_airbyte.connections import AirbyteConnection # noqa F401 | ||
from prefect_airbyte.server import AirbyteServer # noqa F401 | ||
|
||
__version__ = _version.get_versions()["version"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import pytest | ||
from prefect.blocks.core import Block | ||
from prefect.testing.standard_test_suites import BlockStandardTestSuite | ||
from prefect.utilities.dispatch import get_registry_for_type | ||
from prefect.utilities.importtools import to_qualified_name | ||
|
||
|
||
def find_module_blocks(): | ||
blocks = get_registry_for_type(Block) | ||
module_blocks = [ | ||
block | ||
for block in blocks.values() | ||
if to_qualified_name(block).startswith("prefect_airbyte") | ||
] | ||
return module_blocks | ||
|
||
|
||
@pytest.mark.parametrize("block", find_module_blocks()) | ||
class TestAllBlocksAdhereToStandards(BlockStandardTestSuite): | ||
@pytest.fixture | ||
def block(self, block): | ||
return block |