Skip to content

Commit 00a8015

Browse files
Merge pull request #1925 from alicevision/dev/swigProgressDisplay
SwigBinding: Expose ProgressDisplay
2 parents 6f08078 + 4ebbdff commit 00a8015

File tree

6 files changed

+99
-2
lines changed

6 files changed

+99
-2
lines changed

pyTests/system/__init__.py

Whitespace-only changes.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
Collection of unit tests for the ProgressDisplay logger.
3+
"""
4+
5+
import pytest
6+
7+
from pyalicevision.system import ConsoleProgressDisplay
8+
9+
10+
PROGRESS_BAR_TEMPLATE = """{desc}
11+
0% 10 20 30 40 50 60 70 80 90 100%
12+
|----|----|----|----|----|----|----|----|----|----|
13+
"""
14+
15+
def test_progress_display(capfd):
16+
items = range(10)
17+
desc = "Iter over items"
18+
stars_by_item = "*" * (50 // len(items))
19+
progress = ConsoleProgressDisplay(len(items), desc + "\n")
20+
for index, _i in enumerate(items):
21+
assert(progress.count() == index)
22+
out, _ = capfd.readouterr() # readout is flushed each time we call this so we only have to check for diff
23+
if index == 0:
24+
assert out == PROGRESS_BAR_TEMPLATE.format(desc=desc)
25+
else:
26+
assert out == stars_by_item
27+
progress += 1

src/aliceVision/system/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,18 @@ alicevision_add_library(aliceVision_system
3636
)
3737

3838
alicevision_add_test(Logger_test.cpp NAME "system_Logger" LINKS aliceVision_system)
39+
40+
# SWIG Binding
41+
if (ALICEVISION_BUILD_SWIG_BINDING)
42+
alicevision_swig_add_library(system
43+
SOURCES System.i
44+
PUBLIC_LINKS
45+
aliceVision_system
46+
${Python3_LIBRARIES}
47+
PRIVATE_INCLUDE_DIRS
48+
../include
49+
${ALICEVISION_ROOT}/include
50+
${Python3_INCLUDE_DIRS}
51+
${Python3_NumPy_INCLUDE_DIRS}
52+
)
53+
endif()

src/aliceVision/system/ProgressDisplay.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,16 @@ class ProgressDisplay
4242
void restart(unsigned long expectedCount) { _impl->restart(expectedCount); }
4343

4444
// Thread safe with respect to other calls to operator++ and to calls to count()
45-
void operator++() { _impl->increment(1); }
45+
ProgressDisplay& operator++() {
46+
_impl->increment(1);
47+
return *this;
48+
}
4649

4750
// Thread safe with respect to other calls to operator++ and to calls to count()
48-
void operator+=(unsigned long increment) { _impl->increment(increment); }
51+
ProgressDisplay& operator+=(unsigned long increment) {
52+
_impl->increment(increment);
53+
return *this;
54+
}
4955

5056
// Thread safe with respect to calls to operator++
5157
unsigned long count() { return _impl->count(); }
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// This file is part of the AliceVision project.
2+
// Copyright (c) 2025 AliceVision contributors.
3+
// This Source Code Form is subject to the terms of the Mozilla Public License,
4+
// v. 2.0. If a copy of the MPL was not distributed with this file,
5+
// You can obtain one at https://mozilla.org/MPL/2.0/.
6+
7+
%include <aliceVision/system/ProgressDisplay.hpp>
8+
9+
%{
10+
#include <iostream>
11+
#include <aliceVision/system/ProgressDisplay.hpp>
12+
13+
// Use the full namespace in the wrapper
14+
namespace aliceVision {
15+
namespace system {
16+
17+
inline ProgressDisplay ConsoleProgressDisplay(unsigned long expectedCount,
18+
const std::string& s1 = "\n", // leading strings
19+
const std::string& s2 = "",
20+
const std::string& s3 = "")
21+
{
22+
return createConsoleProgressDisplay(expectedCount, std::cout, s1, s2, s3);
23+
}
24+
25+
} // namespace system
26+
} // namespace aliceVision
27+
28+
%}
29+
30+
// Declare the wrapper so SWIG knows it
31+
namespace aliceVision {
32+
namespace system {
33+
ProgressDisplay ConsoleProgressDisplay(unsigned long expectedCount,
34+
const std::string& s1 = "\n",
35+
const std::string& s2 = "",
36+
const std::string& s3 = "");
37+
}
38+
}

src/aliceVision/system/System.i

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// This file is part of the AliceVision project.
2+
// Copyright (c) 2025 AliceVision contributors.
3+
// This Source Code Form is subject to the terms of the Mozilla Public License,
4+
// v. 2.0. If a copy of the MPL was not distributed with this file,
5+
// You can obtain one at https://mozilla.org/MPL/2.0/.
6+
7+
%module (package="pyalicevision") system
8+
9+
%include <aliceVision/global.i>
10+
%include <aliceVision/system/ProgressDisplay.i>
11+

0 commit comments

Comments
 (0)