From cddd6bec4e5a831351f15d0c6d3db86f3a952c4c Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Wed, 15 Nov 2023 17:19:05 +0100 Subject: [PATCH] Python bindings: define entry_points.console_scripts --- .github/workflows/cmake_builds.yml | 7 +++++-- swig/python/setup.py.in | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cmake_builds.yml b/.github/workflows/cmake_builds.yml index b33cd3a619d6..f84990de9702 100644 --- a/.github/workflows/cmake_builds.yml +++ b/.github/workflows/cmake_builds.yml @@ -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: | @@ -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 diff --git a/swig/python/setup.py.in b/swig/python/setup.py.in index 8bcf24d2ede9..58cdbe0cb4e9 100644 --- a/swig/python/setup.py.in +++ b/swig/python/setup.py.in @@ -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 @@ -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, @@ -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), )