I have a Python toolbox which I would like to publish to our ArcGIS Enterprise 10.8.1 environment. I use ArcGIS Pro 2.7.3 for publishing. The Python toolbox reads from a configuration file on the file system.
After publishing and running the geoprocessing service on the server, the configuration are based on the file on my local machine rather than the configuration file on the server (in the same directory) which is not desired.
import json
# ...
DATASOURCE_CONFIG_FILE = r"f:\geoportal\data.json"
class Tool(object):
# ...
@staticmethod
def read_datasources():
""" Read datasource config file. """
with open(DATASOURCE_CONFIG_FILE, "r") as config_file:
return json.load(config_file)
I assume this is some sort of a security mechanism (sandbox?). Could someone explain me what ArcGIS Pro and/or ArcGIS Enterprise is actually doing/changing when publishing a tool and why?
Also, is there another workaround other than "obfuscating" DATASOURCE_CONFIG_FILE = r"f:\geoportal\data.json"
to conceal it from the publishing parser?
Doing some more research I found this:
Whenever a quoted string is found in the script, the test for data existence proceeds as follows:
[...]
These tests proceed in sequential order. If the test passes, and the data exists, it will be consolidated, with one exception: if you are sharing a service, the server's data store is examined to determine if the data resides in the data store. If it resides in the data store, then it is not consolidated.
Authoring geoprocessing tasks with Python scripts
In my case, I have a configuration file on my local machine and on the server machine located in the same directory (but different file content). So, in this case it should not be consolidated, right?
Solution: See KHibma's answer and my comment. The issue was that I used localhost
instead of MY_COMPUTER_NAME
for the Publisher Folder Hostname when registering a folder in Data Stores. localhost
does not work despite of being mentioned here.
Field | Value |
---|---|
Publisher Folder Path | f:\geoportal |
Publisher Folder Hostname | MY_COMPUTER_NAME |
Server Folder Path | Same as publisher folder path checked |