Skip to content

Fix debian package generation to include subdirectories #567

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ __pycache__/
*.so

# Distribution / packaging
*.tar.gz
.Python
env/
build/
deb_dist/
develop-eggs/
dist/
downloads/
Expand Down
48 changes: 1 addition & 47 deletions makedeb
Original file line number Diff line number Diff line change
@@ -1,49 +1,3 @@
#!/bin/sh

py=python3
name='canopen'
pkgname=$py-$name
description="CANopen stack implementation"

version=`git tag |grep -Eo '[0-9]+\.[0-9]+\.[0-9]+' |sort | tail -1 `
maintainer=`git log -1 --pretty=format:'%an <%ae>'`
arch=all

echo version: $version
echo maintainer: $maintainer

cd $(dirname $0)
package_dir=$PWD/build-deb/${pkgname}_$version-1_all
fakeroot=$package_dir

mkdir -p $fakeroot

$py setup.py bdist_wheel >setup_py.log

mkdir -p $fakeroot/usr/lib/$py/dist-packages/
unzip dist/*.whl -d $fakeroot/usr/lib/python3/dist-packages/

# deploy extra files
#cp -r install/* $fakeroot/

mkdir $package_dir/DEBIAN

cat > $package_dir/DEBIAN/control <<control_end
Package: $pkgname
Version: $version
Section: python
Priority: optional
Architecture: $arch
Maintainer: $maintainer
Description: $description
Depends: $py, $py-can
control_end


dpkg-deb --build --root-owner-group $package_dir






python3 setup.py --command-packages=stdeb.command bdist_deb
74 changes: 73 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,75 @@
#!/usr/bin/env python
import os
from setuptools import setup
import subprocess

setup()
def get_version():
"""
Get the version from a git tag

Executes
git tag |grep -Eo '[0-9]+\\.[0-9]+\\.[0-9]+' |sort | tail -1
and returns the result
"""
tag_proc = subprocess.Popen(
["git", "tag"],
cwd=".",
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL,
)
grep_proc = subprocess.Popen(
[
"grep",
"-Eo",
"[0-9]+\\.[0-9]+\\.[0-9]+"
],
stdin=tag_proc.stdout,
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL,
)
sort_proc = subprocess.Popen(
["sort"],
stdin=grep_proc.stdout,
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL,
)
tail_proc = subprocess.Popen(
["tail", "-1"],
stdin=sort_proc.stdout,
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL,
)
(stdout, _) = tail_proc.communicate()
stdout = stdout.decode()
return stdout.strip()


def enumerate_modules() -> list[str]:
"""
Enumerate all additional modules that need to be included in the package.

:return: The list of modules that should be included in the package
"""
modules = []
dotpy = ".py"
for root_dir, _, files in os.walk("canopen"):
for f in files:
if f.endswith(dotpy):
modules.append(
f"{root_dir.replace('/', '.')}.{f.replace(dotpy, '')}"
)
return modules


setup(
name="canopen",
version=get_version(),
description="CANopen stack implementation",
url="https://github.com/christiansandberg/canopen",
author="Christian Sandberg",
author_email="[email protected]",
license="MIT",
py_modules=enumerate_modules(),
install_requires=[],
)