Skip to content
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

Python bindings: define entry_points.console_scripts #8718

Merged
merged 1 commit into from
Nov 21, 2023
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
7 changes: 5 additions & 2 deletions .github/workflows/cmake_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,11 @@ jobs:
# Set PATH so that gdal-config is found
PATH=$GITHUB_WORKSPACE/install-gdal/bin:$PATH pip install gdal-python.tar.gz[numpy]
LD_LIBRARY_PATH=$GITHUB_WORKSPACE/install-gdal/lib python -c "from osgeo import gdal_array"
which gdal_edit.py
which gdal_edit
cp $GITHUB_WORKSPACE/autotest/gcore/data/byte.tif .
LD_LIBRARY_PATH=$GITHUB_WORKSPACE/install-gdal/lib ldd myvenv/lib/python3.8/site-packages/osgeo/_gdal.cpython-38-x86_64-linux-gnu.so
LD_LIBRARY_PATH=$GITHUB_WORKSPACE/install-gdal/lib gdal_edit.py byte.tif -mo FOO=BAR
LD_LIBRARY_PATH=$GITHUB_WORKSPACE/install-gdal/lib gdal_edit byte.tif -mo FOO=BAR
rm -f myvenv/bin/gdal_edit
rm -f myvenv/bin/gdal_edit.py
- name: Standalone gdal-utils package from wheel
run: |
Expand Down Expand Up @@ -490,6 +491,8 @@ jobs:
gdalinfo --version
python -VV
PYTHONPATH=$GITHUB_WORKSPACE/install-gdal/lib/site-packages python -c "from osgeo import gdal;print(gdal.VersionInfo(None))"
export PATH=$GITHUB_WORKSPACE/install-gdal/Scripts:$PATH
PYTHONPATH=$GITHUB_WORKSPACE/install-gdal/lib/site-packages gdal_edit --version
- name: Show gdal.pc
shell: bash -l {0}
run: cat $GITHUB_WORKSPACE/build/gdal.pc
Expand Down
21 changes: 21 additions & 0 deletions swig/python/setup.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import os
import sys
from glob import glob
from pathlib import Path

from setuptools.command.build_ext import build_ext
from setuptools import setup
Expand Down Expand Up @@ -357,6 +358,25 @@ classifiers = [

exclude_package_data = {'': ['CMakeLists.txt']}

scripts = sorted(glob("./gdal-utils/osgeo_utils/*.py"), reverse=True) # command line scripts

def define_entry_points(scripts, entry_points=None):
"""
Return a dict defining scripts that get installed to PYTHONHOME/Scripts.

console_scripts : [
# CLI_command = dirname.filename
'gdal_edit = osgeo_utils.gdal_edit',
'gdal_merge = osgeo_utils.gdal_merge',
... ]
"""
console_scripts = []
for f in scripts:
name = Path(f).stem # 'gdal_edit' from 'gdal_edit.py'
console_scripts.append([f"{name} = osgeo_utils.{name}:main"])
entry_points = {"console_scripts": console_scripts}
return entry_points

setup(
name=name,
version=version,
Expand All @@ -380,4 +400,5 @@ setup(
zip_safe=False,
cmdclass=dict(build_ext=gdal_ext),
exclude_package_data = exclude_package_data,
entry_points=define_entry_points(scripts),
)
Loading