How to properly use a private GitHub repo as a package dependency in a VIKTOR app?

Hi everyone,

I’m developing a VIKTOR app and want to use a private Python package hosted on GitHub (Rod-Pattern-Automation). Here’s my situation and what I’ve tried so far:


What I want to do:

  • Use my private package Rod-Pattern-Automation inside the VIKTOR app.
  • Access the class RodPattern from this package to populate an OptionField dynamically.

My provisional solution (local import):

I tried temporarily adding the package folder path manually:

import sys
import os
sys.path.append(os.path.abspath(r"Path_to_folder"))

from rod_pattern_class import RodPattern
from WriterDrawing import DXFwriter

And my VIKTOR parametrization code looks like:


class Parametrization(vkt.Parametrization):
    product = vkt.OptionField("Choose product", options=[], visible=True)

class Controller(vkt.Controller):
    parametrization = Parametrization

    def get_parametrization(self, params, **kwargs):
        RP = RodPattern()
        options = RP.PRODUCT_CHOICE  # Must be a list of strings
        p = Parametrization()
        p.product.options = options
        return p

However, the options never show up in the UI.


Next, I tried to install the private package as a dependency

I followed the documentation to add the private repo to requirements.txt using this line:

Rod-Pattern-Automation@git+https://${julesangebault-ff:${*MyPassword*}@https://github.com/julesangebault-ff/Rod-Pattern-Automation

But the installation keeps failing with access error

fatal: unable to access 'https://https//github.com/julesangebault-ff/Rod-Pattern-Automation/'


Questions:

  1. How can I correctly import and use a private GitHub package inside a VIKTOR app?
  2. What is the correct format to add a private GitHub repo to requirements.txt for VIKTOR apps, especially regarding tokens or passwords?
  3. Is there a recommended way to dynamically update OptionField options based on an imported package?

Thanks in advance for any guidance or examples!

Hy @Jules ,

Welcome to the VIKTOR community! To answer your questions:

  1. To import a private Github package would require of you to generate a Personal Access Token in Github. The GITHUB_USER and GITHUB_TOKEN should then be added as environment variables. You can then install your app with the env variable defined as an argument (viktor-cli install --env GITHUB_USER=xxx). When publishing your app, make sure to have those env variables defined in the app details page.
  2. The correct format to add your private package would be the format:
git+https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/username/repo.git@branch#egg=package_name
  1. To dynamically update an OptionField’s options based on imported package, I would recommend using a callback function. This gives you the freedom to define dynamic nature of your options in Python. What you specifically want to make dynamic would depend on what you would like to achieve specifically.

To make it clear for other readers, here is the link to find more info on private repositories in the VIKTOR docs.

For more info on using a Private Github Repository, you can refer to this link.

I hope this was helpful?

1 Like