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 28, 2022
1 parent d3998ea commit b5b0dbe
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 80 deletions.
6 changes: 5 additions & 1 deletion PyRedPitaya/raw_memory.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from ctypes import POINTER, c_uint32, cast, cdll, create_string_buffer, sizeof

import numpy as np
from pathlib import Path
from importlib.machinery import EXTENSION_SUFFIXES

libmonitor_file = "libmonitor.so"
libmonitor_file = str(Path(__file__).parent / '..' / 'monitor{}'.format(
EXTENSION_SUFFIXES[0]
))

libmonitor = 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,60 +1,14 @@
import os
from distutils.command.build import build
from distutils.command.install import install
from distutils.core import setup
from distutils.core import setup, Extension
from pathlib import Path

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 @@ -67,7 +21,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 @@ -82,4 +35,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 b5b0dbe

Please sign in to comment.