0

With Azure Functions we have code duplications in multiple projects and init.py files. We would like to develop a single helper package to import functions and classes to our init.py files. We would like to avoid code duplication, and place this helper package to its own github repository for proper version control, release management and multi developer work. This should be a private repo.

With public repos it is easy to add the git url to the requirements.txt, and the functions work fine on azure. But with private repositories this approach doesn't work.

Of course we could copy-paste the package files into each project, but that would be a maintenance nightmare after a short time.

So what approach, solution do you think would be the best for importing in our functions from this distinct repository?

Sinus Gamma
  • 5
  • 1
  • 4
  • Does this helpful https://stackoverflow.com/questions/69767860/modulenotfounderror-no-module-named-x-using-azure-functions-python-privat ? – VenkateshDodda Nov 22 '21 at 08:37

1 Answers1

0

Based on our requirement we need to import the packages or files from our local or from any stored location. Below are few ways to import them:

  1. To reference local files:

     import pathlib
     open(pathlib.Path(__file__).parent / 'model.pkl', 'rb')
    
  2. If we have modules we need to import them by using relative import syntax:

    from . import example

  3. If it is below case:

    |__ HttpTrigger1
             |__ function.json
             |__ main.py
             |__ example.py
             |__ helpers
                     |__ jwt
                             |__ __init__.py   

We can do it as below:

    from sys import path
    from os.path import dirname, join
    path.append(dirname(__file__))
    
    import json
    from .helpers import jwt

Also check as VenkateshDodda-MT suggest if that might solve the issue.

SaiKarri-MT
  • 1,174
  • 1
  • 3
  • 8