Skip to content

Commit

Permalink
python package
Browse files Browse the repository at this point in the history
  • Loading branch information
maxime-desroches committed Jul 12, 2024
1 parent 3ad6816 commit f354821
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 54 deletions.
40 changes: 20 additions & 20 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,33 @@ 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
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Build docker image
run: eval ${{ env.BUILD }}
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Installing build dependencies
run: ./install_dependencies.sh
- name: Installing rednose
run: pip3 install --break-system-packages .[dev]
- name: Static analysis
run: ${{ env.RUN }} "git init && git add -A && pre-commit run --all"
run: pre-commit run --all
- name: Unit Tests
run: ${{ env.RUN }} "pytest"
run: pytest

docker_push:
name: docker push
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master' && github.event_name != 'pull_request' && github.repository == 'commaai/rednose'
static_analysis:
runs-on: ubuntu-24.04
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
- name: Installing build dependencies
run: ./install_dependencies.sh
- name: Installing rednose
run: pip3 install --break-system-packages .[dev]
- name: Static analysis
run: pre-commit run --all
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 examples/SConscript
recursive-include site_scons *
2 changes: 2 additions & 0 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ env = Environment(
tools=["default", "cython", "rednose_filter"],
)

env.AppendENVPath('PYTHONPATH', '.')

# Cython build enviroment
envCython = env.Clone()
envCython["CCFLAGS"] += ["-Wno-#warnings", "-Wno-shadow", "-Wno-deprecated-declarations"]
Expand Down
20 changes: 20 additions & 0 deletions install_dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"

cd $DIR

SUDO=""

# Use sudo if not root
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 capnproto libcapnp-dev clang wget git autoconf libtool curl make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python3-openssl libeigen3-dev python3-pip python3-dev

28 changes: 27 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
# https://beta.ruff.rs/docs/configuration/#using-pyprojecttoml
[project]
name = "rednose"
requires-python = ">= 3.8"
version = "0.1.0"

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

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

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

[tool.ruff]
line-length = 160
target-version="py311"
Expand Down
11 changes: 0 additions & 11 deletions requirements.txt

This file was deleted.

42 changes: 20 additions & 22 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
from setuptools import Command, setup
from setuptools.command.build import build
import subprocess
import os
from setuptools import setup, find_packages

here = os.path.abspath(os.path.dirname(__file__))
class SconsBuild(Command):
def initialize_options(self) -> None:
pass

def finalize_options(self) -> None:
pass

def run(self) -> None:
subprocess.run(["scons -j$(nproc)"], shell=True).check_returncode()

class CustomBuild(build):
sub_commands = [('scons_build', None)] + build.sub_commands

setup(
name='rednose',
version='0.0.1',
url='https://github.com/commaai/rednose',
author='comma.ai',
author_email='harald@comma.ai',
packages=find_packages(),
platforms='any',
license='MIT',
package_data={'': ['helpers/chi2_lookup_table.npy', 'templates/*']},
install_requires=[
'sympy',
'numpy',
'scipy',
'tqdm',
'cffi',
],
ext_modules=[],
description="Kalman filter library",
long_description='See https://github.com/commaai/rednose',
)
packages = ["rednose", "examples", "rednose.helpers"],
package_data={'': ['**/*.cc', '**/*.c', '**/*.h', '**/*.pxd', '**/*.pyx', '**/*.py', '**/*.so', '**/*.npy']},
include_package_data=True,
cmdclass={'build': CustomBuild, 'scons_build': SconsBuild}
)

0 comments on commit f354821

Please sign in to comment.