From 2c879b525ad59d035d045c9354ddee9d8f810074 Mon Sep 17 00:00:00 2001 From: Melech Lapson Date: Tue, 27 Feb 2024 11:25:18 -0600 Subject: [PATCH 01/12] added .idea to .gitignore for Pycharm --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index a4393ae2a..7c875878e 100644 --- a/.gitignore +++ b/.gitignore @@ -107,3 +107,6 @@ Qconfig.py .DS_Store /docs/stubs/ + +# Pycharm +.idea \ No newline at end of file From ff7ad87c53986afcd339889603f27d47b04010b5 Mon Sep 17 00:00:00 2001 From: Melech Lapson Date: Tue, 27 Feb 2024 11:34:55 -0600 Subject: [PATCH 02/12] switched sphinx-ext-viewcode for sphinx-ext-linkcode --- docs/conf.py | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 85 insertions(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 621a3a38d..d5eee3849 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -11,7 +11,9 @@ # that they have been altered from the originals. # -- Path setup -------------------------------------------------------------- +import inspect import os +import re import sys sys.path.insert(0, os.path.abspath('.')) @@ -34,7 +36,7 @@ 'sphinx.ext.autodoc', 'sphinx.ext.autosummary', # This is used by qiskit/documentation to generate links to github.com. - "sphinx.ext.viewcode", + "sphinx.ext.linkcode", 'jupyter_sphinx', 'sphinx_autodoc_typehints', 'reno.sphinxext', @@ -117,3 +119,85 @@ html_last_updated_fmt = '%Y/%m/%d' html_sourcelink_suffix = '' autoclass_content = 'both' + + +# ---------------------------------------------------------------------------------- +# Source code links +# ---------------------------------------------------------------------------------- + +def determine_github_branch() -> str: + """Determine the GitHub branch name to use for source code links. + + We need to decide whether to use `stable/` vs. `main` for dev builds. + Refer to https://docs.github.com/en/actions/learn-github-actions/variables + for how we determine this with GitHub Actions. + """ + # If CI env vars not set, default to `main`. This is relevant for local builds. + if ( + "GITHUB_REF_NAME" not in os.environ + and "BUILD_SOURCE_BRANCH_NAME" not in os.environ + ): + return "main" + + # PR workflows set the branch they're merging into. + if base_ref := ( + os.environ.get("GITHUB_BASE_REF") + or os.environ.get("SYSTEM_PULL_REQUEST_TARGET_BRANCH_NAME") + ): + return base_ref + + ref_name = ( + os.environ.get("GITHUB_REF_NAME") + or os.environ.get("BUILD_SOURCE_BRANCH_NAME") + ) + assert ref_name is not None + + # Check if the ref_name is a tag like `1.0.0` or `1.0.0rc1`. If so, we need + # to transform it to a Git branch like `stable/1.0`. + version_without_patch_match = re.match(r"(\d+\.\d+)", ref_name) + return ( + f"stable/{version_without_patch_match.group()}" + if version_without_patch_match + else ref_name + ) + + +GITHUB_BRANCH = determine_github_branch() + + +def linkcode_resolve(domain, info): + if domain != "py": + return None + + module_name = info["module"] + module = sys.modules.get(module_name) + if module is None or "qiskit" not in module_name: + return None + + obj = module + for part in info["fullname"].split("."): + try: + obj = getattr(obj, part) + except AttributeError: + return None + is_valid_code_object = ( + inspect.isclass(obj) or inspect.ismethod(obj) or inspect.isfunction(obj) + ) + if not is_valid_code_object: + return None + try: + full_file_name = inspect.getsourcefile(obj) + except TypeError: + return None + if full_file_name is None: + return None + file_name = full_file_name.split("/qiskit-ibm-runtime/")[-1] + + try: + source, lineno = inspect.getsourcelines(obj) + except (OSError, TypeError): + linespec = "" + else: + ending_lineno = lineno + len(source) - 1 + linespec = f"#L{lineno}-L{ending_lineno}" + return f"https://github.com/Qiskit/qiskit-ibm-runtime/tree/{GITHUB_BRANCH}/qiskit-ibm-runtime/{file_name}{linespec}" From a03ccfdf1141c9cb34606e129e37c40bb8bd8cca Mon Sep 17 00:00:00 2001 From: melechlapson Date: Tue, 27 Feb 2024 11:49:09 -0600 Subject: [PATCH 03/12] remove leftover code from Azure Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> --- docs/conf.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index d5eee3849..c2ac8e26b 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -140,10 +140,7 @@ def determine_github_branch() -> str: return "main" # PR workflows set the branch they're merging into. - if base_ref := ( - os.environ.get("GITHUB_BASE_REF") - or os.environ.get("SYSTEM_PULL_REQUEST_TARGET_BRANCH_NAME") - ): + if base_ref := os.environ.get("GITHUB_BASE_REF") return base_ref ref_name = ( From 9eb66b245eec1998ce0ac3eea001e9e29d1dce48 Mon Sep 17 00:00:00 2001 From: Melech Lapson Date: Tue, 27 Feb 2024 11:51:50 -0600 Subject: [PATCH 04/12] Update tox.ini --- tox.ini | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tox.ini b/tox.ini index f219e404e..c42394b21 100644 --- a/tox.ini +++ b/tox.ini @@ -10,6 +10,9 @@ setenv = VIRTUAL_ENV={envdir} LANGUAGE=en_US LC_ALL=en_US.utf-8 +passenv= + GITHUB_REF_NAME, + GITHUB_BASE_REF deps = -r{toxinidir}/requirements.txt -r{toxinidir}/requirements-dev.txt From b03dbb41a6eb8303342ad46d56a1071e022c3c4a Mon Sep 17 00:00:00 2001 From: melechlapson Date: Tue, 27 Feb 2024 11:52:37 -0600 Subject: [PATCH 05/12] remove leftover code from Azure part 2 Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> --- docs/conf.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index c2ac8e26b..8b67fd62d 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -143,11 +143,7 @@ def determine_github_branch() -> str: if base_ref := os.environ.get("GITHUB_BASE_REF") return base_ref - ref_name = ( - os.environ.get("GITHUB_REF_NAME") - or os.environ.get("BUILD_SOURCE_BRANCH_NAME") - ) - assert ref_name is not None + ref_name = os.environ["GITHUB_REF_NAME"] # Check if the ref_name is a tag like `1.0.0` or `1.0.0rc1`. If so, we need # to transform it to a Git branch like `stable/1.0`. From 0a35196a6acb8120dd476c54007b71c6483e5bcf Mon Sep 17 00:00:00 2001 From: melechlapson Date: Tue, 27 Feb 2024 11:53:11 -0600 Subject: [PATCH 06/12] change dashes to underscores Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 8b67fd62d..5f38780f1 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -184,7 +184,7 @@ def linkcode_resolve(domain, info): return None if full_file_name is None: return None - file_name = full_file_name.split("/qiskit-ibm-runtime/")[-1] + file_name = full_file_name.split("/qiskit_ibm_runtime/")[-1] try: source, lineno = inspect.getsourcelines(obj) From 92ad8901c306d638dc842f9471a6a57a7123b980 Mon Sep 17 00:00:00 2001 From: melechlapson Date: Tue, 27 Feb 2024 11:53:33 -0600 Subject: [PATCH 07/12] switch from qiskit to qiskit_ibm_runtime Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 5f38780f1..40f700aa2 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -164,7 +164,7 @@ def linkcode_resolve(domain, info): module_name = info["module"] module = sys.modules.get(module_name) - if module is None or "qiskit" not in module_name: + if module is None or "qiskit_ibm_runtime" not in module_name: return None obj = module From 690834cacba71dffdc74deb7a3d58aa7e0e7c227 Mon Sep 17 00:00:00 2001 From: melechlapson Date: Tue, 27 Feb 2024 11:53:56 -0600 Subject: [PATCH 08/12] remove leftover code from Azure part 3 Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> --- docs/conf.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 40f700aa2..5ab917636 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -147,10 +147,10 @@ def determine_github_branch() -> str: # Check if the ref_name is a tag like `1.0.0` or `1.0.0rc1`. If so, we need # to transform it to a Git branch like `stable/1.0`. - version_without_patch_match = re.match(r"(\d+\.\d+)", ref_name) + version_without_patch = re.match(r"(\d+\.\d+)", ref_name) return ( - f"stable/{version_without_patch_match.group()}" - if version_without_patch_match + f"stable/{version_without_patch.group()}" + if version_without_patch else ref_name ) From 83f6e7e42ff37fd07d12da4d1be3bfd99665fbef Mon Sep 17 00:00:00 2001 From: melechlapson Date: Tue, 27 Feb 2024 11:54:35 -0600 Subject: [PATCH 09/12] final updates to determine_github_branch method Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> --- docs/conf.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 5ab917636..ef2a751fd 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -133,10 +133,7 @@ def determine_github_branch() -> str: for how we determine this with GitHub Actions. """ # If CI env vars not set, default to `main`. This is relevant for local builds. - if ( - "GITHUB_REF_NAME" not in os.environ - and "BUILD_SOURCE_BRANCH_NAME" not in os.environ - ): + if "GITHUB_REF_NAME" not in os.environ: return "main" # PR workflows set the branch they're merging into. From c4c69ca5cfc174db84b4b98179b76ed04fb493f2 Mon Sep 17 00:00:00 2001 From: melechlapson Date: Tue, 27 Feb 2024 11:55:01 -0600 Subject: [PATCH 10/12] cha Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index ef2a751fd..3ec000b04 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -190,4 +190,4 @@ def linkcode_resolve(domain, info): else: ending_lineno = lineno + len(source) - 1 linespec = f"#L{lineno}-L{ending_lineno}" - return f"https://github.com/Qiskit/qiskit-ibm-runtime/tree/{GITHUB_BRANCH}/qiskit-ibm-runtime/{file_name}{linespec}" + return f"https://github.com/Qiskit/qiskit-ibm-runtime/tree/{GITHUB_BRANCH}/qiskit_ibm_runtime/{file_name}{linespec}" From f734053c554fac089eb94758d140d837ecfc9838 Mon Sep 17 00:00:00 2001 From: Melech Lapson Date: Tue, 27 Feb 2024 11:57:23 -0600 Subject: [PATCH 11/12] added colon --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 3ec000b04..86ad44d82 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -137,7 +137,7 @@ def determine_github_branch() -> str: return "main" # PR workflows set the branch they're merging into. - if base_ref := os.environ.get("GITHUB_BASE_REF") + if base_ref := os.environ.get("GITHUB_BASE_REF"): return base_ref ref_name = os.environ["GITHUB_REF_NAME"] From 51f8d18036ad767bbd2305b8a78ed6ee6e4866de Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Tue, 27 Feb 2024 16:32:09 -0500 Subject: [PATCH 12/12] Fix issue with inherited methods --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 86ad44d82..08a28ec2e 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -179,7 +179,7 @@ def linkcode_resolve(domain, info): full_file_name = inspect.getsourcefile(obj) except TypeError: return None - if full_file_name is None: + if full_file_name is None or "/qiskit_ibm_runtime/" not in full_file_name: return None file_name = full_file_name.split("/qiskit_ibm_runtime/")[-1]