Select to view content in your preferred language

Script are changed by ESRI with g_ESRI_variable_1, g_ESRI_variable_2

5100
13
08-10-2018 12:09 AM
simoxu
by MVP Regular Contributor
MVP Regular Contributor

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"

# Esri start of added imports
import sys, os, arcpy
# Esri end of added imports

# Esri start of added variables
g_ESRI_variable_1 = "EventID = '{}'"
g_ESRI_variable_2 = os.path.join(arcpy.env.scriptWorkspace,'..\\..\\..\\Users\\simoxu
\\AppData\\Local\\Esri\\ArcGISPro\\Staging\\SharingProcesses\\0038
\\RDA Tools for ArcGIS Pro\\p20\\current_checkout_attachments')
# Esri end of added variables

 #-------------------------------------------------------------------------------
# Name:        rda_checkout
# Purpose:     checkout the assessment for a specific event and map it
#
# Author:      simoxu
# Created:     27/07/2018
#-------------------------------------------------------------------------------
from arcpy import da
import os,sys
import shutil
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

In one place in my original code, I have the following line:

checkout_image_path= os.path.join(homefolder,"current_checkout_attachments")

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.

13 Replies
DanPatterson_Retired
MVP Emeritus

Package Project—Data Management toolbox | ArcGIS Desktop 

it seems some of your paths are to your folder and even if you are sharing internally, I doubt that anyone has access to it.  You should consolidate all the data, scripts etc into the folder structure that you are packaging.

Connections—such as folder, server, database and workflow—will only be included in an internal package. These items are removed if the package is created to be shared outside your organization.
simoxu
by MVP Regular Contributor
MVP Regular Contributor

Thanks Dan.

That's the problem ---  ESRI-added variable points to my folder which no one else can access. My question is, why does the Package Project tool do this? it seems the tool is confused by my code, somehow.

I understand the Package Project tool will analyze my custom tool before consolidating the required resources, so I manually used the Analyze Tools for Pro to analyze my script, and there are no related issues reported in result.

As you can see in my code, I am creating a path using os.path.join() function, the second parameter is a string (folder name) which is replaced by an ESRI-added variable ---- what? I am using a string, a CONSTANT, why changed it to a variable?

0 Kudos
DanPatterson_Retired
MVP Emeritus

os.path.join(arcpy.env.scriptWorkspace,'..\\..\\..\\Users\\simoxu ….. isn't that you?

Your workspace should be in the same folder as your whole project

c:\MyProjects\

\my.aprx

\mydata.gdb

\myscratch.gdb

\myscripts

\the_script.py

0 Kudos
simoxu
by MVP Regular Contributor
MVP Regular Contributor

I am pretty sure all the workspaces I use in the project are all under the same project folder.

The absolute path pointing to "..\\users\\simoxu...." were added in the front of my code by ArcGIS Pro Package Project tool / function, I am quite puzzled by this behavior.

Because it is pointing to "C:\Users\<USERPROFILE>\AppData\Local\ESRI\ArcGISPro\Staging\SharingProcesses/..."  and this folder seems related to the sharing activity, I'll see whether or not this behavior has anything to do with caching.

0 Kudos
ModyBuchbinder
Esri Regular Contributor

The packaging is really making the tool ready for server. It should keep paths that are registered in the server and try to replace others since the server does not have access to them. In your case I think it try to pack everything since the package should be self contained and should not use any other paths. Sometime the only way with server is to edit the result script. You can try to unzip, fix the script and zip again but this is not supported!!

Have Fun

simoxu
by MVP Regular Contributor
MVP Regular Contributor

That makes sense.

I remember someone reported the similar issue when publishing a custom Geoprocessing to the server.

But my case is really about sharing a project with other team mates, all the tools are designed to run on the local machine rather than run as a web service.  After they download it (or open it from portal/ArcGIS Online directly), the project folder structure are guaranteed and all the references to the datasource and Online resources should be ready to use. 

Thanks

0 Kudos
DanMcCoy
Frequent Contributor

simo xu‌, do you have any info about the similar issue when publishing a custom geoprocessing service?

Thanks,

Dan

0 Kudos
DanMcCoy
Frequent Contributor
0 Kudos
DanPatterson_Retired
MVP Emeritus

from Package Project—Data Management toolbox | ArcGIS Desktop 

did you remove the history?

And I would make sure that you have no reference to your folders as either a data source or a data destination since that will cause the tool to fail if people in your organization don't have access to, or permission to use, it

0 Kudos