It's a surprise to me that ArcGIS Pro changes the python code in my script tool when I pack the project and upload the ppkx to ArcGIS Online.
Here is the first a few lines of code for one script tool in the unpacked ppkx, please pay attention to the codes between "Esri start of added imports" and "Esri end of added variables"
<SPAN class="comment token"># Esri start of added imports</SPAN>
<SPAN class="keyword token">import</SPAN> sys<SPAN class="punctuation token">,</SPAN> os<SPAN class="punctuation token">,</SPAN> arcpy
<SPAN class="comment token"># Esri end of added imports</SPAN>
<SPAN class="comment token"># Esri start of added variables</SPAN>
g_ESRI_variable_1 <SPAN class="operator token">=</SPAN> <SPAN class="string token">"EventID = '{}'"</SPAN>
g_ESRI_variable_2 <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>scriptWorkspace<SPAN class="punctuation token">,</SPAN>'<SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN>\\<SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN>\\<SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN>\\Users\\simoxu
\\AppData\\Local\\Esri\\ArcGISPro\\Staging\\SharingProcesses\\<SPAN class="number token">0038</SPAN>
\\RDA Tools <SPAN class="keyword token">for</SPAN> ArcGIS Pro\\p20\\current_checkout_attachments'<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Esri end of added variables</SPAN>
<SPAN class="comment token">#-------------------------------------------------------------------------------</SPAN>
<SPAN class="comment token"># Name: rda_checkout</SPAN>
<SPAN class="comment token"># Purpose: checkout the assessment for a specific event and map it</SPAN>
<SPAN class="comment token">#</SPAN>
<SPAN class="comment token"># Author: simoxu</SPAN>
<SPAN class="comment token"># Created: 27/07/2018</SPAN>
<SPAN class="comment token">#-------------------------------------------------------------------------------</SPAN>
<SPAN class="keyword token">from</SPAN> arcpy <SPAN class="keyword token">import</SPAN> da
<SPAN class="keyword token">import</SPAN> os<SPAN class="punctuation token">,</SPAN>sys
<SPAN class="keyword token">import</SPAN> shutil
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>In one place in my original code, I have the following line:
checkout_image_path<SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>homefolder<SPAN class="punctuation token">,</SPAN><SPAN class="string token">"current_checkout_attachments"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
But it was replaced with the following code, which is causing fatal error for the tool itself.
checkout_image_path= os.path.join(homefolder,g_ESRI_variable_2)
It's quite strange that ArcGIS Pro packaging tool will change my code without informing me --- I only found out this when I shared the project package with others and then was told the tools could not run properly.
Is it only me? Any advice?
I am using ArcGIS Pro 2.2.1, by the way.
Thanks.