How to install a custom GeoApp

· 1 · 114

Tom Cvjetkovic

  • *
  • Posts: 1
    • View Profile
    • cvt engineering
How to install a custom GeoApp
« on: October 21, 2022, 05:25:52 PM »
Dear GeoDict-Team,

I have developed a custom GeoApp which incorporates a special workflow. Now I would like to provide an easy way to install it.

The App itself is available as a Python package on a private package registry, so usually I would use the following command to install it
(here for the private Gitlab package registry)

Code: [Select]
pip install <geoapp> --extra-index-url https://__token__:<your_personal_token>
unfortunately, this doesn't work in GeoDict. Although there is an option to install an additional Python package (via Macro-> Execute Macro/Script -> Add Python Package), using the addional option for pip doesn't work.

My current workaround for Installing the GeoApp is a separate install script. One can simply run this install script in GeoDict to install and update the GeoApp.

First, we have a function which provides the path to the Python executable (we need this because sys.executable points to the global python executable)

Code: [Select]
def get_python_executable():
    if sys.platform.startswith("linux"):
        py_executable = Path(gd.getInstallationFolder()) / "python36"
    elif sys.platform.startswith("win"):
        py_executable = Path(gd.getInstallationFolder()) / "python36.exe"
    return py_executable

Additionally, we need a helper function to run the install command later

Code: [Select]
def run_cmd(cmd, verbose=True):
    with Popen(cmd, stdout=PIPE, stderr=STDOUT, bufsize=1, universal_newlines=True) as p:
        for line in p.stdout:
            if verbose:
                print(line, end='')
    return p.returncode

Then we can run the pip command to install and upgrade using a private package index-url. We also need to define the target to install the GeoApp and it's dependencies in the GeoDict user folder.

Code: [Select]

executable = get_python_executable().as_posix()
target = (Path(gd.getSettingsFolder()) / "Python").as_posix()
index_url = https://__token__:<your_personal_token> package_name = "my_geoapp"
cmd = [executable, "-m", "pip", "install", "--upgrade", "--target", target, package_name, "--extra-index-url", index_url]

After that we need to restart GeoDict and call a setup function which copies the GeoApp-Macros into the GeoDict user folder. For Linux, this would be ~/.geodict22/GeoApp/MyGeoApp.
The GeoApp Macros just contain the code for the user interface. The actual business logic is inside the python package.

As you can see, this is a rather complicated way to install a GeoApp, I am sure there must be a better way, what do you think :-)

Best regards, Tom