Skip to content

Commit 3613bfc

Browse files
committed
Add version check and update to use my fork for python bindings
1 parent c0edd8e commit 3613bfc

File tree

8 files changed

+63
-48
lines changed

8 files changed

+63
-48
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ pip install libcamera
1111
```
1212
If you have an older release of libcamera on your system then you may need to use `libcamera==version` to install the correct release.
1313

14+
### If you get a version error
15+
If you get the error `This package works with libcamera version ..., but you have version ... installed`, then this means the version strings are not matching. If you have built your own version of libcamera, then just pass `-C setup-args="-Dversion=unknown"` to skip this check and follow the instructions in the next section. If you have a system installed version of libcamera then you will need to check this table for the correct pip package version to install, based on the version of libcamera you have installed. These are the common versions found on Raspberry Pis.
16+
17+
| system and date | libcamera reported version | pip package version |
18+
| --------------- | -------------------------- | ------------------- |
19+
| Raspberry Pi Bookworm Oct 2023 | v0.1.0+52-a858d20b | 0.1a1 |
20+
1421
### If that doesn't work...
1522

1623
If you have built your own version of libcamera, or your system has a version which is not compatible with a release version, then you may need to pass the repository and revision to meson. The arguments to do this are `-C setup-args="-Drepository=https://my.repository.git"` for the repository and `-C setup-args="-Drevision=branch"` for the revision. These are passed directly into `git clone` and `git checkout` respectively, so and strings that work with those will work here. The `-C, --config-settings` argument require an up to date version of `pip>=23.1` so you may first need to run `pip install --upgrade pip`

check-version

69.8 KB
Binary file not shown.

check-version.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <iostream>
2+
#include <libcamera/camera_manager.h>
3+
4+
5+
int main()
6+
{
7+
std::cout << libcamera::CameraManager::version() << "\n";
8+
}

check-version.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
cc check-version.cpp -I libcamera/include -lcamera -lstdc++ -o check-version
4+
5+
./check-version

meson.build

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,24 @@ project('pylibcamera', 'c', 'cpp',
1010
],
1111
license : 'LGPL 2.1+')
1212

13+
if not get_option('pycamera').enabled()
14+
error('pycamera must be enabled')
15+
endif
16+
1317
message('Cloning from: @0@, revision @1@'.format(get_option('repository'), get_option('revision')))
1418

15-
r = run_command('clone-libcamera.sh', get_option('repository'), get_option('revision'), get_option('patch'), check : true)
19+
run_command('clone-libcamera.sh', get_option('repository'), get_option('revision'), get_option('patch'), check : true)
20+
21+
r = run_command('check-version.sh', capture : true)
22+
if r.returncode() == 0 and get_option('version') != 'unknown'
23+
version = r.stdout()
24+
message('libcamera version is @0@'.format(version))
25+
if version.strip() != get_option('version').strip()
26+
error('This package works with libcamera version @0@, but you have version @1@ installed. Please check the readme for help with this error'.format(get_option('version'), version))
27+
endif
28+
else
29+
message('Version Check Not Done')
30+
endif
1631

1732
libcamera_includes = include_directories('libcamera/include')
1833
libcamera_private = dependency(

meson_options.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,17 @@ option('revision',
1010
value : 'master',
1111
description : 'Git revision to checkout')
1212

13+
option('version',
14+
type : 'string',
15+
value : 'unknown',
16+
description : 'libcamera version')
17+
1318
option('patch',
1419
type : 'string',
1520
value : 'pypatch',
1621
description : 'Patch to apply')
22+
23+
option('pycamera',
24+
type : 'feature',
25+
value : 'enabled',
26+
description : 'Enable libcamera Python bindings - must be enabled')

pypatch.patch

Lines changed: 14 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,20 @@
11
diff --git a/src/py/libcamera/meson.build b/src/py/libcamera/meson.build
2-
index f58c7198..c65fc044 100644
2+
index 128793aa..1df65c54 100644
33
--- a/src/py/libcamera/meson.build
44
+++ b/src/py/libcamera/meson.build
5-
@@ -1,13 +1,13 @@
6-
# SPDX-License-Identifier: CC0-1.0
7-
8-
-py3_dep = dependency('python3', required : get_option('pycamera'))
9-
+py3_dep = py.dependency()
10-
11-
if not py3_dep.found()
12-
pycamera_enabled = false
13-
subdir_done()
14-
endif
15-
16-
-pybind11_dep = dependency('pybind11', required : get_option('pycamera'))
17-
+pybind11_dep = dependency('pybind11', required : true)
18-
19-
if not pybind11_dep.found()
20-
pycamera_enabled = false
21-
@@ -77,30 +77,3 @@ pycamera_args = [
5+
@@ -91,6 +91,7 @@ pycamera_args = [
6+
'-fvisibility=hidden',
227
'-Wno-shadow',
238
'-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT',
9+
+ '-DLIBCAMERA_BASE_PRIVATE',
2410
]
25-
-
26-
-destdir = get_option('libdir') / ('python' + py3_dep.version()) / 'site-packages' / 'libcamera'
27-
-
28-
-pycamera = shared_module('_libcamera',
29-
- pycamera_sources,
30-
- install : true,
31-
- install_dir : destdir,
32-
- name_prefix : '',
33-
- dependencies : pycamera_deps,
34-
- cpp_args : pycamera_args)
35-
-
36-
-# Create symlinks from the build dir to the source dir so that we can use the
37-
-# Python module directly from the build dir.
38-
-
39-
-run_command('ln', '-fsrT', files('__init__.py'),
40-
- meson.current_build_dir() / '__init__.py',
41-
- check : true)
42-
-
43-
-run_command('ln', '-fsrT', meson.current_source_dir() / 'utils',
44-
- meson.current_build_dir() / 'utils',
45-
- check : true)
46-
-
47-
-install_data(['__init__.py'], install_dir : destdir)
48-
-
49-
-# \todo Generate stubs when building. See https://peps.python.org/pep-0484/#stub-files
50-
-# Note: Depends on pybind11-stubgen. To generate pylibcamera stubs:
51-
-# $ PYTHONPATH=build/src/py pybind11-stubgen --no-setup-py -o build/src/py libcamera
11+
12+
if meson.is_cross_build()
13+
@@ -109,6 +110,7 @@ else
14+
install : true,
15+
subdir : 'libcamera',
16+
dependencies : pycamera_deps,
17+
+ include_directories : libcamera_includes,
18+
cpp_args : pycamera_args)
19+
endif
20+

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ Source = "https://github.com/will-v-pi/pylibcamera"
1414

1515
[tool.meson-python.args]
1616
setup = [
17-
'-Drevision=release-v0.0.5+83-bde9b04f',
18-
'-Drepository=https://github.com/raspberrypi/libcamera.git'
17+
'-Drevision=17d88f4',
18+
'-Drepository=https://github.com/will-v-pi/libcamera.git',
19+
'-Dversion=v0.1.0+99-4a23664b'
1920
]
2021

2122
[tool.flit.module]

0 commit comments

Comments
 (0)