From 94de48cae66bd6b5d199837708679694add55826 Mon Sep 17 00:00:00 2001 From: Pablo Perez Piskunow Date: Sat, 25 Nov 2023 08:20:38 +0100 Subject: [PATCH 1/4] Hotfix/api docs (#36) * fix api link * mock import kwant --- README.md | 2 +- docs/conf.py | 1 + noxfile.py | 6 ------ 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e51718a..0a2cf75 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ $ pip install kpm-tools ## Python API -Please see the [Python API reference] for details. +Please see the [python api reference] for details. ## Contributing diff --git a/docs/conf.py b/docs/conf.py index 1fcc385..5ed17c3 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -8,6 +8,7 @@ project = "KPM Tools" author = "Pablo Piskunow" copyright = "2023, Pablo Piskunow" +autodoc_mock_imports = ["kwant"] extensions = [ "sphinx.ext.autodoc", "sphinx.ext.napoleon", diff --git a/noxfile.py b/noxfile.py index a13536d..130d2be 100644 --- a/noxfile.py +++ b/noxfile.py @@ -276,9 +276,6 @@ def docs_build(session: Session) -> None: "sphinx", "sphinx-click", "nbsphinx", "pandoc", "furo", "myst-parser" ) - # Call the kwant installation functions - build_kwant(session) - build_dir = Path("docs", "_build") if build_dir.exists(): shutil.rmtree(build_dir) @@ -302,9 +299,6 @@ def docs(session: Session) -> None: "pandoc", ) - # Call the kwant installation functions - build_kwant(session) - build_dir = Path("docs", "_build") if build_dir.exists(): shutil.rmtree(build_dir) From 15f4dd5b7b2a3ac3e0e395fc66271bdb6551a90c Mon Sep 17 00:00:00 2001 From: Pablo Perez Piskunow Date: Sat, 25 Nov 2023 08:42:02 +0100 Subject: [PATCH 2/4] fix linkcode (#37) --- docs/conf.py | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 5ed17c3..4f92084 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,7 +1,6 @@ """Sphinx configuration.""" import inspect -import os import sys @@ -47,40 +46,37 @@ def linkcode_resolve(domain, info): - """Resolve links to source.""" + """Parse links to source.""" if domain != "py": return None if not info["module"]: return None - # Replace with your project's GitHub repository URL github_repo = "https://github.com/piskunow/kpm-tools" - # Get the module object module = sys.modules.get(info["module"]) if module is None: return None - # Get the source file path of the module - filename = inspect.getsourcefile(module) - if filename is None: - return None - - # Trim the filename to a path relative to the project root - rel_fn = os.path.relpath(filename, start=os.path.dirname(__file__)) - - # Get the line number of the object within the module - obj = module - for part in info["fullname"].split("."): - obj = getattr(obj, part, None) - - if obj is None: - return None - try: - lines, _ = inspect.getsourcelines(obj) - except Exception: + filename = inspect.getsourcefile(module) + if filename is None: + return None + + # Assuming your package is installed in 'site-packages' + # and the source is in 'src/kpm_tools' in the repo + src_path = filename.split("site-packages")[1] + rel_fn = "src" + src_path + + obj = module + for part in info["fullname"].split("."): + obj = getattr(obj, part, None) + + if obj is None: + return None + + line = inspect.getsourcelines(obj)[1] + return f"{github_repo}/blob/develop/{rel_fn}#L{line}" + except Exception as e: + print(f"Error generating linkcode URL for {info['module']}: {e}") return None - - line = inspect.getsourcelines(obj)[1] - return f"{github_repo}/blob/main/{rel_fn}#L{line}" From cf7195286e52b0a3db35b6c31c37628b6fd9dc62 Mon Sep 17 00:00:00 2001 From: Pablo Perez Piskunow Date: Sat, 25 Nov 2023 08:50:35 +0100 Subject: [PATCH 3/4] resolve branch (#38) --- docs/conf.py | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 4f92084..b6ce2da 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,6 +1,7 @@ """Sphinx configuration.""" import inspect +import os import sys @@ -46,37 +47,39 @@ def linkcode_resolve(domain, info): - """Parse links to source.""" + """Resolve and link to source.""" if domain != "py": return None if not info["module"]: return None + # Determine the branch based on RTD version + rtd_version = os.getenv("READTHEDOCS_VERSION", "latest") + github_branch = "develop" if rtd_version == "latest" else "main" + github_repo = "https://github.com/piskunow/kpm-tools" module = sys.modules.get(info["module"]) if module is None: return None - try: - filename = inspect.getsourcefile(module) - if filename is None: - return None + filename = inspect.getsourcefile(module) + if filename is None: + return None - # Assuming your package is installed in 'site-packages' - # and the source is in 'src/kpm_tools' in the repo - src_path = filename.split("site-packages")[1] - rel_fn = "src" + src_path + # Adjust the file path for the repository structure + package_dir = "src/kpm_tools" + rel_fn = os.path.relpath(filename, start=os.path.dirname(package_dir)) - obj = module - for part in info["fullname"].split("."): - obj = getattr(obj, part, None) + obj = module + for part in info["fullname"].split("."): + obj = getattr(obj, part, None) - if obj is None: - return None + if obj is None: + return None + try: line = inspect.getsourcelines(obj)[1] - return f"{github_repo}/blob/develop/{rel_fn}#L{line}" - except Exception as e: - print(f"Error generating linkcode URL for {info['module']}: {e}") + return f"{github_repo}/blob/{github_branch}/{rel_fn}#L{line}" + except Exception: return None From c4114610318f1c0527bacf5b629979c46495e09a Mon Sep 17 00:00:00 2001 From: Pablo Piskunow Date: Sat, 25 Nov 2023 08:59:07 +0100 Subject: [PATCH 4/4] bump patch version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 14aa962..6209964 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "kpm-tools" -version = "0.0.2" +version = "0.0.3" description = "KPM Tools" authors = ["Pablo Piskunow "] license = "BSD 2-Clause"