Closed coderabbitai[bot] closed 1 month ago
@coderabbitai,
linkcode_resolve
function with configuration option/function to specify the branch), complete with possible implementation of changes to code (ie, the 'how'), we'll call this the "plan draft"[!TIP] For best results, initiate chat on the files or code changes.
@reactive-firewall,
Improved Plan for Implementing Issue #113
Objective: Make the branch name in the linkcode_resolve
function of docs/conf.py
dynamic, allowing for better maintainability and portability.
Add at the top of docs/conf.py
:
import os
# Define the branch name for linkcode_resolve
linkcode_branch = os.environ.get("LINKCODE_BRANCH", "stable")
"""
linkcode_branch: The name of the branch used in the GitHub links generated by the linkcode_resolve function.
Defaults to 'stable', but can be overridden by setting the LINKCODE_BRANCH environment variable.
"""
linkcode_branch
to the value of the LINKCODE_BRANCH
environment variable if it exists; otherwise, it defaults to "stable"
.linkcode_resolve
Function to Use the Configuration VariableUpdate the linkcode_resolve
function:
def linkcode_resolve(domain, info):
"""
Resolve the GitHub URL corresponding to the Python object.
Parameters:
domain (str): The domain of the object (e.g., 'py' for Python).
info (dict): Information about the object.
Returns:
str or None: The GitHub URL pointing to the source code, or None if not applicable.
"""
if domain != "py" or not info["module"]:
return None
filename = info["module"].replace(".", "/")
theResult = "{prefix}/blob/{branch}/{file}.py".format(
prefix=linkcode_url_prefix, branch=linkcode_branch, file=filename
)
if "/multicast.py" in theResult:
theResult = theResult.replace("/multicast.py", "/multicast/__init__.py")
if "/tests.py" in theResult:
theResult = theResult.replace("/tests.py", "/tests/__init__.py")
return theResult
"stable"
with the linkcode_branch
variable.Leverage Environment Variables:
os.environ.get()
allows users to set the branch dynamically without modifying the code.Default Behavior:
"stable"
maintains current behavior if no environment variable is set.Document the New Configuration Option:
README.md
or appropriate documentation files about LINKCODE_BRANCH
.### Building Documentation with Custom Branch Links
By default, the documentation links to the `stable` branch on GitHub. To override this, set the `LINKCODE_BRANCH` environment variable:
```bash
export LINKCODE_BRANCH="your-branch-name"
make html # or your documentation build command
Verify Default Behavior:
LINKCODE_BRANCH
and ensure links point to the stable
branch.Verify Custom Branch Behavior:
LINKCODE_BRANCH
to a different branch name and rebuild.Ensure No Breakages:
This improved plan aligns with the project's coding standards and emphasizes:
Code Style and Conventions:
Maintainability:
Portability:
Documentation:
Please review the plan and let me know if you have any suggestions or require further adjustments.
🤔 First, this plan makes sense! Let's go with this. 🔧 Second, a couple of tweaks:
GITHUB_SHA
(for GHA) and CIRCLE_SHA1
(for CircleCI)DOCS_BUILD_REF=$(${GIT:-git} rev-parse --verify HEAD)
as it shows how to dynamically set the value (for example if done by a git-hook locally)Refs:
@coderabbitai, please read up on the recent updates to this issue and relevant code, and regenerate your improved plan to bring this issue back up to date.
[!TIP] For best results, initiate chat on the files or code changes.
@reactive-firewall,
I've reviewed the recent updates to Issue #113 and the relevant code. Here is the updated plan incorporating your suggestions:
Updated Plan for Implementing Issue #113
Objective: Make the branch reference in the linkcode_resolve
function of docs/conf.py
dynamic, enhancing maintainability, portability, and aligning with CI environment variables.
At the top of docs/conf.py
, add:
import os
# Define the branch reference for linkcode_resolve
DOCS_BUILD_REF = os.environ.get("DOCS_BUILD_REF", "stable")
"""
DOCS_BUILD_REF: The Git reference (commit hash or branch name) used in the GitHub links generated by the linkcode_resolve function.
Defaults to 'stable', but can be overridden by setting the DOCS_BUILD_REF environment variable.
"""
DOCS_BUILD_REF
to the value of the DOCS_BUILD_REF
environment variable if it exists; otherwise, defaults to "stable"
.linkcode_resolve
Function to Use DOCS_BUILD_REF
Update the linkcode_resolve
function:
def linkcode_resolve(domain, info):
"""
Resolve the GitHub URL corresponding to the Python object.
Parameters:
domain (str): The domain of the object (e.g., 'py' for Python).
info (dict): Information about the object.
Returns:
str or None: The GitHub URL pointing to the source code, or None if not applicable.
"""
if domain != "py" or not info["module"]:
return None
filename = info["module"].replace(".", "/")
theResult = "{prefix}/blob/{ref}/{file}.py".format(
prefix=linkcode_url_prefix, ref=DOCS_BUILD_REF, file=filename
)
if "/multicast.py" in theResult:
theResult = theResult.replace("/multicast.py", "/multicast/__init__.py")
if "/tests.py" in theResult:
theResult = theResult.replace("/tests.py", "/tests/__init__.py")
return theResult
"stable"
with DOCS_BUILD_REF
.DOCS_BUILD_REF
For GitHub Actions (GHA):
.github/workflows/ci.yml
):jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set DOCS_BUILD_REF
run: echo "DOCS_BUILD_REF=${GITHUB_SHA}" >> $GITHUB_ENV
- name: Build Documentation
env:
DOCS_BUILD_REF: ${{ env.DOCS_BUILD_REF }}
run: make html # or your documentation build command
DOCS_BUILD_REF
from GITHUB_SHA
, which is the commit hash of the current build.For CircleCI:
.circleci/config.yml
):jobs:
build:
docker:
- image: cimg/python:3.9 # Or your preferred image
steps:
- checkout
- run:
name: Set DOCS_BUILD_REF
command: |
echo 'export DOCS_BUILD_REF=${CIRCLE_SHA1}' >> $BASH_ENV
source $BASH_ENV
- run:
name: Build Documentation
command: |
make html # or your documentation build command
DOCS_BUILD_REF
using CIRCLE_SHA1
, the commit hash for the build.In your documentation (e.g., README.md
):
### Building Documentation with a Custom Git Reference
By default, the documentation links to the `stable` branch on GitHub. To override this and link to the specific commit you're working on, set the `DOCS_BUILD_REF` environment variable:
```bash
export DOCS_BUILD_REF=$(${GIT:-git} rev-parse --verify HEAD)
make html # or your documentation build command
This command dynamically sets DOCS_BUILD_REF
to the current Git commit hash, ensuring that documentation links point to the exact version of your code.
Ensure that all scripts or commands that build the documentation in CI environments are using the updated DOCS_BUILD_REF
variable.
Leverage Environment Variables from CI Systems:
GITHUB_SHA
and CIRCLE_SHA1
) ensures that the documentation reflects the exact state of the code at each commit.Default Behavior:
"stable"
maintains the current behavior for environments where DOCS_BUILD_REF
is not set, ensuring backward compatibility.Verify Default Behavior:
DOCS_BUILD_REF
to ensure links point to the stable
branch.Verify CI Integration:
DOCS_BUILD_REF
is correctly set to the commit hash and that documentation links are accurate.Verify Local Builds:
DOCS_BUILD_REF
properly and that links in the documentation point to the local commit hash.Check for Breakages:
This updated plan implements your suggestions and focuses on:
Code Style and Conventions:
Maintainability:
Portability:
Documentation:
Please review the updated plan and let me know if there are any additional changes or considerations.
The branch name "stable" is hardcoded in the
linkcode_resolve
function indocs/conf.py
. To enhance maintainability, consider using a variable or configuration option to specify the branch.See PR #110: https://github.com/reactive-firewall/multicast/pull/110 and the specific comment: https://github.com/reactive-firewall/multicast/pull/110#discussion_r1764390519 for more details.
Reported by @reactive-firewall.