Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/check-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v5
- uses: actions/checkout@v6

- name: Set up Python ${{ matrix.python-version }} on ${{ matrix.os }}
uses: actions/setup-python@v6
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v5
uses: actions/checkout@v6

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/generate-metadata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v5
- uses: actions/checkout@v6

- name: Set up Python
uses: actions/setup-python@v6
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
UPLOAD_FILE_NAME: tabcmd

steps:
- uses: actions/checkout@v5
- uses: actions/checkout@v6

- uses: actions/setup-python@v6
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
name: Build dist files for PyPi
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/checkout@v6
with:
fetch-depth: 0
- uses: actions/setup-python@v6
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run-e2-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v5
- uses: actions/checkout@v6

- name: Set up Python ${{ matrix.python-version }} on ${{ matrix.os }}
uses: actions/setup-python@v6
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v5
- uses: actions/checkout@v6

- name: Set up Python ${{ matrix.python-version }} on ${{ matrix.os }}
uses: actions/setup-python@v6
Expand Down
45 changes: 33 additions & 12 deletions bin/license-checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
# Modified version of https://stackoverflow.com/a/44090218
from __future__ import print_function
from collections import defaultdict
import pkg_resources
from pathlib import Path
from importlib.metadata import distributions

def get_pkg_license(pkg):
def get_pkg_license(dist):
# Match original behavior: scan text lines for "License:" only
try:
lines = pkg.get_metadata_lines('METADATA')
except:
lines = pkg.get_metadata_lines('PKG-INFO')

lines = dist.read_text('METADATA').splitlines()
except Exception:
lines = (dist.read_text('PKG-INFO') or '').splitlines()
for line in lines:
if line.startswith('License:'):
return line[9:]
return line[9:].strip()
return '(Licence not found)'
exit()

def print_table(table):
column_index_to_max_width = defaultdict(int)
Expand All @@ -38,15 +38,36 @@ def print_table(table):
print("-" * len(line))


def get_directory(package_name):
return pkg_resources.working_set.find(pkg_resources.Requirement.parse(package_name)).location
def get_location(dist):
# Try to locate the site-packages directory containing this distribution
files = list(dist.files or [])
# Prefer metadata files to infer the base
meta_file = next((f for f in files if getattr(f, 'name', None) in ('METADATA', 'PKG-INFO')), None)
if meta_file is not None:
abs_path = Path(dist.locate_file(meta_file))
# .../site-packages/<dist>.dist-info/METADATA -> site-packages
return str(abs_path.parent.parent)
if files:
some_file = Path(dist.locate_file(files[0]))
return str(some_file.parent)
return '(Unknown)'


def print_packages_and_licenses():
table = []
table.append(['Package', 'License', 'Location'])
for pkg in sorted(pkg_resources.working_set):
table.append([str(pkg).rjust(25)[:25], get_pkg_license(pkg)[:25], pkg.location])
# Sort by distribution name
dists = []
for dist in distributions():
name = (dist.metadata.get('Name') or '').strip()
dists.append((name.lower(), dist))
for _, dist in sorted(dists, key=lambda t: t[0]):
name = (dist.metadata.get('Name') or 'UNKNOWN').strip()
version = getattr(dist, 'version', '')
pkg_display = f"{name} {version}".strip()
license_value = get_pkg_license(dist)[:25]
location_value = get_location(dist)
table.append([pkg_display.rjust(25)[:25], license_value, location_value])
print_table(table)


Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ classifiers = [
dependencies = [
"appdirs",
"requests>=2.25,<3.0",
# pinned to 81 so the license_checker can use pkg_resources
"setuptools<81; python_version >= '3.12'",
"setuptools",
"tableauserverclient==0.40",
"urllib3",
]
Expand Down