-
Notifications
You must be signed in to change notification settings - Fork 0
docs: implement dynamic API docs, standardize configurations, and prep 0.1.2 release #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,76 @@ | ||
| # noqa: INP001 | ||
| """ | ||
| Generate the code reference pages and navigation. | ||
|
|
||
| This module automates the creation of API reference documentation. It leverages the | ||
| ``mkdocs-gen-files`` plugin to traverse the ``src/`` directory, generating Markdown | ||
| pages for each Python module and constructing a unified navigation structure. This | ||
| ensures the project's codebase remains fully documented and accessible. | ||
| """ | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import mkdocs_gen_files | ||
|
|
||
| __all__ = ["generate_api_reference"] | ||
|
|
||
|
|
||
| def generate_api_reference() -> None: | ||
| """ | ||
| Generate the API reference documentation and navigation structure. | ||
|
|
||
| Iterates through all Python source files in the ``src/`` directory, converting | ||
| their paths into a logical documentation structure. It generates Markdown files | ||
| with appropriate directives to render the API, and produces a literate navigation | ||
| summary. | ||
|
|
||
| Example: | ||
| This function is executed directly when the script is run: | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| generate_api_reference() | ||
|
|
||
| :return: None | ||
| """ | ||
| navigation = mkdocs_gen_files.Nav() | ||
| root_directory = Path(__file__).parent.parent.parent | ||
| source_directory = root_directory / "src" | ||
| api_reference_path = Path("reference/api") | ||
|
|
||
| for python_file in sorted(source_directory.rglob("*.py")): | ||
| module_path = python_file.relative_to(source_directory).with_suffix("") | ||
| document_path = python_file.relative_to(source_directory).with_suffix(".md") | ||
| full_document_path = api_reference_path / document_path | ||
|
|
||
| path_parts = tuple(module_path.parts) | ||
|
|
||
| if path_parts[-1] == "__init__": | ||
| path_parts = path_parts[:-1] | ||
| document_path = document_path.with_name("index.md") | ||
| full_document_path = full_document_path.with_name("index.md") | ||
| elif path_parts[-1] == "__main__": | ||
| continue | ||
|
|
||
| if not path_parts: | ||
| continue | ||
|
|
||
| navigation[path_parts] = document_path.as_posix() | ||
|
|
||
| with mkdocs_gen_files.open(full_document_path, "w") as document_file: | ||
| identifier = ".".join(path_parts) | ||
| document_file.write( | ||
| f"::: {identifier}\n" | ||
| " options:\n" | ||
| " show_root_heading: true\n" | ||
| " show_source: true\n" | ||
| ) | ||
|
|
||
| mkdocs_gen_files.set_edit_path(full_document_path, python_file) | ||
|
|
||
| summary_file_path = api_reference_path / "SUMMARY.md" | ||
| with mkdocs_gen_files.open(summary_file_path, "w") as navigation_file: | ||
| navigation_file.writelines(navigation.build_literate_nav()) | ||
|
|
||
|
|
||
| generate_api_reference() |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,84 @@ | ||
| # Testing Guide | ||
|
|
||
| This directory contains the testing suite for `gitversioned`. We use `pytest` as our testing framework and `hatch` to manage test environments and execution. | ||
|
|
||
| ## Test Tiers | ||
|
|
||
| Tests are categorized into three distinct tiers, each located in its respective subdirectory: | ||
|
|
||
| | Test Tier | Directory | Description | | ||
| | :-------------- | :------------------- | :------------------------------------------------------------------------------------------------------------------------ | | ||
| | **Unit** | `tests/unit/` | Fast, isolated tests for individual functions and classes. These tests should not rely on external services or databases. | | ||
| | **Integration** | `tests/integration/` | Slower tests that verify interactions between multiple components or modules within the application. | | ||
| | **End-to-End** | `tests/e2e/` | Full-stack tests simulating real user workflows, from entry points to expected outcomes. | | ||
|
|
||
| ## Pytest Markers | ||
|
|
||
| We use custom `pytest` markers to categorize test scope and intent. Every test should be decorated with appropriate markers. | ||
|
|
||
| | Marker | Purpose | Example Use Case | | ||
| | :------------------------ | :-------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------- | | ||
| | `@pytest.mark.smoke` | Quick tests to check basic functionality. | A crucial happy-path test that must pass for the system to be considered fundamentally operational. | | ||
| | `@pytest.mark.sanity` | Detailed tests to ensure major functions work correctly. | Testing key business logic and typical user flows. | | ||
| | `@pytest.mark.regression` | Tests to ensure that new changes do not break existing functionality. | Tests written specifically to prevent known bugs from reoccurring. | | ||
|
|
||
| > [!NOTE] | ||
| > Every test should be decorated with one of the above markers to indicate its role in the testing pipeline. | ||
|
|
||
| ## Running Tests | ||
|
|
||
| We recommend using `hatch` to run tests, as it automatically manages the required virtual environments and dependencies. | ||
|
|
||
| ### Standard Test Runs | ||
|
|
||
| ```bash | ||
| # Run all tests | ||
| hatch run test:all | ||
|
|
||
| # Run only unit tests | ||
| hatch run test:unit | ||
|
|
||
| # Run tests with a specific marker | ||
| hatch run test:all -m "smoke" | ||
|
|
||
| # Run tests in a specific file | ||
| hatch run test:all tests/unit/test_version.py | ||
| ``` | ||
|
|
||
| ### Coverage Reports | ||
|
|
||
| To generate coverage reports, use the `-cov` suffixed commands. These will output both a terminal report and an HTML report located in `docs/coverage/`. | ||
|
|
||
| ```bash | ||
| # Run all tests with coverage | ||
| hatch run test:all-cov | ||
|
|
||
| # Run only unit tests with coverage | ||
| hatch run test:unit-cov | ||
| ``` | ||
|
|
||
| ## Adding New Tests | ||
|
|
||
| When creating new tests, ensure they are placed in the appropriate tier directory (`unit/`, `integration/`, or `e2e/`) and include the necessary markers. | ||
|
|
||
| ### Example Unit Test | ||
|
|
||
| ```python | ||
| """Unit tests for my_module.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import pytest | ||
|
|
||
| from gitversioned import my_module | ||
|
|
||
|
|
||
| @pytest.mark.smoke | ||
| def test_my_function() -> None: | ||
| """Verify my_function behaves as expected.""" | ||
| result = my_module.my_function() | ||
| assert result is True | ||
| ``` | ||
|
|
||
| > [!TIP] | ||
| > **Type Hints:** Ensure all test functions are fully type-hinted (e.g., `-> None:` for test return types) to satisfy our strict `mypy` configuration. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.