Skip to content

armgit / burr

Public Imported from GitHub
0

Build applications that make decisions (chatbots, agents, simulations, etc...). Monitor, trace, persist, and execute on your own infrastructure.

All examples must adhere to a strict format. We'll be adding a directory with "unstructured" examples that don't adhere.

elijahbenizzyb33940039492
diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml
index 106c2bc8..5726a6c8 100644
--- a/.github/workflows/python-package.yml
+++ b/.github/workflows/python-package.yml
@@ -37,3 +37,16 @@ jobs:
- name: Run tests
run: |
python -m pytest tests
+
+ validate-examples:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v3
+ - uses: actions/setup-python@v3
+ - name: Install dependencies
+ run: |
+ python -m pip install -e ".[tests]"
+ - name: Validate examples
+ working-directory: ./examples
+ run: |
+ python -m pytest validate_examples.py
diff --git a/docs/contributing/contributing.rst b/docs/contributing/contributing.rst
index d2785199..a0f955ce 100644
--- a/docs/contributing/contributing.rst
+++ b/docs/contributing/contributing.rst
@@ -22,6 +22,17 @@ Please:
#. Ensure all new features have tests
#. Add documentation for new features
+Examples
+--------
+
+All examples must have the following files:
+1. A ``README.md`` file that describes the example -- this should follow the pattern of the others
+2. A ``requirements.txt`` file that lists the dependencies for the example
+3. An ``application.py`` file whose mainline runs a simple version of the example + generates the DAG to
+4. A ``statemachine.png`` file that shows the DAG for the example
+3. A `notebook.ipynb` file that uses the example in a
+
+The ``notebook.ipynb`` can import stuff from the ``application.py``, or redefine it as an example.
---------------
Developer notes
diff --git a/examples/validate_examples.py b/examples/validate_examples.py
new file mode 100644
index 00000000..0d76a5ac
--- /dev/null
+++ b/examples/validate_examples.py
@@ -0,0 +1,60 @@
+import os
+
+# hardcoded to work in current directory for now, but we can easily change
+EXAMPLES_DIR = "."
+
+# Required files for each example
+REQUIRED_FILES = [
+ "notebook.ipynb",
+ "application.py",
+ "README.md",
+ "statemachine.png",
+ "__init__.py", # included as we want them all to be importable
+]
+
+
+FILTERLIST = ["half-baked", "ml-training"]
+
+def should_validate(directory: str) -> bool:
+ """Return True if the given directory is an example directory."""
+ return (
+ os.path.isdir(os.path.join(EXAMPLES_DIR, directory))
+ and not directory.startswith(".")
+ and not directory.startswith("_")
+ and directory not in FILTERLIST
+ )
+
+
+def get_directories(base_path: str) -> list[str]:
+ """Return a list of directories under the given base_path."""
+ return [d for d in os.listdir(base_path) if should_validate(d)]
+
+
+def check_files_exist(directory, files):
+ """Check if each file in 'files' exists in 'directory'."""
+ missing_files = []
+ for file in files:
+ if not os.path.exists(os.path.join(EXAMPLES_DIR, directory, file)):
+ missing_files.append(file)
+ return missing_files
+
+
+# Use pytest_generate_tests to dynamically parameterize the fixture
+def pytest_generate_tests(metafunc):
+ # if "directory" in metafunc.fixturenames:
+ directories = get_directories(EXAMPLES_DIR)
+ metafunc.parametrize("directory", directories, scope="module")
+
+
+def test_directory_name(directory):
+ if "_" in directory:
+ assert (
+ False
+ ), f"Example Directory '{directory}' should not contain underscores, only dashes!."
+
+
+def test_directory_contents(directory):
+ missing_files = check_files_exist(directory, REQUIRED_FILES)
+ assert (
+ not missing_files
+ ), f"Missing files in example dir '{directory}': {', '.join(missing_files)}"