-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* specify public API and map shallow to deep imports * fix docs * replaced deep with shallow imports * fix doc * see if building docs under 3.11 fixes things * remove things from root namespace that should be used as `config.*` * remove types from public api that should be used as `types.*` * allow `__api__` to subset override `__all__` for api pattern in config * add autogenerated public API * install repo for Python to locate bsb * fix empty line diff
- Loading branch information
Showing
125 changed files
with
1,244 additions
and
370 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,55 @@ | ||
import difflib | ||
import sys | ||
from pathlib import Path | ||
|
||
from bsb import _get_public_api_map | ||
|
||
|
||
def public_annotations(): | ||
annotations = [] | ||
for api, module in _get_public_api_map().items(): | ||
annotation = f'"bsb.{module}.{api}"' | ||
if api[0].isupper(): | ||
annotation = f"typing.Type[{annotation}]" | ||
annotations.append(f"{api}: {annotation}") | ||
|
||
lines = [ | ||
"if typing.TYPE_CHECKING:", | ||
*sorted(f" import bsb.{module}" for module in {*_get_public_api_map().values()}), | ||
"", | ||
*sorted(annotations), | ||
"", | ||
] | ||
|
||
return lines | ||
|
||
|
||
if __name__ == "__main__": | ||
import bsb | ||
|
||
path = Path(bsb.__path__[0]) / "__init__.py" | ||
text = path.read_text() | ||
find = ( | ||
"# Do not modify: autogenerated public API type annotations of the `bsb` module\n" | ||
"# fmt: off\n" | ||
"# isort: off\n" | ||
) | ||
idx = text.find(find) | ||
annotation_lines = public_annotations() | ||
if idx == -1: | ||
print("__init__.py file is missing the replacement tag", file=sys.stderr) | ||
exit(1) | ||
if "--check" in sys.argv: | ||
diff = "\n".join( | ||
l | ||
for l in difflib.ndiff( | ||
text[idx + len(find) :].split("\n"), | ||
annotation_lines, | ||
) | ||
if l[0] != " " | ||
) | ||
print(diff, file=sys.stderr, end="") | ||
exit(bool(diff)) | ||
else: | ||
text = text[:idx] + find + "\n".join(annotation_lines) | ||
path.write_text(text) |
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,21 @@ | ||
name: Check public API | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
check-documentation: | ||
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python 3.11 | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: 3.11 | ||
- name: Setup Python environment | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -e . | ||
- name: Check public API | ||
run: python .github/devops/generate_public_api.py --check |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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,5 +1,9 @@ | ||
# isort: off | ||
# Load module before others to prevent partially initialized modules | ||
from .strategy import ConnectionStrategy | ||
|
||
# isort: on | ||
from .detailed import * | ||
from .detailed.fiber_intersection import FiberTransform, QuiverTransform | ||
from .general import * | ||
from .import_ import CsvImportConnectivity | ||
from .strategy import ConnectionStrategy |
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,19 +1,3 @@ | ||
import inspect | ||
import os | ||
from glob import glob | ||
from importlib import import_module | ||
|
||
from ..strategy import ConnectionStrategy | ||
|
||
# Scan the whole directory for python files, then import any ConnectionStrategies into | ||
# this module. | ||
src_files = glob(os.path.join(os.path.dirname(__file__), "*.py")) | ||
exclude_src = ["__init__"] | ||
for src_file in src_files: | ||
module_name = os.path.basename(src_file).split(".")[0] | ||
if module_name in exclude_src: | ||
continue | ||
module = import_module("." + module_name, __package__) | ||
for name, obj in module.__dict__.items(): | ||
if inspect.isclass(obj) and issubclass(obj, ConnectionStrategy): | ||
globals()[name] = obj | ||
from .fiber_intersection import FiberIntersection | ||
from .touch_detection import TouchDetector | ||
from .voxel_intersection import VoxelIntersection |
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
Oops, something went wrong.