$npx -y skills add opendatahub-io/ai-helpers --skill python-packaging-license-finderUse this skill to deterministically find license information for Python packages by checking PyPI metadata first, then falling back to Git repository LICENSE files using shallow cloning.
| 1 | # Python Package License Finder |
| 2 | |
| 3 | This skill helps you deterministically find license information for Python packages using a two-step approach: first checking PyPI metadata, then searching the source repository if needed. |
| 4 | |
| 5 | ## Instructions |
| 6 | |
| 7 | When a user asks to find the license for a Python package, follow this deterministic process: |
| 8 | |
| 9 | ### Step 0: Source URL Priority |
| 10 | |
| 11 | If a source repository URL is provided by the caller, skip PyPI lookup entirely: |
| 12 | |
| 13 | 1. Pass the URL directly to the `git:shallow-clone` skill |
| 14 | 2. Search for LICENSE files in the cloned repository (see Step 2.3-2.4 below) |
| 15 | 3. Report the license found |
| 16 | |
| 17 | You can also use the script with a source URL to trigger this flow: |
| 18 | ```bash |
| 19 | ./scripts/find_license.py <package_name> --source-url <url> |
| 20 | ``` |
| 21 | |
| 22 | If no source URL is provided, proceed with Step 1. |
| 23 | |
| 24 | ### Step 1: Check PyPI Metadata |
| 25 | First, attempt to find the license from PyPI using the package inspection script: |
| 26 | |
| 27 | ```bash |
| 28 | ./scripts/find_license.py <package_name> [version] |
| 29 | ``` |
| 30 | |
| 31 | If the script finds a license in the PyPI metadata, **stop here** and return the license name. |
| 32 | |
| 33 | ### Step 2: Search Git Repository (if PyPI fails) |
| 34 | If no license is found in PyPI metadata, search the package's source repository: |
| 35 | |
| 36 | 1. **Get the source repository URL** from the PyPI metadata (the script will provide it) |
| 37 | 2. **Use the shallow-clone skill** to clone the repository: |
| 38 | ``` |
| 39 | Skill: git:shallow-clone |
| 40 | ``` |
| 41 | 3. **Search for LICENSE files** in the cloned repository: |
| 42 | ```bash |
| 43 | find . -iname "license*" -o -iname "copying*" -o -iname "copyright*" | head -10 |
| 44 | ``` |
| 45 | 4. **Read the license file** to identify the license type: |
| 46 | ```bash |
| 47 | head -20 <license_file> |
| 48 | ``` |
| 49 | |
| 50 | ### Step 3: Report Results |
| 51 | - **License Found**: Return the license name (e.g., "MIT License", "Apache-2.0", "GPL-3.0") |
| 52 | - **License Not Found**: Report that the license could not be determined |
| 53 | |
| 54 | ## Usage Examples |
| 55 | |
| 56 | ### Find License for Popular Package |
| 57 | ```bash |
| 58 | ./scripts/find_license.py requests |
| 59 | ``` |
| 60 | **Expected**: Find "Apache-2.0" from PyPI metadata |
| 61 | |
| 62 | ### Find License for Package with Missing PyPI License |
| 63 | ```bash |
| 64 | ./scripts/find_license.py some-package |
| 65 | ``` |
| 66 | **Expected**: Fall back to repository search if PyPI metadata is incomplete |
| 67 | |
| 68 | ### Specific Version Analysis |
| 69 | ```bash |
| 70 | ./scripts/find_license.py django 4.2.0 |
| 71 | ``` |
| 72 | **Expected**: Find license for specific Django version |
| 73 | |
| 74 | ## Error Handling |
| 75 | |
| 76 | ### Package Not Found |
| 77 | - Verify package name spelling |
| 78 | - Check package availability on PyPI |
| 79 | - Suggest alternative package names |
| 80 | |
| 81 | ### Repository Access Issues |
| 82 | - Report if source repository is unavailable |
| 83 | - Note private/restricted repositories |
| 84 | - Suggest manual license verification |
| 85 | |
| 86 | ### License File Parsing |
| 87 | - Handle non-standard license file formats |
| 88 | - Report unclear or multiple licenses |
| 89 | - Recommend manual review for complex cases |
| 90 | |
| 91 | ## Integration Notes |
| 92 | |
| 93 | This skill complements: |
| 94 | - **python-packaging-complexity** - License info helps assess redistribution complexity |
| 95 | - **python-packaging-license-checker** - Provides license names for compatibility assessment |
| 96 | - **python-packaging-source-finder** - Uses similar PyPI metadata analysis |
| 97 | |
| 98 | The skill focuses on **finding** license information, while license-checker focuses on **assessing** license compatibility for redistribution. |