forked from basler/pypylon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
executable file
·840 lines (688 loc) · 26.4 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
#!/usr/bin/env python
from __future__ import print_function
from setuptools import setup, Extension
from distutils import spawn
from distutils.dir_util import copy_tree
from distutils.version import LooseVersion
from logging import info, warning, error
import argparse
import ctypes
import datetime
import glob
import os
import re
import shutil
import subprocess
import sys
import platform
import VersionInfo;
ErrFileNotFound = FileNotFoundError if sys.version_info.major >= 3 else OSError
################################################################################
def get_machinewidth():
# From the documentation of 'platform.architecture()':
# "Note:
# On Mac OS X (and perhaps other platforms), executable files may be
# universal files containing multiple architectures. To get at the
# '64-bitness# of the current interpreter, it is more reliable to query
# the sys.maxsize attribute.
# "
if sys.maxsize > 2147483647:
return 64
else:
return 32
def get_platform():
return platform.system()
class BuildSupport(object):
# --- Constants ---
# Mapping from python platform to pylon platform dirname
BinPath = {
('Windows', 32): 'Win32',
('Windows', 64): 'x64',
('Linux', 32): 'lib',
('Linux', 64): 'lib64',
('Darwin', 64): 'lib64'
} [ (get_platform(), get_machinewidth()) ]
# Compatible swig versions
SwigVersions = ["3.0.12"]
SwigOptions = [
"-c++",
"-Wextra",
"-Wall",
"-threads",
"-modern",
"-DSWIG_PYTHON_LEGACY_BOOL",
]
# Where to place generated code
GeneratedDir = os.path.join(".", "generated")
# Directory of the final package
PackageDir = os.path.join(".", "pypylon")
# What parts of the runtime should be deployed by default
RuntimeDefaultDeploy = {
"base",
"gige",
"usb",
"camemu",
"gentl",
"extra",
"bcon",
}
# --- Attributes to be set by init (may be platform specific ---
# swig executable to be called
SwigExe = None
# Library dirs for compiling extensions
LibraryDirs = []
# Macro definitions for compiling extensions
DefineMacros = []
# Additional compiler arguments for extensions
ExtraCompileArgs = []
# Additional linker arguments for extensions
ExtraLinkArgs = []
# Runtime files needed for copy deployment
RuntimeFiles = {}
def get_swig_includes(self):
raise RuntimeError("Must be implemented by platform build support!")
def __init__(self):
self.SwigExe = "swig"
if sys.version_info[0] == 3:
self.SwigOptions.append("-py3")
def dump(self):
for a in dir(self):
info("%s=%s" % (a, getattr(self, a)))
def find_swig(self):
# Find SWIG executable
swig_executable = None
for candidate in ["swig3.0", "swig"]:
swig_executable = spawn.find_executable(candidate)
if self.is_supported_swig_version(swig_executable):
info("Found swig: %s" % (swig_executable,))
return swig_executable
raise RuntimeError("swig executable not found on path!")
def is_supported_swig_version(self, swig_executable):
if swig_executable is None:
return False
try:
output = subprocess.check_output([swig_executable, "-version"], universal_newlines=True)
except (subprocess.CalledProcessError, ErrFileNotFound):
return False
res = re.search(r"SWIG Version ([\d\.]+)", output)
if res is None:
return False
if LooseVersion(res.group(1)) < LooseVersion("3.0.12"):
warning("The version of swig is %s which is too old. Minimum required version is 3.0.12", res.group(1))
return False
return True
def call_swig(self, sourcedir, source, version):
name = os.path.splitext(source)[0]
cpp_name = os.path.abspath(
os.path.join(self.GeneratedDir, "%s_wrap.cpp" % name)
)
if not os.path.exists(self.GeneratedDir):
os.makedirs(self.GeneratedDir)
outdir = os.path.abspath(self.PackageDir)
if not os.path.exists(outdir):
os.makedirs(outdir)
for inc in self.get_swig_includes():
self.SwigOptions.append("-I%s" % inc)
if not args.skip_swig:
call_args = [self.SwigExe]
call_args.extend(["-python"])
call_args.extend(["-outdir", outdir])
call_args.extend(["-o", cpp_name])
call_args.extend(self.SwigOptions)
call_args.append(source)
print("call", " ".join(call_args))
subprocess.check_call(call_args, cwd=os.path.abspath(sourcedir))
# append module version property
with open(os.path.join(outdir, "%s.py" % name), 'at') as gpf:
gpf.write("\n__version__ = '%s'\n" % version)
# Python needs an __init__.py inside the package directory...
with open(os.path.join(bs.PackageDir, "__init__.py"), "a"):
pass
return cpp_name
def copy_runtime(self):
runtime_dir = os.path.join(
self.PylonDevDir,
"..",
"runtime",
self.BinPath
)
for package in self.RuntimeDefaultDeploy:
for pattern in self.RuntimeFiles[package]:
full_p = os.path.abspath(os.path.join(runtime_dir, pattern))
for f in glob.glob(full_p):
print("Copy %s => %s" % (f, self.PackageDir))
shutil.copy(f, self.PackageDir)
def clean(self, additional_dirs=None):
clean_dirs = [self.GeneratedDir, self.PackageDir]
if additional_dirs:
clean_dirs.extend(additional_dirs)
for cdir in clean_dirs:
print("Remove:", cdir)
shutil.rmtree(cdir, ignore_errors=True)
def get_pylon_version(self):
raise RuntimeError("Must be implemented by platform build support!")
def use_debug_configuration(self):
raise RuntimeError("Must be implemented by platform build support!")
@staticmethod
def get_git_version():
try:
# GIT describe as version
git_version = subprocess.check_output(
["git", "describe", "--tags", "--dirty"],
universal_newlines=True
)
git_version = git_version.strip()
m_rel = re.match(r"^\d+(?:\.\d+){2,3}(?:(?:a|b|rc)\d*)?$", git_version)
#this will match something like 1.0.0-14-g123456 and 1.0.0-14-g123456-dirty and 1.0.0-dirty
m_dev = re.match(r"^(\d+(?:\.\d+){2,3}(?:(?:a|b|rc)\d*)?)(?:-(\d+)-g[0-9a-f]+)?(?:-dirty)?$", git_version)
if m_rel:
# release build -> return as is
return git_version
if m_dev:
# development build
return "%s.dev%s" % (m_dev.group(1), m_dev.group(2) or 0)
warning("failed to parse git version '%s'", git_version)
raise OSError
except (OSError, subprocess.CalledProcessError) as e:
warning("git not found or invalid tag found.")
warning("-> Building version from date!")
now = datetime.datetime.now()
midnight = datetime.datetime(now.year, now.month, now.day)
todays_seconds = (now - midnight).seconds
return "%d.%d.%d.dev%d" % (now.year, now.month, now.day, todays_seconds)
def get_version(self):
git_version = self.get_git_version()
pylon_version = self.get_pylon_version()
#strip the build number from the pylon version
#on linux an optional tag might be included in the version
match = re.match(r"^(\d+\.\d+\.\d+)\.\d+(.*)", pylon_version)
pylon_version_no_build = match.group(1)
pylon_version_tag = match.group(2)
if pylon_version_no_build == VersionInfo.ReferencePylonVersion[get_platform()] and pylon_version_tag == '':
return git_version
#remove all characters forbidden in a local version (- and _ get normalized anyways)
pylon_version_tag_cleaned=re.sub(r"[^a-zA-Z0-9\.-_]",'',pylon_version_tag)
return "%s+pylon%s%s" % (git_version, pylon_version_no_build, pylon_version_tag_cleaned)
def get_short_version(self, version):
return version.split('+')[0]
@staticmethod
def make():
if get_platform() == "Windows":
return BuildSupportWindows()
elif get_platform() == "Linux":
return BuildSupportLinux()
elif get_platform() == "Darwin":
return BuildSupportMacOS()
else:
error("Unsupported platform")
################################################################################
class BuildSupportWindows(BuildSupport):
# Base directory for pylon SDK on Windows
PylonDevDir = None
DefineMacros = [
("UNICODE", None),
("_UNICODE", None),
# let swig share its type information between the 'genicam' and the
# 'pylon' module by using the same name for the type table.
("SWIG_TYPE_TABLE", "pylon")
]
ExtraCompileArgs = [
'/Gy', # separate functions for linker
'/GL', # enable link-time code generation
'/EHsc', # set execption handling model
]
ExtraLinkArgs = [
'/OPT:REF', # eliminate unused functions
'/OPT:ICF', # eliminate identical COMDAT
'/LTCG' # link time code generation
]
RuntimeFiles = {
"base": [
"PylonBase_*.dll",
"GCBase_MD_*.dll",
"GenApi_MD_*.dll",
"log4cpp_MD_*.dll",
"Log_MD_*.dll",
"NodeMapData_MD_*.dll",
"XmlParser_MD_*.dll",
"MathParser_MD_*.dll",
],
"gige": [
"PylonGigE_*.dll",
"gxapi*.dll",
],
"usb": [
"PylonUsb_*.dll",
"uxapi*.dll",
],
"camemu": [
"PylonCamEmu_*.dll"
],
"1394": [
"Pylon1394_*.dll",
"BcamError_*.dll",
"Basler_A1_A3_A6_1394.zip",
"Basler_scout_1394.zip",
],
"bcon": [
"BconAdapterPleora.dll",
"bxapi_*.dll",
"PylonBcon_*.dll",
],
"extra": [
"PylonGUI_*.dll",
"PylonUtility_*.dll"
],
"gentl": [
"PylonGtc_*.dll"
],
}
def __init__(self):
super(BuildSupportWindows, self).__init__()
self.SwigExe = self.find_swig()
self.SwigOptions.append("-DHAVE_PYLON_GUI")
self.SwigOptions.append("-D_WIN32")
if get_machinewidth() != 32:
self.SwigOptions.append("-D_WIN64")
self.PylonDevDir = os.environ.get("PYLON_DEV_DIR")
if not self.PylonDevDir:
raise EnvironmentError("PYLON_DEV_DIR is not set")
self.LibraryDirs = [
os.path.join(
self.PylonDevDir,
"lib",
self.BinPath
)
]
for inc in self.get_swig_includes():
self.ExtraCompileArgs.append('/I%s' % inc)
def get_swig_includes(self):
return [os.path.join(self.PylonDevDir, "include")]
def use_debug_configuration(self):
self.ExtraCompileArgs.append('/Od') # disable optimizations
self.ExtraCompileArgs.append('/Zi') # create debug info
self.ExtraLinkArgs.append('/DEBUG') # create pdb file
def find_swig(self):
#this searches for swigwin-<version>\swig.exe at the usual places
env_names = ['PROGRAMFILES', 'PROGRAMFILES(X86)', 'PROGRAMW6432']
search = [os.environ[n] for n in env_names if n in os.environ]
for prg in search:
for swig_version in self.SwigVersions:
candidate = os.path.join(
prg,
"swigwin-%s" % swig_version,
"swig.exe"
)
if self.is_supported_swig_version(candidate):
info("Found swig: %s" % (candidate,))
return candidate
#fallback to the standard implementation
return BuildSupport.find_swig(self)
def copy_runtime(self):
super(BuildSupportWindows, self).copy_runtime()
# detect OS and target bitness
os_bits = 64
if os.environ['PROCESSOR_ARCHITECTURE'] == 'x86':
# might be WOW
wow = os.environ.get('PROCESSOR_ARCHITEW6432', False)
if not wow:
os_bits = 32
tgt_bits = get_machinewidth()
# Copy msvc runtime for pylon
runtime_dlls = ["vcruntime140.dll", "msvcp140.dll"]
sysname = "System32" if tgt_bits == 64 or os_bits == 32 else "SysWOW64"
sysdir = os.path.join(os.environ["windir"], sysname)
for dll in runtime_dlls:
src = os.path.join(sysdir, dll)
print("Copy %s => %s" % (src, self.PackageDir))
shutil.copy(src, self.PackageDir)
def get_pylon_version(self):
dll_dir = os.path.realpath(
os.path.join(
self.PylonDevDir,
"..",
"Runtime",
self.BinPath
)
)
dll_pattern = os.path.join(dll_dir, "PylonBase_*.dll")
lst = glob.glob(dll_pattern)
if lst:
dll_path = lst[0]
else:
raise EnvironmentError("could not find PylonBase")
# temporarily add dll dir to path
prev_path = os.environ['PATH']
os.environ['PATH'] = os.pathsep.join((dll_dir, prev_path))
pylon_version = [ctypes.c_uint() for _ in range(4)]
pylon_base = ctypes.CDLL(dll_path)
pylon_base.GetPylonVersion(*list(map(ctypes.byref, pylon_version)))
#restore path
os.environ['PATH'] = prev_path
return ".".join([str(v.value) for v in pylon_version])
################################################################################
class BuildSupportLinux(BuildSupport):
PylonConfig = os.path.join(
os.getenv('PYLON_ROOT', '/opt/pylon5'),
'bin/pylon-config'
)
DefineMacros = [
("SWIG_TYPE_TABLE", "pylon")
]
ExtraCompileArgs = [
'-Wno-unknown-pragmas',
'-fPIC',
'-g0',
'-Wall',
'-O3',
'-Wno-switch'
]
ExtraLinkArgs = [
'-g0',
'-Wl,--enable-new-dtags',
'-Wl,-rpath,$ORIGIN',
]
RuntimeFiles = {
"base": [
("libpylonbase-*.so", ""),
("libGCBase_*.so", ""),
("libGenApi_*.so", ""),
("liblog4cpp_*.so", ""),
("libLog_*.so", ""),
("libNodeMapData_*.so", ""),
("libXmlParser_*.so", ""),
("libMathParser_*.so", ""),
],
"gige": [
("libpylon_TL_gige-*.so", ""),
("libgxapi-*.so", ""),
],
"usb": [
("libpylon_TL_usb-*.so", ""),
("libuxapi-*.so", ""),
("pylon-libusb-*.so", ""),
],
"camemu": [
("libpylon_TL_camemu-*.so", ""),
],
"1394": [], # N/A
"bcon": [
("libbxapi*.so", ""),
("libpylon_TL_bcon-*.so", ""),
],
"extra": [
("libpylonutility-*.so", ""),
],
"gentl": [
("libpylon_TL_gtc*.so", ""),
],
}
def __init__(self):
super(BuildSupportLinux, self).__init__()
self.SwigExe = self.find_swig()
config_cflags = self.call_pylon_config("--cflags")
self.ExtraCompileArgs.extend(config_cflags.split())
print("ExtraCompileArgs:", self.ExtraCompileArgs)
config_libs = self.call_pylon_config("--libs")
self.ExtraLinkArgs.extend(config_libs.split())
print("ExtraLinkArgs:", self.ExtraLinkArgs)
config_libdir = self.call_pylon_config("--libdir")
self.LibraryDirs.extend(config_libdir.split())
print("LibraryDirs:", self.LibraryDirs)
def use_debug_configuration(self):
try:
self.ExtraCompileArgs.remove('-O3')
except ValueError:
pass
try:
self.ExtraCompileArgs.remove('-g0')
except ValueError:
pass
try:
self.ExtraLinkArgs.remove('-g0')
except ValueError:
pass
self.ExtraCompileArgs.append('-O0')
self.ExtraCompileArgs.append('-g3')
self.ExtraLinkArgs.append('-g3')
def get_swig_includes(self):
# add compiler include paths to list
includes = [i[2:] for i in self.ExtraCompileArgs if i.startswith("-I")]
return includes
def copy_runtime(self):
runtime_dir = self.call_pylon_config("--libdir")
for package in self.RuntimeDefaultDeploy:
for src, dst in self.RuntimeFiles[package]:
full_dst = os.path.abspath(os.path.join(self.PackageDir, dst))
if not os.path.exists(full_dst):
os.makedirs(full_dst)
src = os.path.join(runtime_dir, src)
for f in glob.glob(src):
print("Copy %s => %s" % (f, full_dst))
shutil.copy(f, full_dst)
def call_pylon_config(self, *args):
params = [self.PylonConfig]
params.extend(args)
try:
res = subprocess.check_output(params, universal_newlines=True)
except ErrFileNotFound:
error("Couldn't find pylon. Please install pylon in /opt/pylon5 or tell us the installation location using the PYLON_ROOT env variable")
raise
return res.strip()
def get_pylon_version(self):
return self.call_pylon_config("--version")
################################################################################
class BuildSupportMacOS(BuildSupport):
FrameworkPath = os.getenv('PYLON_ROOT', '/Library/Frameworks/')
FrameworkName = 'pylon.framework'
PylonConfig = os.path.join(FrameworkPath, FrameworkName, 'Versions/Current/Resources/Tools/pylon-config.sh')
DefineMacros = [
("SWIG_TYPE_TABLE", "pylon")
]
ExtraCompileArgs = [
'-Wno-unknown-pragmas',
'-fPIC',
'-g0',
'-Wall',
'-O3',
'-Wno-switch'
]
ExtraLinkArgs = [
'-g0',
'-Wl,-rpath,@loader_path',
'-Wl,-framework,pylon',
'-F' + FrameworkPath
]
def __init__(self):
super(BuildSupportMacOS, self).__init__()
self.SwigExe = self.find_swig()
includes_dir = os.path.abspath(os.path.join(self.PackageDir, "includes"))
old_cwd = os.getcwd()
if not os.path.isdir(includes_dir):
os.makedirs(includes_dir)
os.chdir(includes_dir)
# simulate implicit include path as swig is unaware of frameworks
fakeframeinclude = 'pylon'
if (os.path.islink(fakeframeinclude)):
os.remove(fakeframeinclude)
os.symlink(os.path.join(self.FrameworkPath, self.FrameworkName, 'Headers'), 'pylon')
os.chdir(old_cwd)
self.ExtraCompileArgs.append("-I{}".format(includes_dir))
self.ExtraCompileArgs.append('-I' + os.path.join(self.FrameworkPath, self.FrameworkName, 'Headers', 'GenICam'))
def call_pylon_config(self, *args):
params = [self.PylonConfig]
params.extend(args)
try:
res = subprocess.check_output(params, universal_newlines=True)
except ErrFileNotFound:
error("Couldn't find pylon. Please install pylon in %s or tell us the installation location using the PYLON_ROOT environment variable", self.FrameworkPath)
raise
# work around simple shells
badprefix='-n '
if res.startswith(badprefix):
res = res[len(badprefix):]
return res.strip()
def get_pylon_version(self):
return self.call_pylon_config("--version")
def get_swig_includes(self):
# add compiler include paths to list
includes = [i[2:] for i in self.ExtraCompileArgs if i.startswith("-I")]
# append framework paths manually
includes += [
os.path.join(self.FrameworkPath, self.FrameworkName, 'Headers'),
os.path.join(self.FrameworkPath, self.FrameworkName, 'Headers', 'GenICam')
]
return includes
def copy_runtime(self):
full_dst = os.path.join(os.path.abspath(self.PackageDir), self.FrameworkName)
if not os.path.exists(full_dst):
copy_tree(os.path.join(self.FrameworkPath, self.FrameworkName), full_dst, preserve_symlinks=1, update=1)
################################################################################
################################################################################
################################################################################
if __name__ == "__main__":
# Get a build support
bs = BuildSupport.make()
bs.dump()
# Parse command line for extra arguments
parser = argparse.ArgumentParser(
description="Build pypylon",
add_help=False
)
parser.add_argument(
"--pp-version",
default=bs.get_version(),
help="set version of packages (normally set by GIT info)"
)
parser.add_argument(
"--pp-debug",
action='store_true',
help="build debug configuration"
)
parser.add_argument(
"--swig-only",
action='store_true',
help="exit after swig generation"
)
parser.add_argument(
"--skip-swig",
action='store_true',
help="skip swig to allow compiling code that was patched after SWIG generated it."
)
parser.add_argument(
"--rebuild-doxygen",
action='store_true',
help="rebuild DoxyGenApi.i and DoxyPylon.i from PYLON_DEV_DIR"
)
parser.add_argument(
"--generate-python-doc",
action='store_true',
help="generate python doc for pypylon"
)
args, remainder = parser.parse_known_args()
# re-build argv so that setup likes it...
progname = sys.argv[0]
sys.argv = [progname] + remainder
# Check if help is requested...
help_mode = False
if "-h" in remainder or "--help" in remainder:
help_mode = True
parser.print_help()
if args.pp_debug:
bs.use_debug_configuration()
args.pp_version += '_dbg'
version = args.pp_version
if "clean" in remainder:
# Remove everything, including the "build" dir from setuptools
print("Cleaning...")
bs.clean(["build", "pypylon.egg-info"])
sys.exit(0)
if not help_mode:
if args.rebuild_doxygen:
print("Rebuilding DoxyGenApi.i and DoxyPylon.i")
subprocess.call("python scripts/builddoxy2swig/builddoxygen.py")
if not help_mode:
print("Building version:", version)
# Call swig for genicam and pylon extensions
if not help_mode:
genicam_wrapper_src = bs.call_swig(
"src/genicam",
"genicam.i",
version
)
pylon_wrapper_src = bs.call_swig(
"src/pylon",
"pylon.i",
version
)
if args.swig_only:
print("Stopping after swig...")
sys.exit(0)
# Copy the runtime DLLs
bs.copy_runtime()
else:
# mock to allow calling "--help" on setup
genicam_wrapper_src, pylon_wrapper_src = "", ""
# Define extensions
genicam_ext = Extension(
'pypylon._genicam',
[genicam_wrapper_src],
include_dirs=[
os.path.join(".", "src", "genicam") # for PyPortImpl.h
],
library_dirs=bs.LibraryDirs,
define_macros=bs.DefineMacros,
extra_compile_args=bs.ExtraCompileArgs,
extra_link_args=bs.ExtraLinkArgs,
)
pylon_ext = Extension(
'pypylon._pylon',
[pylon_wrapper_src],
include_dirs=[
os.path.join(".", "src"), # for PyPortImpl.h
],
library_dirs=bs.LibraryDirs,
define_macros=bs.DefineMacros,
extra_compile_args=bs.ExtraCompileArgs,
extra_link_args=bs.ExtraLinkArgs,
)
with open("README.md", "r") as fh:
long_description = fh.read()
# Now everything is in place to call setup...
#we must not use package_dir to allow develop installs
setup(
name='pypylon',
version=version,
author="Basler AG",
author_email="[email protected]",
description="The python wrapper for the Basler pylon Camera Software Suite.",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/basler/pypylon",
ext_modules=[genicam_ext, pylon_ext],
test_suite='tests.all_emulated_tests',
packages=["pypylon"],
package_data={
"pypylon": ["*.dll", "*.zip", "*.so",
"*.framework/Versions/[A-Z]/*",
"*.framework/Versions/[A-Z]/Libraries/*",
"*.framework/Versions/[A-Z]/Resources/*",
"*.framework/Versions/[A-Z]/Resources/*/*",
"*.framework/Versions/[A-Z]/Resources/*/*/*",
"*.framework/Versions/[A-Z]/Resources/*/*/*/*"]
},
classifiers=[
"License :: Other/Proprietary License", #Proprietary license as the resulting install contains pylon which is under the pylon license
"Programming Language :: C++",
"Operating System :: Microsoft :: Windows :: Windows 7",
"Operating System :: Microsoft :: Windows :: Windows 8",
"Operating System :: Microsoft :: Windows :: Windows 10",
"Operating System :: POSIX :: Linux",
"Topic :: Multimedia :: Graphics :: Capture :: Digital Camera",
"Topic :: Multimedia :: Video :: Capture",
"Topic :: Scientific/Engineering",
]
)
if args.generate_python_doc:
print("Generating doc for python API")
subprocess.call("python scripts/generatedoc/generatedoc.py")