This Extension shows how to wrap-up an existing trigger, so its logic is reused and so it gets some of the benefits of Extensions, like automatic replication, etc. The trigger is Python, so we include a copy of the Python interpreter, making an OS-level Python installation unnecessary. Note that since there's an installer with portable Python binaries on Windows, that this example is tailored for use there. Building a portable Python for Linux is more involved, so will be out of the scope here. There's little in this code that isn't easily ported to a unix environment. The trigger being wrapped is this: https://swarm.workshop.perforce.com/projects/perforce-software-sdp/files/dev/Server/Unix/p4/common/bin/triggers/DefaultChangeDesc.py (revision #2) With a dependency on P4-Python and: https://swarm.workshop.perforce.com/projects/perforce-software-sdp/files/dev/Server/Unix/p4/common/bin/triggers/P4Triggers.py (revision #16) Python 3.7 is used since it's the latest that P4-Python supports at this time. To recreate this with a different Python, first install Python. The steps used for this example are: Python installer: - Uncheck 'Install launcher for all users' - Click 'Customize Installation' - Uncheck everything but pip - Click Next to 'Advanced Options' - Click Precompile standard library - Click Install This installs to "C:\Users\Administrator\AppData\Local\Programs\Python\Python37" Now, install P4-Python: cd "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\Scripts" pip install p4python And copy it into the Extension directory: mkdir wrap_a_trigger-python\python xcopy /O /X /E /H /K C:\Users\Administrator\AppData\Local\Programs\Python\Python37 wrap_a_trigger-python\python Extensions has restrictions on the filenames it will install, with the aim of ensuring portability anywhere an Extension could be used. There are two files in the Python distribution that run afoul of the naming rules and must be deleted prior to installation. They're part of setuptools, which is unlikely to be used during normal trigger usage. del "python\Lib\site-packages\setuptools\script (dev).tmpl" del "python\Lib\site-packages\setuptools\command\launcher manifest.xml" Now it's ready for --package.
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 30809 | C. Thomas Tyler |
Code drop with newer versions of Extensions. Thanks to @jason_gibon. #review-30810 @jabson_gibson |