ID 476167 - Specific order in sys.path is not respected with sitecustomize

Follow

Problem summary
Using sitecustomize to enforce a specific order in sys.path is not respected by Katana.

Customer reported version
katana.4.0v2

Customer reported platform
centos7

Steps to reproduce

1) Create the following Python scripts:

├─ tmp
     └─ katana_test

     ├─ printSysPath.py

     └─ sitecustomize_dir

     └─ sitecustomize.py


a) /tmp/katana_test/printSysPath.py
import sys
print("sys.path inside the python process:")
for index, path in enumerate(sys.path, start=1):
print(" {0:02d} {1}".format(index, path))

b) /tmp/katana_test/sitecustomize_dir/sitecustomize.py
import sys
sys.path = ["/PATH/FIRST"] + sys.path[:]
print("sys.path after sitecustomize was called:")
for index, path in enumerate(sys.path, start=1):
print(" {0:02d} {1}".format(index, path))

2) cd into /tmp/katana_test and set the PYTHONPATH:
export PYTHONPATH=$(pwd)/sitecustomize_dir:/PATH/SECOND


3) Run Katana 4.0v2:
$KATANA_4_0_2/katanaBin --script ./printSysPath.py


Expected behavior
[INFO MAIN]: Launching Katana 4.0v1 script...
[INFO MAIN]: Crash handling is disabled.
[INFO MAIN]: Attempting to acquire Render license...
sys.path after sitecustomize was called:
  01 /PATH/FIRST
  02 /tmp/katana_test/sitecustomize_dir
  03 /PATH/SECOND
  04 /opt/Katana4.0v1/bin/python2.7/lib/python27.zip
  05 /opt/Katana4.0v1/bin/python2.7/lib/python2.7
  06 /opt/Katana4.0v1/bin/python2.7/lib/python2.7/plat-linux2
  07 /opt/Katana4.0v1/bin/python2.7/lib/python2.7/lib-tk
  08 /opt/Katana4.0v1/bin/python2.7/lib/python2.7/lib-old
  09 /opt/Katana4.0v1/bin/python2.7/lib/python2.7/lib-dynload
  10 /opt/Katana4.0v1/bin/python2.7/lib/python2.7/site-packages
[INFO python.Main]: KATANA_RENDER_TILE_SIZE defaulting to 256x256.
[INFO python.Main]: KATANA_IMAGE_MEMORY defaulting to 22381 MB.
[INFO python.Main]: KATANA_IMAGE_DISK_MEMORY defaulting to 129580 MB.
[INFO python.Main]: KATANA_SPEC_CACHE_ENABLED defaulting to 1.
[WARN python.Main]: There are no valid Renderer plug-ins available.
[INFO python.FarmAPI.FarmPluginManager]: Enabled concurrent render jobs.
sys.path inside the python process:
  01 /opt/Katana4.0v1/bin/python2.7
  02 /opt/Katana4.0v1/bin/python2.7/lib/python2.7
  03 /opt/Katana4.0v1/bin/python2.7/lib/python2.7/lib-tk
  04 /opt/Katana4.0v1/bin/python2.7/lib/python2.7/plat-linux2
  05 /opt/Katana4.0v1/bin/python2.7/lib/python2.7/lib-dynload
  06 /opt/Katana4.0v1/bin/python2.7/lib/python2.7/site-packages
  07 /opt/Katana4.0v1/bin
  08 /opt/Katana4.0v1/bin/python
  09 /opt/Katana4.0v1/bin/python/python_katana
  10 /opt/Katana4.0v1/bin/python/Main
  11 /opt/Katana4.0v1
  12 /PATH/FIRST
  13 /tmp/katana_test/sitecustomize_dir
  14 /PATH/SECOND
  15 /opt/Katana4.0v1/bin/python2.7/lib/python27.zip
  16 /opt/Katana4.0v1/bin/python2.7/lib/python2.7/lib-old
  17 /opt/Katana4.0v1/plugins/Resources/Core/Plugins
Notice /PATH/FIRST is before /PATH/SECOND.

Actual behavior
[INFO MAIN]: Launching Katana 4.0v2 script...
[INFO MAIN]: Crash handling is disabled.
[INFO MAIN]: Attempting to acquire Render license...
sys.path after sitecustomize was called:
  01 /PATH/FIRST
  02 /tmp/katana_test/sitecustomize_dir
  03 /PATH/SECOND
  04 /opt/Katana4.0v2/bin/python2.7/lib/python27.zip
  05 /opt/Katana4.0v2/bin/python2.7/lib/python2.7
  06 /opt/Katana4.0v2/bin/python2.7/lib/python2.7/plat-linux2
  07 /opt/Katana4.0v2/bin/python2.7/lib/python2.7/lib-tk
  08 /opt/Katana4.0v2/bin/python2.7/lib/python2.7/lib-old
  09 /opt/Katana4.0v2/bin/python2.7/lib/python2.7/lib-dynload
  10 /opt/Katana4.0v2/bin/python2.7/lib/python2.7/site-packages
[INFO python.Main]: KATANA_RENDER_TILE_SIZE defaulting to 256x256.
[INFO python.Main]: KATANA_IMAGE_MEMORY defaulting to 22381 MB.
[INFO python.Main]: KATANA_IMAGE_DISK_MEMORY defaulting to 129580 MB.
[INFO python.Main]: KATANA_SPEC_CACHE_ENABLED defaulting to 1.
[WARN python.Main]: There are no valid Renderer plug-ins available.
[INFO python.FarmAPI.FarmPluginManager]: Enabled concurrent render jobs.
sys.path inside the python process:
  01 /opt/Katana4.0v2/bin/python2.7
  02 /opt/Katana4.0v2/bin/python2.7/lib/python2.7
  03 /opt/Katana4.0v2/bin/python2.7/lib/python2.7/lib-tk
  04 /opt/Katana4.0v2/bin/python2.7/lib/python2.7/plat-linux2
  05 /opt/Katana4.0v2/bin/python2.7/lib/python2.7/lib-dynload
  06 /opt/Katana4.0v2/bin/python2.7/lib/python2.7/site-packages
  07 /opt/Katana4.0v2/bin
  08 /opt/Katana4.0v2/bin/python
  09 /opt/Katana4.0v2/bin/python/python_katana
  10 /opt/Katana4.0v2/bin/python/Main
  11 /opt/Katana4.0v2/plugins/Resources/Core/Plugins
  12 /opt/Katana4.0v2
  13 /tmp/katana_test/sitecustomize_dir
  14 /PATH/SECOND

  15 /PATH/FIRST
  16 /opt/Katana4.0v2/bin/python2.7/lib/python27.zip
  17 /opt/Katana4.0v2/bin/python2.7/lib/python2.7/lib-old
Notice how the order have changed and  /PATH/SECOND is now BEFORE /PATH/FIRST.

Workaround
No known workaround

Reproduced by support
This bug has been reproduced in:
Katana 4.0v4 - CentOS 7
Katana 4.0v3 - CentOS 7
Katana 4.0v2 - CentOS 7

Unable to reproduce bug in:
Katana 4.0v1 - CentOS 7

Earliest version tested
Katana 4.0v1 - This issue doesn't appear in this version and has regressed


    We're sorry to hear that

    Please tell us why