papi: fix VPP_API_DIR 92/37792/1
authorPim van Pelt <pim@ipng.nl>
Mon, 12 Dec 2022 00:00:16 +0000 (00:00 +0000)
committerPim van Pelt <pim@ipng.nl>
Mon, 12 Dec 2022 00:00:49 +0000 (00:00 +0000)
Docstring in VPP Python API says that find_api_dir() will search for
environment variable VPP_API_DIR first and foremost, except it doesn't.
Prepend VPP_API_DIR if it exists, and allow dirs to be omitted in case
it will be the empty list []

Type: fix
Signed-off-by: pim@ipng.nl
Change-Id: Ic892e4bb7d8ff50f18e64ddfd2a61343883f07ea

src/vpp-api/python/vpp_papi/vpp_papi.py

index e67ee19..a9edfed 100644 (file)
@@ -154,7 +154,7 @@ class VPPValueError(ValueError):
 
 class VPPApiJSONFiles:
     @classmethod
-    def find_api_dir(cls, dirs):
+    def find_api_dir(cls, dirs=[]):
         """Attempt to find the best directory in which API definition
         files may reside. If the value VPP_API_DIR exists in the environment
         then it is first on the search list. If we're inside a recognized
@@ -170,6 +170,9 @@ class VPPApiJSONFiles:
         # in which case, plot a course to likely places in the src tree
         import __main__ as main
 
+        if os.getenv("VPP_API_DIR"):
+            dirs.append(os.getenv("VPP_API_DIR"))
+
         if hasattr(main, "__file__"):
             # get the path of the calling script
             localdir = os.path.dirname(os.path.realpath(main.__file__))