Skip to content

Commit

Permalink
Use python's setup.py to compile & install monitor
Browse files Browse the repository at this point in the history
Find monitor shared object file using a relative path to `__file__`.
  • Loading branch information
doronbehar committed Oct 25, 2022
1 parent f13da68 commit 21eb3eb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 80 deletions.
16 changes: 15 additions & 1 deletion PyRedPitaya/raw_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,25 @@
from ctypes import *
import numpy as np
from time import time
from os import path
import platform

if 'PyRedPitayaTest' in list(sys.modules.keys()):
from PyRedPitayaTest import libmonitor_file
else:
libmonitor_file = 'libmonitor.so'
# The path where monitor...so shared object is installed is sort of predictable
libmonitor_file = path.join(
path.join(
path.dirname(__file__), '..',
# linux-gnu is hardcoded since we are running this code on a red
# pitaya where it should be a GNU and not musl system, and most
# likely Linux
'monitor.cpython-{pyVer}-{machine}-linux-gnu.so'.format(
pyVer="".join(list(platform.python_version_tuple())[0:2]),
machine=platform.machine()
)
)
)

libmonitor = ctypes.cdll.LoadLibrary(libmonitor_file)
libmonitor.read_value.restype = c_uint32
Expand Down
31 changes: 0 additions & 31 deletions monitor/Makefile

This file was deleted.

50 changes: 2 additions & 48 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

from distutils.core import setup
from distutils.core import setup, Extension
from distutils.command.build import build
from distutils.command.install import install

Expand All @@ -9,55 +9,9 @@

from PyRedPitaya import __version__

# If we want to overrid the build processe
# For example, to compile de libmonitor and install it
# Install libmonitor only for redpitaya, i.e. when

build_dir = "monitor/"


def compile_libmonitor():
cwd = os.getcwd() # get current directory
try:
os.chdir(build_dir)
os.system("make clean")
os.system("make all")
finally:
os.chdir(cwd)


def install_libmonitor(prefix=""):
cwd = os.getcwd() # get current directory
try:
os.chdir(build_dir)
os.system("make install INSTALL_DIR={prefix}".format(prefix=prefix))
finally:
os.chdir(cwd)


class lib_build(build):
def run(self):
compile_libmonitor()
build.run(self)


class lib_install(install):
def run(self):
compile_libmonitor()
install_libmonitor(self.prefix)


# install.run(self)


cmdclass = {}
cmdclass["lib_build"] = lib_build
cmdclass["lib_install"] = lib_install

this_directory = Path(__file__).parent
long_description = (this_directory / "README.rst").read_text()


setup(
name="PyRedPitaya",
version=__version__,
Expand All @@ -70,7 +24,6 @@ def run(self):
long_description_content_type="text/rst",
packages=["PyRedPitaya", "PyRedPitaya.enum"],
install_requires=["myhdl", "rpyc", "cached_property", "numpy"],
cmdclass=cmdclass,
classifiers=[
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
Expand All @@ -85,4 +38,5 @@ def run(self):
"Topic :: Software Development :: Libraries :: Python Modules",
],
keywords=["redpitaya", "FPGA", "zynq"],
ext_modules=[Extension('monitor',['monitor/monitor.c'])]
)

0 comments on commit 21eb3eb

Please sign in to comment.