-
Notifications
You must be signed in to change notification settings - Fork 38
Python SDK: Adds section on optional dependencies #1906
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ngrayluna
wants to merge
16
commits into
main
Choose a base branch
from
sdk_optional_dependencies
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
2039e1b
first draft
ngrayluna f882f60
Added links to packages
ngrayluna 9036a95
removed layer of section hearders
ngrayluna dfc0840
some feedback
ngrayluna 804f106
removed launch
ngrayluna 3b1911c
minor edits
ngrayluna e88ba1f
remove kubeflow
ngrayluna 8fa94f9
added scripts to generate table
ngrayluna a948edd
workflow in the docs repo that receives the dispatch event from wandb
ngrayluna 3f702a2
remove redundant line
ngrayluna f8e40f2
Cleaning up script
ngrayluna 147d73f
Updated scripts
ngrayluna d860ff5
removed snippet
ngrayluna 4187551
Update text
ngrayluna ef086c6
remove extra spacing
ngrayluna 7e9c8df
Added small blurb
ngrayluna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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,111 @@ | ||
| name: Update SDK Extras Documentation | ||
|
|
||
| on: | ||
| repository_dispatch: | ||
| types: [pyproject-updated] | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| update-sdk-extras: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout docs repository | ||
| uses: actions/checkout@v5 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Checkout wandb repository | ||
| uses: actions/checkout@v5 | ||
| with: | ||
| repository: wandb/wandb | ||
| path: wandb-repo | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v6 | ||
| with: | ||
| python-version: '3.11' | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| pip install tomli | ||
|
|
||
| - name: Generate timestamp | ||
| id: timestamp | ||
| run: | | ||
| TIMESTAMP=$(date -u +"%Y-%m-%d %H:%M:%S UTC") | ||
| echo "timestamp=${TIMESTAMP}" >> $GITHUB_OUTPUT | ||
| echo "Generated at: ${TIMESTAMP}" | ||
|
|
||
| - name: Copy pyproject.toml to scripts directory | ||
| run: | | ||
| echo "Copying wandb/pyproject.toml to scripts/" | ||
| cp wandb-repo/pyproject.toml scripts/pyproject.toml | ||
| echo "✅ File copied successfully" | ||
|
|
||
| - name: Generate SDK Extras Table | ||
| run: | | ||
| echo "Generating SDK extras table from pyproject.toml..." | ||
| cd scripts | ||
| python generate_sdk_extras_table.py | ||
| echo "✅ SDK extras table generated" | ||
|
|
||
| - name: Check for changes | ||
| id: check-changes | ||
| run: | | ||
| if [ -n "$(git status --porcelain)" ]; then | ||
| echo "has_changes=true" >> $GITHUB_OUTPUT | ||
| echo "Changes detected in python-sdk-extras.mdx" | ||
| git diff snippets/en/_includes/python-sdk-extras.mdx | ||
| else | ||
| echo "has_changes=false" >> $GITHUB_OUTPUT | ||
| echo "No changes detected" | ||
| fi | ||
|
|
||
| - name: Create Pull Request | ||
| if: steps.check-changes.outputs.has_changes == 'true' | ||
| id: create-pr | ||
| uses: peter-evans/create-pull-request@v7 | ||
| with: | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
| commit-message: "chore: Update SDK extras documentation" | ||
| title: "Update SDK extras documentation from pyproject.toml" | ||
| draft: false | ||
| body: | | ||
| This PR updates the SDK extras documentation based on the latest `wandb/pyproject.toml` configuration. | ||
|
|
||
| **Generated on**: ${{ steps.timestamp.outputs.timestamp }} | ||
| **Source**: `wandb/wandb` repository `pyproject.toml` | ||
| **Triggered by**: Repository dispatch event from wandb/wandb | ||
|
|
||
| ### Changes | ||
| - Synced latest optional dependencies from wandb package | ||
| - Updated SDK extras table in documentation | ||
|
|
||
| ### Review Checklist | ||
| - [ ] Verify all extras are correctly listed | ||
| - [ ] Check that package links are accurate | ||
| - [ ] Confirm excluded extras (models, kubeflow, launch, importers, perf) are intentionally omitted | ||
|
|
||
| --- | ||
| *This PR was automatically generated by the SDK extras update workflow.* | ||
| branch: update-sdk-extras-${{ github.run_number }} | ||
| delete-branch: true | ||
| labels: | | ||
| documentation | ||
| automated | ||
| sdk-extras | ||
|
|
||
| - name: Display Result | ||
| run: | | ||
| if [ "${{ steps.check-changes.outputs.has_changes }}" == "true" ]; then | ||
| if [ -n "${{ steps.create-pr.outputs.pull-request-number }}" ]; then | ||
| PR_URL="https://github.com/${{ github.repository }}/pull/${{ steps.create-pr.outputs.pull-request-number }}" | ||
| echo "📝 PR created successfully!" | ||
| echo "::notice title=Pull Request Created::A PR has been created for SDK extras updates: $PR_URL" | ||
| fi | ||
| else | ||
| echo "✅ SDK extras documentation is up to date" | ||
| echo "::notice title=No Updates Needed::SDK extras documentation is already up to date" | ||
| fi |
This file contains hidden or 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 hidden or 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,119 @@ | ||
| """"Generate a markdown table of SDK extras from pyproject.toml. | ||
|
|
||
| This script reads the `pyproject.toml` file to extract optional dependencies (extras) | ||
| and generates a markdown table listing each extra along with the packages it includes. | ||
|
|
||
| Note that this script excludes certain extras defined in the EXCLUDE list. | ||
| """ | ||
| import os | ||
| import re | ||
| import tomli | ||
|
|
||
| # W&B Python SDK Extras to exclude from the table. | ||
| EXCLUDE = ["models", "kubeflow", "launch", "importers", "perf"] | ||
|
|
||
| def header(): | ||
| """Return the markdown table headers.""" | ||
| return "| Extra | Packages included |\n" | ||
|
|
||
| def header_row(head_topics: int = 2): | ||
| """Return the markdown table header row. | ||
|
|
||
| Args: | ||
| head_topics (int): The number of header topics. | ||
|
|
||
| Returns: | ||
| str: A markdown table header row. | ||
| """ | ||
| return "|---------"*head_topics + "|\n" | ||
|
|
||
| def make_table_row(extra: str, packages: str) -> str: | ||
| """Generate a markdown table row for the given extra and packages. | ||
|
|
||
| Args: | ||
| extra (str): The name of the extra. | ||
| packages (str): The markdown links for the packages. | ||
|
|
||
| Returns: | ||
| str: A markdown table row. | ||
| """ | ||
| return f"| `{extra}` | {packages} |\n" | ||
|
|
||
| def clean_deps(deps: list[str]) -> list[str]: | ||
| """Remove version specifiers from a list of dependency strings. | ||
|
|
||
| Args: | ||
| deps (list[str]): A list of dependency strings. | ||
|
|
||
| Returns: | ||
| list[str]: A list of dependency strings without version specifiers. | ||
| """ | ||
| pattern = r"(>=|<=|==|~=|>|<|!=).*" | ||
| return [re.sub(pattern, "", url) for url in deps] | ||
|
|
||
| def make_dep_link(deps: list[str]) -> str: | ||
| """Create a markdown links for dependencies. | ||
|
|
||
| Args: | ||
| deps (list[str]): A list of dependency names. | ||
|
|
||
| Returns: | ||
| str: A string of markdown links for the dependencies. | ||
| """ | ||
| print(f"Creating dependency links for: {deps}") | ||
| dep_names = [dep.split(" ")[0] for dep in deps] | ||
| return ", ".join( | ||
| f"[{name}](https://pypi.org/project/{name}/)" for name in dep_names | ||
| ) | ||
|
|
||
|
|
||
| def generate_table(pyproject_path: str) -> list[str]: | ||
| """Generate the markdown table for the SDK extras. | ||
|
|
||
| Args: | ||
| pyproject_path (str): The path to the pyproject.toml file. | ||
|
|
||
| Returns: | ||
| list[str]: A list of strings representing the markdown table. | ||
| """ | ||
| rows = [] | ||
| rows.append(header()) | ||
| rows.append(header_row()) | ||
|
|
||
| with open(pyproject_path, "rb") as f: | ||
| pyproject = tomli.load(f) | ||
| extras = pyproject.get("project", {}).get("optional-dependencies", {}) | ||
| for extra, deps in extras.items(): | ||
| if extra in EXCLUDE: | ||
| continue | ||
| dep_links = make_dep_link(clean_deps(deps)) | ||
| table_row = make_table_row(extra, dep_links) | ||
| rows.append(table_row) | ||
|
|
||
| return rows | ||
|
|
||
|
|
||
| def main(): | ||
| # Pyproject.toml is expected to be in the same directory as this script. | ||
| pyproject_path = "./pyproject.toml" | ||
|
|
||
| # Output path for the generated markdown table. | ||
| output_path = "../snippets/en/_includes/python-sdk-extras.mdx" | ||
|
|
||
| # Create the output file if it doesn't exist | ||
| if not os.path.exists(output_path): | ||
| with open(output_path, 'w') as f: | ||
| f.write("Creating new file...\n") | ||
| print(f"File '{output_path}' created.") | ||
| else: | ||
| print(f"File '{output_path}' already exists.") | ||
|
|
||
| # Generate the markdown table and write to the output file | ||
| table_lines = generate_table(pyproject_path) | ||
| with open(output_path, "w") as f: | ||
| f.writelines(table_lines) | ||
| print(f"Markdown table written to '{output_path}'.") | ||
|
|
||
| if __name__ == "__main__": | ||
| # To do: Add argument parsing for custom paths | ||
| main() |
This file contains hidden or 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,8 @@ | ||
| | Extra | Packages included | | ||
ngrayluna marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| |---------|---------| | ||
| | `gcp` | [google-cloud-storage](https://pypi.org/project/google-cloud-storage/) | | ||
| | `aws` | [boto3](https://pypi.org/project/boto3/), [botocore](https://pypi.org/project/botocore/) | | ||
| | `azure` | [azure-identity](https://pypi.org/project/azure-identity/), [azure-storage-blob](https://pypi.org/project/azure-storage-blob/) | | ||
| | `media` | [numpy](https://pypi.org/project/numpy/), [moviepy](https://pypi.org/project/moviepy/), [imageio](https://pypi.org/project/imageio/), [pillow](https://pypi.org/project/pillow/), [bokeh](https://pypi.org/project/bokeh/), [soundfile](https://pypi.org/project/soundfile/), [plotly](https://pypi.org/project/plotly/), [rdkit](https://pypi.org/project/rdkit/) | | ||
| | `sweeps` | [sweeps](https://pypi.org/project/sweeps/) | | ||
| | `workspaces` | [wandb-workspaces](https://pypi.org/project/wandb-workspaces/) | | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.