Skip to content

Commit

Permalink
Python bindings: define entry_points.console_scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Nov 15, 2023
1 parent 152a13d commit cddd6be
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
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),
)

0 comments on commit cddd6be

Please sign in to comment.