Skip to content

Commit 48bf566

Browse files
AndrewQuijanolacraig2
authored andcommitted
Replace setup.py with everything using pip now
1 parent 3370902 commit 48bf566

File tree

7 files changed

+144
-168
lines changed

7 files changed

+144
-168
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ trace-ust-all.h
147147
trace-ust-all.c
148148

149149
.vscode/
150+
.idea/
150151

151152
# Pypanda Examples
152153
pwc_log

Dockerfile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ RUN git -C /panda submodule update --init dtc && \
5656
git -C /panda rev-parse HEAD > /usr/local/panda_commit_hash && \
5757
mkdir /panda/build && cd /panda/build && \
5858
python3 -m pip install setuptools_scm && \
59+
python3 -m pip install build && \
5960
python3 -m setuptools_scm -r .. --strip-dev 2>/dev/null >/tmp/savedversion && \
6061
/panda/configure \
6162
--target-list="${TARGET_LIST}" \
@@ -70,7 +71,8 @@ RUN PRETEND_VERSION=$(cat /tmp/savedversion) make -C /panda/build -j "$(nproc)"
7071
#### Develop setup: panda built + pypanda installed (in develop mode) - Stage 3
7172
FROM builder as developer
7273
RUN cd /panda/panda/python/core && \
73-
PRETEND_VERSION=$(cat /tmp/savedversion) python3 setup.py develop && \
74+
python3 create_panda_datatypes.py && \
75+
PRETEND_VERSION=$(cat /tmp/savedversion) pip install -e . && \
7476
ldconfig && \
7577
update-alternatives --install /usr/bin/python python /usr/bin/python3 10 && \
7678
cd /panda && \
@@ -90,11 +92,13 @@ RUN make -C /panda/build install && \
9092

9193
# Install pypanda
9294
RUN cd /panda/panda/python/core && \
93-
PRETEND_VERSION=$(cat /tmp/savedversion) python3 setup.py install
95+
python3 create_panda_datatypes.py --install && \
96+
PRETEND_VERSION=$(cat /tmp/savedversion) pip install .
9497
RUN python3 -m pip install --ignore-install pycparser && python3 -m pip install --force-reinstall --no-binary :all: cffi
9598
# Build a whl too
9699
RUN cd /panda/panda/python/core && \
97-
PRETEND_VERSION=$(cat /tmp/savedversion) python3 setup.py bdist_wheel
100+
python3 create_panda_datatypes.py --install && \
101+
PRETEND_VERSION=$(cat /tmp/savedversion) python3 -m build --wheel .
98102

99103
# BUG: PANDA sometimes fails to generate all the necessary files for PyPANDA. This is a temporary fix to detect and fail when this occurs
100104
RUN ls -alt $(pip show pandare | grep Location: | awk '{print $2}')/pandare/autogen/

panda/python/core/MANIFEST.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
graft pandare
2-
global-exclude *.py[cod] __pycache__ *.sw*
2+
prune pandare/include
3+
global-exclude *.py[cod] __pycache__ *.sw* .git*

panda/python/core/create_panda_datatypes.py

Lines changed: 72 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import sys
55
import shutil
6+
import argparse
67
if sys.version_info[0] < 3:
78
raise RuntimeError('Requires python3')
89

@@ -14,15 +15,16 @@
1415
# those include files. See panda/include/panda/README.pypanda for
1516
# so proscriptions wrt those headers we use here. They need to be kept
1617
# fairly clean if we are to be able to make sense of them with this script
17-
# which isn't terriby clever.
18+
# which isn't terribly clever.
1819

19-
# Also copy all of the generated plog_pb2.py's into pandare/plog_pb/
20+
# Also copy all the generated plog_pb2.py's into pandare/plog_pb/
2021
# XXX: WIP if we do this this file should be renamed
2122
root_dir = os.path.join(*[os.path.dirname(__file__), "..", "..", ".."]) # panda-git/ root dir
2223
build_root = os.path.join(root_dir, "build")
2324
lib_dir = os.path.join("pandare", "data")
2425

25-
for arch in ['arm', 'aarch64', 'i386', 'x86_64', 'ppc', 'mips', 'mipsel', 'mips64']:
26+
arches = ['arm', 'aarch64', 'i386', 'x86_64', 'ppc', 'mips', 'mipsel', 'mips64', 'mips64el']
27+
for arch in arches:
2628
softmmu = arch+"-softmmu"
2729
plog = os.path.join(*[build_root, softmmu, "plog_pb2.py"])
2830
if os.path.isfile(plog):
@@ -187,17 +189,12 @@ def include_this(pdth, fn):
187189
pdth.write(line)
188190
pn += 1
189191

190-
def compile(arch, bits, pypanda_headers, install, static_inc):
191-
#from ..ffi_importer import ffi
192+
def compile(arch, bits, pypanda_headers, include_dir):
192193
from cffi import FFI
193194
ffi = FFI()
194195

195196
ffi.set_source(f"panda_{arch}_{bits}", None)
196-
if install:
197-
import os
198-
include_dir = os.path.abspath(os.path.join(*[os.path.dirname(__file__), "pandare", "include"]))
199-
else:
200-
include_dir = static_inc
197+
201198

202199
def define_clean_header(ffi, fname):
203200
'''Convenience function to pull in headers from file in C'''
@@ -325,7 +322,7 @@ def expand_ppp_def(line):
325322
ffi.compile(verbose=True,debug=True,tmpdir='./pandare/autogen')
326323

327324

328-
def main(install=False,recompile=True):
325+
def main(recompile=True):
329326
'''
330327
Copy and reformat panda header files into the autogen directory
331328
@@ -338,8 +335,6 @@ def main(install=False,recompile=True):
338335
# out pypanda bits to go in INCLUDE_DIR files
339336
plugin_dirs = os.listdir(PLUGINS_DIR)
340337

341-
INCLUDE_DIR_PYP_INSTALL = 'os.path.abspath(os.path.join(*[os.path.dirname(__file__), "..", "..", "pandare", "data", "pypanda", "include"]))' # ... /python3.6/site-packages/panda/data/pypanda/include/
342-
343338
# We want the various cpu_loop_... functions
344339
create_pypanda_header("%s/exec/exec-all.h" % INCLUDE_DIR_CORE)
345340

@@ -631,7 +626,7 @@ def exception(self):
631626

632627
for arch in arches:
633628
print("Compiling headers for:", arch)
634-
compile(arch[0], arch[1], pypanda_headers, install, INCLUDE_DIR_PYP)
629+
compile(arch[0], arch[1], pypanda_headers, INCLUDE_DIR_PYP)
635630

636631
#ps = (
637632
# Process(target=compile, args=(arch[0], arch[1], pypanda_headers, install, INCLUDE_DIR_PYP))
@@ -641,5 +636,68 @@ def exception(self):
641636
#[p.join() for p in ps]
642637

643638

639+
# Check for PANDA binaries in /usr/local/bin/ or in our build directory
640+
# panda_binaries = ['/usr/local/bin/panda-system-{arch}' for arch in arches]
641+
# Do we actually care at this point?
642+
def copy_objs():
643+
'''
644+
Run to copy objects into a (local and temporary) python module before installing to the system.
645+
Shouldn't be run if you're just installing in develop mode
646+
'''
647+
print("Copying objects into pandare/data/pypanda/include")
648+
if os.path.isdir(lib_dir):
649+
shutil.rmtree(lib_dir)
650+
os.mkdir(lib_dir)
651+
652+
# Copy pypanda's include directory (different than core panda's) into a datadir
653+
pypanda_inc = os.path.join(*[root_dir, "panda", "python", "core", "pandare", "include"])
654+
if not os.path.isdir(pypanda_inc):
655+
raise RuntimeError(f"Could not find pypanda include directory at {pypanda_inc}")
656+
pypanda_inc_dest = os.path.join(*["pandare", "data", "pypanda", "include"])
657+
if os.path.isdir(pypanda_inc_dest):
658+
shutil.rmtree(pypanda_inc_dest)
659+
shutil.copytree(pypanda_inc, pypanda_inc_dest)
660+
661+
# For each arch, copy llvm-helpers
662+
# XXX Should these be in standard panda deb?
663+
# What actually uses these? Taint? Disabling for now
664+
'''
665+
# Check if we have llvm-support
666+
with open(os.path.join(*[build_root, 'config-host.mak']), 'r') as cfg:
667+
llvm_enabled = True if 'CONFIG_LLVM=y' in cfg.read() else False
668+
669+
for arch in arches:
670+
libname = "libpanda-"+arch+".so"
671+
softmmu = arch+"-softmmu"
672+
path = os.path.join(*[build_root, softmmu, libname])
673+
llvm1 = os.path.join(*[build_root, softmmu, "llvm-helpers.bc1"])
674+
llvm2 = os.path.join(*[build_root, softmmu, f"llvm-helpers-{arch}.bc"])
675+
676+
if os.path.isfile(path) is False:
677+
print(("Missing file {} - did you run build.sh from panda/build directory?\n"
678+
"Skipping building pypanda for {}").format(path, arch))
679+
continue
680+
681+
os.mkdir(os.path.join(lib_dir, softmmu))
682+
if llvm_enabled:
683+
shutil.copy( llvm1, os.path.join(lib_dir, softmmu))
684+
shutil.copy( llvm2, os.path.join(lib_dir, softmmu))
685+
'''
686+
687+
644688
if __name__ == '__main__':
689+
parser = argparse.ArgumentParser(prog='A python script to populate panda/autogen folder '
690+
'and prep for PyPanda wheel installation')
691+
parser.add_argument('--install', '-i', dest='install', action='store_true',
692+
help='If set, this means update pandare folder for installation')
693+
parser.add_argument('--recompile', '-r', dest='recompile', action='store_true',
694+
help='If set, recompile the headers with cffi')
695+
args = parser.parse_args()
696+
"""
697+
Install as a local module (not to system) by
698+
1) Creating datatype files for local-use
699+
2) Running regular setup tools logic
700+
"""
645701
main()
702+
if args.install:
703+
copy_objs()

panda/python/core/pyproject.toml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[build-system]
2+
requires = ["setuptools>=64", "wheel", "setuptools-scm>=8"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[tool.setuptools.packages.find]
6+
include = [
7+
"pandare",
8+
"pandare.*"
9+
]
10+
11+
[tool.setuptools.package-data]
12+
pandare = [
13+
"data/*-softmmu/llvm-helpers*.bc*", # LLVM Helpers
14+
"data/pypanda/include/*.h", # Includes files
15+
"qcows.json" # Generic Images
16+
]
17+
18+
# This is how to setup cmd replacement, we can figure this out later
19+
# [tool.setuptools.cmdclass]
20+
# install = "setup.custom_install"
21+
# develop = "setup.custom_develop"
22+
23+
[project]
24+
name = "pandare"
25+
dynamic = ["version"]
26+
description = "Python Interface to PANDA"
27+
readme = "README.md"
28+
authors = [
29+
{ name = "Luke Craig", email = "luke.craig@mit.edu" },
30+
{ name = "Andrew Fasano" },
31+
{ name = "Tim Leek" }
32+
]
33+
requires-python = ">=3.6"
34+
dependencies = [
35+
"cffi>=1.14.3",
36+
"protobuf>=4.25.1",
37+
"colorama"
38+
]
39+
40+
[tool.setuptools_scm]
41+
root = "../../.."
42+
fallback_version = "0.0.0.1"
43+
version_scheme = "guess-next-dev"
44+
local_scheme = "no-local-version"

0 commit comments

Comments
 (0)