Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Real python package #45

Open
wants to merge 49 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
f354821
python package
maxime-desroches Jul 12, 2024
a63fce0
x
maxime-desroches Jul 12, 2024
1e7adac
test
maxime-desroches Jul 12, 2024
c0c93f7
no pre-commit
maxime-desroches Jul 12, 2024
4b7c92c
fix
maxime-desroches Jul 12, 2024
9fa5079
instructions
maxime-desroches Jul 12, 2024
31f87db
version
maxime-desroches Jul 12, 2024
eb0541b
clean
maxime-desroches Jul 13, 2024
f1230d7
wheels
maxime-desroches Jul 13, 2024
d214410
par
maxime-desroches Jul 13, 2024
2ea36b5
39
maxime-desroches Jul 13, 2024
dd3ba67
np
maxime-desroches Jul 13, 2024
6ba9222
real wheel
maxime-desroches Jul 17, 2024
c26fce5
wheel
maxime-desroches Jul 17, 2024
09470ce
mapping
maxime-desroches Jul 17, 2024
890c2c4
yml...
maxime-desroches Jul 17, 2024
735f342
'
maxime-desroches Jul 17, 2024
76e25cf
use this image
maxime-desroches Jul 17, 2024
f1ce983
aarch64
maxime-desroches Jul 17, 2024
a8db4b4
test aarch
maxime-desroches Jul 17, 2024
e382021
fake test
maxime-desroches Jul 18, 2024
3bba17a
macos
maxime-desroches Jul 18, 2024
b85776a
skip
maxime-desroches Jul 18, 2024
5a98383
archs
maxime-desroches Jul 18, 2024
5cd9791
fix
maxime-desroches Jul 18, 2024
ae7409e
nproc
maxime-desroches Jul 18, 2024
016609d
try
maxime-desroches Jul 18, 2024
d022fe4
freeling
maxime-desroches Jul 18, 2024
f8ee985
try
maxime-desroches Jul 18, 2024
2c765de
scons
maxime-desroches Jul 18, 2024
1139a9d
test
maxime-desroches Jul 18, 2024
6073df9
py lib
maxime-desroches Jul 18, 2024
86b5b79
try
maxime-desroches Jul 18, 2024
a24e8ce
try this
maxime-desroches Jul 18, 2024
754355c
should work
maxime-desroches Jul 18, 2024
a4f1977
get arch test
maxime-desroches Jul 18, 2024
b3499f7
fix all
maxime-desroches Jul 18, 2024
fec51dd
clean
maxime-desroches Jul 18, 2024
1988025
test this
maxime-desroches Jul 20, 2024
376c1d3
sudo
maxime-desroches Jul 20, 2024
5598c22
fix
maxime-desroches Jul 20, 2024
39327b7
macos
maxime-desroches Jul 20, 2024
a4bd7c0
try
maxime-desroches Jul 20, 2024
b5f49d1
fix
maxime-desroches Jul 20, 2024
c62a75a
cleanup
maxime-desroches Jul 20, 2024
6e3b10c
fix
maxime-desroches Jul 20, 2024
dde0fcb
fix install
maxime-desroches Jul 20, 2024
2401657
last one
maxime-desroches Jul 20, 2024
b9555c0
remove this
maxime-desroches Jul 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 55 additions & 23 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,65 @@ name: tests

on: [push, pull_request]

env:
REGISTRY: ghcr.io/commaai
BUILD: docker buildx build --pull --load --cache-to type=inline --cache-from $REGISTRY/rednose:latest -t rednose -f Dockerfile .
RUN: docker run rednose bash -c

jobs:
test:
runs-on: ubuntu-latest
static_analysis:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: Build docker image
run: eval ${{ env.BUILD }}
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Installing requirements
run:
python -m pip install -r requirements.txt
- name: Static analysis
run: ${{ env.RUN }} "git init && git add -A && pre-commit run --all"
- name: Unit Tests
run: ${{ env.RUN }} "pytest"
run: pre-commit run --all

scons_test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ["ubuntu-20.04", "ubuntu-24.04", "macos-14"]
python: ["3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- name: Installing python requirements
run:
python -m pip install -r requirements.txt
- name: Installing ubuntu requirements
if: ${{startsWith(matrix.os, 'ubuntu')}}
run:
scripts/ubuntu_dependencies.sh
- name: Installing macos requirements
if: ${{startsWith(matrix.os, 'macos')}}
run:
scripts/macos_dependencies.sh
- name: Building
run: scons -j$(nproc || sysctl -n hw.logicalcpu)

docker_push:
name: docker push
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master' && github.event_name != 'pull_request' && github.repository == 'commaai/rednose'
full_test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ["ubuntu-20.04", "ubuntu-24.04", "macos-14"]
python: ["3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Build Docker image
run: eval ${{ env.BUILD }}
- name: Push to dockerhub
run: |
docker login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }}
docker tag rednose ${{ env.REGISTRY }}/rednose:latest
docker push ${{ env.REGISTRY }}/rednose:latest
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- name: Installing ubuntu requirements
if: ${{startsWith(matrix.os, 'ubuntu')}}
run:
scripts/ubuntu_dependencies.sh
- name: Installing macos requirements
if: ${{startsWith(matrix.os, 'macos')}}
run:
scripts/macos_dependencies.sh
- name: Installing rednose
run: pip install -e .[dev]
- name: Running all tests
run: pytest
51 changes: 51 additions & 0 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: wheels

on: [push, pull_request]

jobs:
wheels:
runs-on: ${{ matrix.platform.os }}
strategy:
fail-fast: true
matrix:
platform: [ {os: "ubuntu-latest", target: "manylinux_x86_64", arch: "x86_64"},
{os: "ubuntu-latest", target: "manylinux_aarch64", arch: "aarch64"},
{os: "macos-14", target: "macosx_arm64", arch: "arm64"} ]
python: [ {cp: "cp311", py: "3.11"}, {cp: "cp312", py: "3.12"} ]

steps:
- uses: actions/checkout@v4

- name: Set up QEMU
if: runner.os == 'Linux'
uses: docker/setup-qemu-action@v3
with:
platforms: all

- name: Building wheel
uses: pypa/[email protected]
env:
CIBW_BUILD: "${{ matrix.python.cp }}-${{ matrix.platform.target }}"
CIBW_ARCHS: "${{ matrix.platform.arch }}"
CIBW_BEFORE_ALL_LINUX: "dnf install -y clang libffi-devel eigen3-devel python${{ matrix.python.py }}-devel"
CIBW_BEFORE_BUILD_MACOS: "bash {project}/scripts/macos_dependencies.sh"
CIBW_MANYLINUX_X86_64_IMAGE: "manylinux_2_28"
CIBW_MANYLINUX_AARCH64_IMAGE: "manylinux_2_28"
CIBW_TEST_COMMAND: pip install -r {project}/requirements.txt && pytest {package}


- uses: actions/setup-python@v5
if: ${{ matrix.platform.arch != 'aarch64' }}
with:
python-version: ${{ matrix.python.py }}

- name: Installing the wheel
if: ${{ matrix.platform.arch != 'aarch64' }}
run: |
pip install --break-system-packages ./wheelhouse/*.whl

- name: Saving wheel
uses: actions/upload-artifact@v4
with:
name: cibw-wheels-${{ matrix.platform.target }}-${{ matrix.python.cp }}
path: ./wheelhouse/*.whl
14 changes: 0 additions & 14 deletions Dockerfile

This file was deleted.

5 changes: 5 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
exclude rednose/**/*.o
include SConstruct
include rednose/SConscript
include rednose/examples/SConscript
recursive-include site_scons *
24 changes: 19 additions & 5 deletions SConstruct
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
import os
import platform
import subprocess
import sysconfig
import numpy as np

arch = subprocess.check_output(["uname", "-m"], encoding='utf8').rstrip()
if platform.system() == "Darwin":
arch = "Darwin"

common = ''
py_include = sysconfig.get_paths()['include']

python_path = sysconfig.get_paths()['include']
libpath = []
cpppath = [
'#',
'#rednose',
'#rednose/examples/generated',
'/usr/lib/include',
python_path,
py_include,
np.get_include(),
]

if arch == "Darwin":
brew_prefix = subprocess.check_output(['brew', '--prefix'], encoding='utf8').strip()
libpath += [
f"{brew_prefix}/lib",
]
cpppath += [
f"{brew_prefix}/include",
]

env = Environment(
ENV=os.environ,
CC='clang',
Expand All @@ -32,7 +45,7 @@ env = Environment(
"-Werror=format-extra-args",
"-Wshadow",
],
LIBPATH=["#rednose/examples/generated"],
LIBPATH=libpath + ["#rednose/examples/generated"],
CFLAGS="-std=gnu11",
CXXFLAGS="-std=c++1z",
CPPPATH=cpppath,
Expand All @@ -43,17 +56,18 @@ env = Environment(
# Cython build enviroment
envCython = env.Clone()
envCython["CCFLAGS"] += ["-Wno-#warnings", "-Wno-shadow", "-Wno-deprecated-declarations"]
envCython["CPPPATH"] += [py_include, np.get_include()]

envCython["LIBS"] = []
if arch == "Darwin":
envCython["LINKFLAGS"] = ["-bundle", "-undefined", "dynamic_lookup"]
elif arch == "aarch64":
envCython["LINKFLAGS"] = ["-shared"]
envCython["LIBS"] = [os.path.basename(python_path)]
envCython["LIBS"] = [os.path.basename(py_include)]
else:
envCython["LINKFLAGS"] = ["-pthread", "-shared"]

Export('env', 'envCython', 'common')

SConscript(['#rednose/SConscript'])
SConscript(['#examples/SConscript'])
SConscript(['#rednose/examples/SConscript'])
29 changes: 28 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
# https://beta.ruff.rs/docs/configuration/#using-pyprojecttoml
[project]
name = "rednose"
requires-python = ">= 3.11"
version = "0.1.0"

dependencies = [
"sympy",
"numpy<2.0",
"scipy",
"tqdm",
"cffi",
"scons",
"Cython",
"setuptools",
]

[project.optional-dependencies]
dev = [
"ruff",
"pre-commit",
"pytest",
"pytest-xdist",
]

[build-system]
requires = ["setuptools", "scons", "Cython", "numpy<2.0", "sympy", "pytest", "cffi"]
build-backend = "setuptools.build_meta"

[tool.ruff]
line-length = 160
target-version="py311"
Expand Down
2 changes: 2 additions & 0 deletions examples/SConscript → rednose/examples/SConscript
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Import('env')

env.AppendENVPath('PYTHONPATH', env["REDNOSE_ROOT"])

gen_dir = Dir('generated/').abspath

env.RednoseCompileFilter(
Expand Down
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
69 changes: 58 additions & 11 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,58 @@
ruff
sympy
numpy
scipy
tqdm
cffi
scons
pre-commit
Cython
pytest
pytest-xdist
# This file was autogenerated by uv via the following command:
# uv pip compile --all-extras -o requirements.txt pyproject.toml
cffi==1.16.0
# via rednose (pyproject.toml)
cfgv==3.4.0
# via pre-commit
cython==3.0.10
# via rednose (pyproject.toml)
distlib==0.3.8
# via virtualenv
execnet==2.1.1
# via pytest-xdist
filelock==3.15.4
# via virtualenv
identify==2.6.0
# via pre-commit
iniconfig==2.0.0
# via pytest
mpmath==1.3.0
# via sympy
nodeenv==1.9.1
# via pre-commit
numpy==1.26.4
# via
# rednose (pyproject.toml)
# scipy
packaging==24.1
# via pytest
platformdirs==4.2.2
# via virtualenv
pluggy==1.5.0
# via pytest
pre-commit==3.7.1
# via rednose (pyproject.toml)
pycparser==2.22
# via cffi
pytest==8.2.2
# via
# rednose (pyproject.toml)
# pytest-xdist
pytest-xdist==3.6.1
# via rednose (pyproject.toml)
pyyaml==6.0.1
# via pre-commit
ruff==0.5.3
# via rednose (pyproject.toml)
scipy==1.14.0
# via rednose (pyproject.toml)
scons==4.8.0
# via rednose (pyproject.toml)
setuptools==71.0.4
# via rednose (pyproject.toml)
sympy==1.13.1
# via rednose (pyproject.toml)
tqdm==4.66.4
# via rednose (pyproject.toml)
virtualenv==20.26.3
# via pre-commit
6 changes: 6 additions & 0 deletions scripts/macos_dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
brew bundle --file=- <<-EOS
brew "eigen"
cask "gcc-arm-embedded"
brew "gcc@13"
EOS
12 changes: 12 additions & 0 deletions scripts/ubuntu_dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

if [[ ! $(id -u) -eq 0 ]]; then
if [[ -z $(which sudo) ]]; then
echo "Please install sudo or run as root"
exit 1
fi
SUDO="sudo"
fi

$SUDO apt-get update
$SUDO apt-get install -y --no-install-recommends clang libeigen3-dev
Loading