0

In version ArcGIS Pro 2.9,3.0 and 3.1 the following structure of a web tool worked as intended when it was staged, in order to be published in ArcGIS Enterprise:

Updm2018 └── TestService.atbx ├ __init__.py ├ MyTestService.py ├ foo.py └──bar ├ __init__.py ├ real_bar.py ├ file_required_by_baz.json └─ baz.py 

The definition was staged using the StageService function and the .sd file will include the required files.

In the version 3.3 it does not behave as it used to do it, now the referenced modules in subfolders are not consolidated.

Note: I also tried using the Save As Offline Service Definition tool:

enter image description here

It is worth to mention that the file MyTestService.py include the imports:

… import foo from bar import realbar from bar import baz … 

Execution of the tool StageService in ArcGIS Pro 3.3.1 generates an .sd file with the following structure (.sd file is just a zip file):

│ manifest.xml │ serviceconfiguration.json │ tilingservice.xml │ ├───cd │ └───updm2018 │ foo.py │ MyTestService.py │ TestService.atbx │ ├───esriinfo │ │ iteminfo.xml │ │ │ └───metadata │ metadata.xml │ └───p30 MyTestService.msd MyTestService.rltx MyTestService.tbx 

There are missing files required by the tool to properly run:

real_bar.py file_required_by_baz.json baz.py 

Following the indications of the documentation , it should be possible to do it. As a matter of fact it has been working with out any issue, until this version.

Am I missing some new configuration in the staging process?

2
  • 2 things: 1) If this has worked in a prior version and has stopped working in a newer version without any code changes: that sounds like a bug you should submit to support. 2) A file you said is not consolidated, file_required_by_baz.json, where is the reference? I could be wrong, but I thought only files referenced from the main script were consolidated. Not a file referenced from a consolidated file (however I could be wrong in this point) Commented Jul 29, 2024 at 14:19
  • @KHibma the file is referenced by baz.py. I can confirm you that files referenced by other consolidated files were consolidated too in version 3.0 and 3.1 of ArcGIS Pro. Commented Jul 29, 2024 at 14:41

2 Answers 2

1

I chatted with the Esri Geoprocessing Services Team -- they confirmed this is a bug and have entered a ticket into their system. I can't make any promises on their behalf, but they've set a target to fix in ArcGIS Pro 3.4

1
  • This appears to be fixed in ArcGIS Pro 3.4 Commented Jan 28 at 17:56
0

In root level, I created a file called modules_importer.py:

Updm2018 └── TestService.atbx ├ __init__.py ├ MyTestService.py ├ modules_importer.py ├ foo.py └──bar ├ __init__.py ├ real_bar.py ├ file_required_by_baz.json └─ baz.py 

Inside the file I put the following code:

import arcpy import sys from os.path import exists def set_path(): bar_module = r".\bar" if exists(arcpy.env.packageWorkspace + '\\..\\cd\\'): sys.path.append(arcpy.env.packageWorkspace + '\\..\\cd\\') 

Modified the imports of the file MyTestService.py:

... import arcpy import foo arcpy.AddMessage("Loading own modules") import modules_importer modules_importer.set_path() arcpy.AddMessage("AfterLoading own modules") import bar.real_bar as real_bar import bar.baz as baz .... 
  1. When the stage definition is created, is very important to select the Copy all data option (in ArcGIS Pro): enter image description here

or its equivalent in python: setting True the property copyDataToServer in the GeoprocessingSharingDraft class.

when all this is set, the creation of the .sd file will consolidate, and the file structure will be:

│ manifest.xml │ serviceconfiguration.json │ tilingservice.xml │ ├───cd │ ├───updm2018 │ │ foo.py │ │ MyTestService.py │ │ TestService.atbx │ └───bar │ real_bar.py │ file_required_by_baz.json │ baz.py │ ├───esriinfo │ │ iteminfo.xml │ │ │ └───metadata │ metadata.xml │ └───p30 MyTestService.msd MyTestService.rltx MyTestService.tbx 

and the file modules_importer.py will be consolidated as:

# Esri start of added imports import sys, os, arcpy # Esri end of added imports # Esri start of added variables g_ESRI_variable_1 = os.path.join(arcpy.env.packageWorkspace,'..\\cd\\bar') # Esri end of added variables import arcpy import sys from os.path import exists def set_path(): bar_module = g_ESRI_variable_1 # pythonModules = r".\\" # this line make a recursive call to the current folder arcpy.AddMessage("Call set_path") arcpy.AddMessage(arcpy.env.packageWorkspace + '\\..\\cd\\') if exists(arcpy.env.packageWorkspace + '\\..\\cd\\'): sys.path.append(arcpy.env.packageWorkspace + '\\..\\cd\\') 

Having this folder structure and with the cd folder added to the PATH, the imports to modules are resolved properly.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.