Change in gr-gsm[master]: Fix grcc compilation with python3 by adding local subdirs to __path__

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

ptrkrysik gerrit-no-reply at lists.osmocom.org
Mon May 3 10:31:42 UTC 2021


ptrkrysik has submitted this change. ( https://gerrit.osmocom.org/c/gr-gsm/+/24075 )

Change subject: Fix grcc compilation with python3 by adding local subdirs to __path__
......................................................................

Fix grcc compilation with python3 by adding local subdirs to __path__

As the directory structure in the repository is different then the one
after the package gets installed we need to add those subdirectories to
the __path__ otherwise python3 is not able to load the modules using the
relative import syntax and grcc compilation and some unit tests fail.

Mofiy __path__ only when the CMAKE_BINARY_DIR environment variable is
present.

Revert "grgsm_livemon: Set cell_allocation to [0]"

This reverts commit 013d4c258c6ad31c2581f0caa4eee3aa609fd9de.

Change-Id: I223fd6181e8e36027039301186b671712a597ff8
---
M apps/grgsm_livemon.grc
M apps/grgsm_livemon_headless.grc
M cmake/Modules/GrccCompile.cmake
M python/CMakeLists.txt
M python/__init__.py
5 files changed, 24 insertions(+), 3 deletions(-)

Approvals:
  ptrkrysik: Looks good to me, approved; Verified



diff --git a/apps/grgsm_livemon.grc b/apps/grgsm_livemon.grc
index 941f816..e8bf4a5 100644
--- a/apps/grgsm_livemon.grc
+++ b/apps/grgsm_livemon.grc
@@ -360,7 +360,7 @@
   parameters:
     affinity: ''
     alias: ''
-    cell_allocation: '[0]'
+    cell_allocation: '[arfcn.downlink2arfcn(fc)]'
     comment: ''
     maxoutbuf: '0'
     minoutbuf: '0'
diff --git a/apps/grgsm_livemon_headless.grc b/apps/grgsm_livemon_headless.grc
index f4d5945..8e2e3fa 100644
--- a/apps/grgsm_livemon_headless.grc
+++ b/apps/grgsm_livemon_headless.grc
@@ -315,7 +315,7 @@
   parameters:
     affinity: ''
     alias: ''
-    cell_allocation: '[0]'
+    cell_allocation: '[arfcn.downlink2arfcn(fc)]'
     comment: ''
     maxoutbuf: '0'
     minoutbuf: '0'
diff --git a/cmake/Modules/GrccCompile.cmake b/cmake/Modules/GrccCompile.cmake
index 4589fd4..d2bc2d8 100644
--- a/cmake/Modules/GrccCompile.cmake
+++ b/cmake/Modules/GrccCompile.cmake
@@ -39,6 +39,7 @@
         OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${file_name}
         COMMAND "${CMAKE_COMMAND}"
         -E env PYTHONPATH="${PYTHONPATH}" GRC_BLOCKS_PATH=${CMAKE_SOURCE_DIR}/grc
+        CMAKE_BINARY_DIR=${CMAKE_BINARY_DIR}
         ${GRCC} -o ${CMAKE_CURRENT_BINARY_DIR}
         ${CMAKE_CURRENT_SOURCE_DIR}/${file_name}.grc
         COMMAND "${CMAKE_COMMAND}" -E rename ${CMAKE_CURRENT_BINARY_DIR}/${file_name}.py ${CMAKE_CURRENT_BINARY_DIR}/${file_name}
diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt
index f0c984d..9cd7045 100644
--- a/python/CMakeLists.txt
+++ b/python/CMakeLists.txt
@@ -47,7 +47,8 @@
 include(GrTest)
 
 set(GR_TEST_TARGET_DEPS gr-gsm)
-set(GR_TEST_PYTHON_DIRS ${CMAKE_BINARY_DIR}/swig:${CMAKE_BINARY_DIR}/python/misc_utils:${CMAKE_BINARY_DIR}/python/receiver:${CMAKE_BINARY_DIR}/python/demapping:${CMAKE_BINARY_DIR}/python/transmitter)
+set(GR_TEST_PYTHON_DIRS ${CMAKE_BINARY_DIR}/swig:${CMAKE_BINARY_DIR}/python/misc_utils)
+set(GR_TEST_ENVIRONS "CMAKE_BINARY_DIR=${CMAKE_BINARY_DIR}")
 GR_ADD_TEST(qa_arfcn ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_arfcn.py)
 GR_ADD_TEST(qa_decryption ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_decryption.py)
 GR_ADD_TEST(qa_burst_printer ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_burst_printer.py)
diff --git a/python/__init__.py b/python/__init__.py
index ba5fc00..87a62d6 100644
--- a/python/__init__.py
+++ b/python/__init__.py
@@ -23,6 +23,25 @@
 description here (python/__init__.py).
 '''
 
+import os
+
+if "CMAKE_BINARY_DIR" in os.environ:
+    dirname, filename = os.path.split(os.path.abspath(__file__))
+
+    # As the directory structure in the repository is different then the one after the package
+    # gets installed we need to add those subdirectories to the __path__ otherwise python3 is
+    # not able to load the modules using the relative import syntax and grcc compilation and
+    # some unit tests fail.
+    __path__ += [
+        # Load the local (not yet installed) grgsm_swig from the ../swig subdirectory.
+        os.path.join(os.environ.get("CMAKE_BINARY_DIR"), "swig"),
+
+        # Load the local (not yet installed) python modules from the local subdirectories
+        os.path.join(dirname, "misc_utils"),
+        os.path.join(dirname, "receiver"),
+        os.path.join(dirname, "demapping"),
+        os.path.join(dirname, "transmitter"),
+        os.path.join(dirname, "trx")]
 
 # import swig generated symbols into the gsm namespace
 from .grgsm_swig import *

-- 
To view, visit https://gerrit.osmocom.org/c/gr-gsm/+/24075
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: gr-gsm
Gerrit-Branch: master
Gerrit-Change-Id: I223fd6181e8e36027039301186b671712a597ff8
Gerrit-Change-Number: 24075
Gerrit-PatchSet: 1
Gerrit-Owner: ptrkrysik <ptrkrysik at gmail.com>
Gerrit-Reviewer: ptrkrysik <ptrkrysik at gmail.com>
Gerrit-Reviewer: vvvelichkov <vvvelichkov at gmail.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210503/6e5a342c/attachment.htm>


More information about the gerrit-log mailing list