Skip to content

Commit

Permalink
swig/python/setup.py.in: workaround easy_install behavior on Windows …
Browse files Browse the repository at this point in the history
…to keep .py scripts (fixes OSGeo#8811)

This is a follow-up of OSGeo#8815 for Windows, and particularly to unbreak conda-forge builds that
test the presence of the .py scripts.

Before this PR, "python setup.py install" would cause the following
logs:
```
Installing gdal2tiles.py script to C:\Miniconda3\envs\test\conda-bld\gdal-split_1700841951001\_h_env\Scripts
[...]
Deleting C:\Miniconda3\envs\test\conda-bld\gdal-split_1700841951001\_h_env\Scripts\gdal2tiles.py
Installing gdal2tiles-script.py script to C:\Miniconda3\envs\test\conda-bld\gdal-split_1700841951001\_h_env\Scripts
Installing gdal2tiles.exe script to C:\Miniconda3\envs\test\conda-bld\gdal-split_1700841951001\_h_env\Scripts
```

This PR hacks around easy_install to avoid the deletiong of the .py
script
  • Loading branch information
rouault committed Nov 25, 2023
1 parent 07ecc07 commit b46aff1
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions swig/python/setup.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,39 @@ def has_flag(compiler, flagname):
return False
return True

# ---------------------------------------------------------------------------
# BEGIN monkey patching of setuptools.command.easy_install.easy_install class
# ---------------------------------------------------------------------------

# "python setup.py install" uses setuptools.command.easy_install internally
# When installing the .exe wrapper executable for our command line utilities,
# that class removes the installed .py scripts themselves. Which we do not want,
# since they may be directly used by users. So we do a monkey patching of
# easy_install.install_wrapper_scripts to install a modified
# easy_install.delete_blockers method that does NOT remove .py files
if sys.platform == 'win32':
from setuptools.command.easy_install import easy_install

original_install_wrapper_scripts = easy_install.install_wrapper_scripts

def monkey_patched_install_wrapper_scripts(self, dist):
original_delete_blockers = easy_install.delete_blockers
def monkey_patched_delete_blockers(self, blockers):
blockers = filter(lambda x: not x.endswith('.py'), blockers)
return original_delete_blockers(self, blockers)

easy_install.delete_blockers = monkey_patched_delete_blockers
try:
return original_install_wrapper_scripts(self, dist)
finally:
easy_install.delete_blockers = original_delete_blockers

easy_install.install_wrapper_scripts = monkey_patched_install_wrapper_scripts

# ---------------------------------------------------------------------------
# END monkey patching of setuptools.command.easy_install.easy_install class
# ---------------------------------------------------------------------------

# ---------------------------------------------------------------------------
# Imports
# ---------------------------------------------------------------------------
Expand Down

0 comments on commit b46aff1

Please sign in to comment.