-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into publish-workflow
- Loading branch information
Showing
32 changed files
with
595 additions
and
377 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[*] | ||
end_of_line = lf | ||
|
||
[*.cmd] | ||
end_of_line = crlf |
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,9 @@ | ||
# By default, convert line endings automatically. | ||
* text=auto | ||
|
||
# Declare files that will always have LF line endings on checkout. | ||
*.py text eol=lf | ||
*.sh text eol=lf | ||
|
||
# Declare files that will always have CRLF line endings on checkout. | ||
*.cmd text eol=crlf |
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,23 @@ | ||
name: Lint with MyPy | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
mypy: | ||
timeout-minutes: 10 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: 3.11 | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install -c ci-constraints.txt . -r mypy-requirements.txt -r test-requirements.txt | ||
- name: Run MyPy | ||
run: | | ||
mypy . |
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,31 @@ | ||
name: Test | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
test: | ||
timeout-minutes: 120 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
timeout-minutes: 10 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: 3.11 | ||
timeout-minutes: 10 | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install -c ci-constraints.txt -r test-requirements.txt . | ||
timeout-minutes: 10 | ||
|
||
- name: Test | ||
run: | | ||
python -m unittest | ||
timeout-minutes: 60 |
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,3 +1,51 @@ | ||
# mkdocstrings-vba | ||
|
||
A VBA handler for [mkdocstrings](https://github.com/mkdocstrings/mkdocstrings). | ||
|
||
Since there is no official way of documenting VBA functions, we have opted for | ||
the [Google Docstring format](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) commonly used | ||
in Python projects. This is conveniently parsed by the [`griffe`](https://mkdocstrings.github.io/griffe) library which | ||
is also used by [`mkdocstrings[python]`](https://mkdocstrings.github.io/python/). The argument types and return types | ||
are taken from the | ||
VBA [Function](https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/function-statement) | ||
or [Sub](https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/sub-statement) signatures, | ||
which we parse using [regex](https://regular-expressions.info). | ||
|
||
## Examples | ||
|
||
See the [`examples`](examples) folder. | ||
|
||
To build an example site: | ||
|
||
1. `pip install mkdocstrings mkdocstrings-vba` | ||
2. `cd examples/example1` | ||
3. View the source code. | ||
4. `mkdocs build` | ||
5. cd `site/` | ||
6. View the results. | ||
|
||
## Running tests | ||
|
||
```shell | ||
pip install -r test-requirements.txt | ||
python -m unittest | ||
``` | ||
|
||
This will run all tests. This includes | ||
- Unit tests from `tests/`. | ||
- Doctests from `mkdocstrings_vba/`. | ||
- Full builds from `examples/`. | ||
|
||
## Linting | ||
|
||
Fix code style using `black`: | ||
|
||
```shell | ||
black . | ||
``` | ||
|
||
Check types using `mypy`: | ||
|
||
```shell | ||
mypy . | ||
``` |
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,3 @@ | ||
mkdocstrings==0.22.0 | ||
griffe==0.34.0 | ||
mkdocs-material==9.2.1 |
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
|
@@ -6,4 +6,3 @@ plugins: | |
- mkdocstrings: | ||
handlers: | ||
vba: { } | ||
python: { } |
File renamed without changes.
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
Empty file.
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,5 @@ | ||
"""This package implements a handler for the VBA language.""" | ||
|
||
from mkdocstrings_handlers.vba.handler import get_handler | ||
from ._handler import get_handler | ||
|
||
__all__ = ["get_handler"] |
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,50 @@ | ||
import re | ||
|
||
from markupsafe import Markup | ||
|
||
|
||
def do_crossref(path: str, brief: bool = True) -> Markup: | ||
"""Filter to create cross-references. | ||
Parameters: | ||
path: The path to link to. | ||
brief: Show only the last part of the path, add the full path as hover. | ||
Returns: | ||
Markup text. | ||
""" | ||
full_path = path | ||
if brief: | ||
path = full_path.split(".")[-1] | ||
return Markup( | ||
"<span data-autorefs-optional-hover={full_path}>{path}</span>" | ||
).format(full_path=full_path, path=path) | ||
|
||
|
||
def do_multi_crossref(text: str, code: bool = True) -> Markup: | ||
"""Filter to create cross-references. | ||
Parameters: | ||
text: The text to scan. | ||
code: Whether to wrap the result in a code tag. | ||
Returns: | ||
Markup text. | ||
""" | ||
group_number = 0 | ||
variables = {} | ||
|
||
def repl(match: re.Match[str]) -> str: | ||
nonlocal group_number | ||
group_number += 1 | ||
path = match.group() | ||
path_var = f"path{group_number}" | ||
variables[path_var] = path | ||
return ( | ||
f"<span data-autorefs-optional-hover={{{path_var}}}>{{{path_var}}}</span>" | ||
) | ||
|
||
text = re.sub(r"([\w.]+)", repl, text) | ||
if code: | ||
text = f"<code>{text}</code>" | ||
return Markup(text).format(**variables) |
Oops, something went wrong.