agx-openplx 0.15.1__cp39-cp39-macosx_12_0_arm64.whl → 0.15.2__cp39-cp39-macosx_12_0_arm64.whl

Sign up to get free protection for your applications and to get access to all the features.
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
openplx/__init__.py CHANGED
@@ -1,51 +1,55 @@
1
- # pylint: disable=C0103 # name doesn't conform to snake_case naming style
1
+ # pylint: disable=invalid-name
2
2
  """
3
3
  __init__ module for OpenPLX package
4
4
  """
5
5
  import os
6
6
  import sys
7
- __AGXVERSION__ = "2.38.0.2"
8
- __version__ = "0.15.1"
9
-
10
- # pylint doesn't like bare excepts, but we need to catch all exceptions here
11
- # pylint: disable=W0702 # bare-except
12
- # pylint doesn't like below errors which is normally ok, but this file is copied to the right place during build
13
- # pylint: disable=E0402 # Attempted relative import beyond top-level
14
- # pylint: disable=E0611 # Missing name in module
15
- # pylint: disable=W0611 # Unused import
16
- # pylint: disable=W0401 # Wildcard import
7
+ import traceback
8
+ # Use agx_env if available
9
+ import importlib.util
10
+ if importlib.util.find_spec("agx_env"):
11
+ import agx_env # pylint: disable=unused-import
12
+ __AGXVERSION__ = "2.39.0.1"
13
+ __version__ = "0.15.2"
17
14
 
18
15
  try:
19
16
  import agx
20
17
  if agx.__version__ != __AGXVERSION__:
21
18
  print(f"This version of agx-openplx is compiled for AGX {__AGXVERSION__} and may crash with your {agx.__version__} version, "+
22
19
  "update agx-openplx or AGX to make sure the versions are suited for eachother")
23
- except:
20
+ except Exception as e: # pylint: disable=broad-exception-caught
21
+ traceback.print_exc()
24
22
  print("Failed finding AGX Dynamics, have you run setup_env?")
25
23
  sys.exit(255)
26
24
 
27
25
  if "DEBUG_AGXOPENPLX" in os.environ:
28
26
  print("#### Using Debug build ####")
29
27
  try:
28
+ # pylint: disable=relative-beyond-top-level, wildcard-import, unused-import, no-name-in-module
30
29
  from .debug.api import *
31
30
  from .debug import Core
32
31
  from .debug import Math
33
32
  from .debug import Physics
34
33
  from .debug import Simulation
35
- except:
34
+ # pylint: enable=relative-beyond-top-level, wildcard-import, unused-import, no-name-in-module
35
+ except Exception as e: # pylint: disable=broad-exception-caught
36
+ traceback.print_exc()
36
37
  print("Failed finding OpenPLX modules or libraries, did you set PYTHONPATH correctly? "+
37
- "Should point to where OpenPLX directory with binaries are located")
38
+ "Should point to where OpenPLX directory with binaries are located.")
38
39
  print("Also, make sure you are using the same Python version the libraries were built for.")
39
40
  sys.exit(255)
40
41
  else:
41
42
  try:
43
+ # pylint: disable=relative-beyond-top-level, wildcard-import, unused-import, no-name-in-module
42
44
  from .api import *
43
45
  from . import Core
44
46
  from . import Math
45
47
  from . import Physics
46
48
  from . import Simulation
47
- except:
49
+ # pylint: enable=relative-beyond-top-level, wildcard-import, unused-import, no-name-in-module
50
+ except Exception as e: # pylint: disable=broad-exception-caught
51
+ traceback.print_exc()
48
52
  print("Failed finding OpenPLX modules or libraries, did you set PYTHONPATH correctly? "+
49
- "Should point to where OpenPLX directory with binaries are located")
53
+ "Should point to where OpenPLX directory with binaries are located.")
50
54
  print("Also, make sure you are using the same Python version the libraries were built for.")
51
55
  sys.exit(255)
openplx/api.py CHANGED
@@ -407,117 +407,126 @@ class AgxToOpenPlxMapper(object):
407
407
  # Register AgxToOpenPlxMapper in _AgxOpenPlxPyApi:
408
408
  _AgxOpenPlxPyApi.AgxToOpenPlxMapper_swigregister(AgxToOpenPlxMapper)
409
409
 
410
- class Signals(object):
411
- r"""Proxy of C++ agxopenplx::Signals class."""
410
+ class InputSignalQueue(object):
411
+ r"""Proxy of C++ agxopenplx::InputSignalQueue class."""
412
412
 
413
413
  thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
414
+
415
+ def __init__(self, *args, **kwargs):
416
+ raise AttributeError("No constructor defined")
414
417
  __repr__ = _swig_repr
415
418
 
416
419
  @staticmethod
417
- def popInputSignals():
418
- r"""popInputSignals() -> Physics_Signals_InputSignal_Vector"""
419
- return _AgxOpenPlxPyApi.Signals_popInputSignals()
420
+ def create():
421
+ r"""create() -> std::shared_ptr< agxopenplx::InputSignalQueue >"""
422
+ return _AgxOpenPlxPyApi.InputSignalQueue_create()
420
423
 
421
- @staticmethod
422
- def sendInputSignal(signal):
424
+ def send(self, signal):
423
425
  r"""
424
- sendInputSignal(agxopenplx::InputSignalPtr signal) -> bool
426
+ send(InputSignalQueue self, agxopenplx::InputSignalPtr signal)
425
427
 
426
428
  Parameters
427
429
  ----------
428
430
  signal: agxopenplx::InputSignalPtr
429
431
 
430
432
  """
431
- return _AgxOpenPlxPyApi.Signals_sendInputSignal(signal)
433
+ return _AgxOpenPlxPyApi.InputSignalQueue_send(self, signal)
432
434
 
433
- @staticmethod
434
- def getOutputSignals():
435
- r"""getOutputSignals() -> Physics_Signals_OutputSignal_Vector"""
436
- return _AgxOpenPlxPyApi.Signals_getOutputSignals()
435
+ def getSignals(self):
436
+ r"""getSignals(InputSignalQueue self) -> Physics_Signals_InputSignal_Vector"""
437
+ return _AgxOpenPlxPyApi.InputSignalQueue_getSignals(self)
437
438
 
438
- @staticmethod
439
- def sendOutputSignal(signal):
440
- r"""
441
- sendOutputSignal(agxopenplx::OutputSignalPtr signal) -> bool
439
+ def popSignals(self):
440
+ r"""popSignals(InputSignalQueue self) -> Physics_Signals_InputSignal_Vector"""
441
+ return _AgxOpenPlxPyApi.InputSignalQueue_popSignals(self)
442
442
 
443
- Parameters
444
- ----------
445
- signal: agxopenplx::OutputSignalPtr
443
+ def clear(self):
444
+ r"""clear(InputSignalQueue self)"""
445
+ return _AgxOpenPlxPyApi.InputSignalQueue_clear(self)
446
446
 
447
- """
448
- return _AgxOpenPlxPyApi.Signals_sendOutputSignal(signal)
447
+ def size(self):
448
+ r"""size(InputSignalQueue self) -> size_t"""
449
+ return _AgxOpenPlxPyApi.InputSignalQueue_size(self)
449
450
 
450
- @staticmethod
451
- def clearOutputSignals():
452
- r"""clearOutputSignals()"""
453
- return _AgxOpenPlxPyApi.Signals_clearOutputSignals()
451
+ def empty(self):
452
+ r"""empty(InputSignalQueue self) -> bool"""
453
+ return _AgxOpenPlxPyApi.InputSignalQueue_empty(self)
454
+ __swig_destroy__ = _AgxOpenPlxPyApi.delete_InputSignalQueue
454
455
 
455
- def __init__(self):
456
- r"""__init__(Signals self) -> Signals"""
457
- _AgxOpenPlxPyApi.Signals_swiginit(self, _AgxOpenPlxPyApi.new_Signals())
458
- __swig_destroy__ = _AgxOpenPlxPyApi.delete_Signals
456
+ # Register InputSignalQueue in _AgxOpenPlxPyApi:
457
+ _AgxOpenPlxPyApi.InputSignalQueue_swigregister(InputSignalQueue)
459
458
 
460
- # Register Signals in _AgxOpenPlxPyApi:
461
- _AgxOpenPlxPyApi.Signals_swigregister(Signals)
459
+ def InputSignalQueue_create():
460
+ r"""InputSignalQueue_create() -> std::shared_ptr< agxopenplx::InputSignalQueue >"""
461
+ return _AgxOpenPlxPyApi.InputSignalQueue_create()
462
462
 
463
- def Signals_popInputSignals():
464
- r"""Signals_popInputSignals() -> Physics_Signals_InputSignal_Vector"""
465
- return _AgxOpenPlxPyApi.Signals_popInputSignals()
463
+ class OutputSignalQueue(object):
464
+ r"""Proxy of C++ agxopenplx::OutputSignalQueue class."""
466
465
 
467
- def Signals_sendInputSignal(signal):
468
- r"""
469
- Signals_sendInputSignal(agxopenplx::InputSignalPtr signal) -> bool
466
+ thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
470
467
 
471
- Parameters
472
- ----------
473
- signal: agxopenplx::InputSignalPtr
468
+ def __init__(self, *args, **kwargs):
469
+ raise AttributeError("No constructor defined")
470
+ __repr__ = _swig_repr
474
471
 
475
- """
476
- return _AgxOpenPlxPyApi.Signals_sendInputSignal(signal)
472
+ @staticmethod
473
+ def create():
474
+ r"""create() -> std::shared_ptr< agxopenplx::OutputSignalQueue >"""
475
+ return _AgxOpenPlxPyApi.OutputSignalQueue_create()
477
476
 
478
- def Signals_getOutputSignals():
479
- r"""Signals_getOutputSignals() -> Physics_Signals_OutputSignal_Vector"""
480
- return _AgxOpenPlxPyApi.Signals_getOutputSignals()
477
+ def send(self, signal):
478
+ r"""
479
+ send(OutputSignalQueue self, agxopenplx::OutputSignalPtr signal)
481
480
 
482
- def Signals_sendOutputSignal(signal):
483
- r"""
484
- Signals_sendOutputSignal(agxopenplx::OutputSignalPtr signal) -> bool
481
+ Parameters
482
+ ----------
483
+ signal: agxopenplx::OutputSignalPtr
485
484
 
486
- Parameters
487
- ----------
488
- signal: agxopenplx::OutputSignalPtr
485
+ """
486
+ return _AgxOpenPlxPyApi.OutputSignalQueue_send(self, signal)
489
487
 
490
- """
491
- return _AgxOpenPlxPyApi.Signals_sendOutputSignal(signal)
488
+ def getSignals(self):
489
+ r"""getSignals(OutputSignalQueue self) -> Physics_Signals_OutputSignal_Vector"""
490
+ return _AgxOpenPlxPyApi.OutputSignalQueue_getSignals(self)
492
491
 
493
- def Signals_clearOutputSignals():
494
- r"""Signals_clearOutputSignals()"""
495
- return _AgxOpenPlxPyApi.Signals_clearOutputSignals()
492
+ def popSignals(self):
493
+ r"""popSignals(OutputSignalQueue self) -> Physics_Signals_OutputSignal_Vector"""
494
+ return _AgxOpenPlxPyApi.OutputSignalQueue_popSignals(self)
496
495
 
496
+ def clear(self):
497
+ r"""clear(OutputSignalQueue self)"""
498
+ return _AgxOpenPlxPyApi.OutputSignalQueue_clear(self)
497
499
 
498
- def findAllOutputs(openplx_scene):
499
- r"""
500
- findAllOutputs(openplx::Core::ObjectPtr const & openplx_scene) -> Physics_Signals_Output_Vector
500
+ def size(self):
501
+ r"""size(OutputSignalQueue self) -> size_t"""
502
+ return _AgxOpenPlxPyApi.OutputSignalQueue_size(self)
501
503
 
502
- Parameters
503
- ----------
504
- openplx_scene: openplx::Core::ObjectPtr const &
504
+ def empty(self):
505
+ r"""empty(OutputSignalQueue self) -> bool"""
506
+ return _AgxOpenPlxPyApi.OutputSignalQueue_empty(self)
507
+ __swig_destroy__ = _AgxOpenPlxPyApi.delete_OutputSignalQueue
508
+
509
+ # Register OutputSignalQueue in _AgxOpenPlxPyApi:
510
+ _AgxOpenPlxPyApi.OutputSignalQueue_swigregister(OutputSignalQueue)
511
+
512
+ def OutputSignalQueue_create():
513
+ r"""OutputSignalQueue_create() -> std::shared_ptr< agxopenplx::OutputSignalQueue >"""
514
+ return _AgxOpenPlxPyApi.OutputSignalQueue_create()
505
515
 
506
- """
507
- return _AgxOpenPlxPyApi.findAllOutputs(openplx_scene)
508
516
  class InputSignalListener(agxSDK.StepEventListener):
509
517
  r"""Proxy of C++ agxopenplx::InputSignalListener class."""
510
518
 
511
519
  thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
512
520
  __repr__ = _swig_repr
513
521
 
514
- def __init__(self, assembly):
522
+ def __init__(self, assembly, input_queue):
515
523
  r"""
516
- __init__(InputSignalListener self, Assembly assembly) -> InputSignalListener
524
+ __init__(InputSignalListener self, Assembly assembly, std::shared_ptr< agxopenplx::InputSignalQueue > input_queue) -> InputSignalListener
517
525
 
518
526
  Parameters
519
527
  ----------
520
528
  assembly: agxSDK::Assembly *
529
+ input_queue: std::shared_ptr< agxopenplx::InputSignalQueue >
521
530
 
522
531
  """
523
532
 
@@ -525,7 +534,7 @@ class InputSignalListener(agxSDK.StepEventListener):
525
534
  assembly = assembly.get()
526
535
 
527
536
 
528
- _AgxOpenPlxPyApi.InputSignalListener_swiginit(self, _AgxOpenPlxPyApi.new_InputSignalListener(assembly))
537
+ _AgxOpenPlxPyApi.InputSignalListener_swiginit(self, _AgxOpenPlxPyApi.new_InputSignalListener(assembly, input_queue))
529
538
 
530
539
  def preCollide(self, time):
531
540
  r"""
@@ -558,14 +567,15 @@ class OutputSignalListener(agxSDK.StepEventListener):
558
567
  thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
559
568
  __repr__ = _swig_repr
560
569
 
561
- def __init__(self, assembly, openplx_scene):
570
+ def __init__(self, assembly, openplx_scene, output_queue):
562
571
  r"""
563
- __init__(OutputSignalListener self, Assembly assembly, std::shared_ptr< openplx::Core::Object > const & openplx_scene) -> OutputSignalListener
572
+ __init__(OutputSignalListener self, Assembly assembly, std::shared_ptr< openplx::Core::Object > const & openplx_scene, std::shared_ptr< agxopenplx::OutputSignalQueue > output_queue) -> OutputSignalListener
564
573
 
565
574
  Parameters
566
575
  ----------
567
576
  assembly: agxSDK::Assembly *
568
577
  openplx_scene: std::shared_ptr< openplx::Core::Object > const &
578
+ output_queue: std::shared_ptr< agxopenplx::OutputSignalQueue >
569
579
 
570
580
  """
571
581
 
@@ -573,7 +583,7 @@ class OutputSignalListener(agxSDK.StepEventListener):
573
583
  assembly = assembly.get()
574
584
 
575
585
 
576
- _AgxOpenPlxPyApi.OutputSignalListener_swiginit(self, _AgxOpenPlxPyApi.new_OutputSignalListener(assembly, openplx_scene))
586
+ _AgxOpenPlxPyApi.OutputSignalListener_swiginit(self, _AgxOpenPlxPyApi.new_OutputSignalListener(assembly, openplx_scene, output_queue))
577
587
 
578
588
  def syncOutputSignals(self):
579
589
  r"""syncOutputSignals(OutputSignalListener self)"""
@@ -647,19 +657,20 @@ class ClickInputListener(object):
647
657
  thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
648
658
  __repr__ = _swig_repr
649
659
 
650
- def __init__(self, server, openplx_scene, time_step, autostepping_enabled):
660
+ def __init__(self, server, openplx_scene, input_queue, time_step, autostepping_enabled):
651
661
  r"""
652
- __init__(ClickInputListener self, std::shared_ptr< click::Server > & server, std::shared_ptr< openplx::Core::Object > const & openplx_scene, double time_step, bool autostepping_enabled) -> ClickInputListener
662
+ __init__(ClickInputListener self, std::shared_ptr< click::Server > & server, std::shared_ptr< openplx::Core::Object > const & openplx_scene, std::shared_ptr< agxopenplx::InputSignalQueue > input_queue, double time_step, bool autostepping_enabled) -> ClickInputListener
653
663
 
654
664
  Parameters
655
665
  ----------
656
666
  server: std::shared_ptr< click::Server > &
657
667
  openplx_scene: std::shared_ptr< openplx::Core::Object > const &
668
+ input_queue: std::shared_ptr< agxopenplx::InputSignalQueue >
658
669
  time_step: double
659
670
  autostepping_enabled: bool
660
671
 
661
672
  """
662
- _AgxOpenPlxPyApi.ClickInputListener_swiginit(self, _AgxOpenPlxPyApi.new_ClickInputListener(server, openplx_scene, time_step, autostepping_enabled))
673
+ _AgxOpenPlxPyApi.ClickInputListener_swiginit(self, _AgxOpenPlxPyApi.new_ClickInputListener(server, openplx_scene, input_queue, time_step, autostepping_enabled))
663
674
  __swig_destroy__ = _AgxOpenPlxPyApi.delete_ClickInputListener
664
675
 
665
676
  def preFrame(self, arg2):
@@ -743,19 +754,20 @@ class OsgClickInputListener(ClickInputListener):
743
754
  thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
744
755
  __repr__ = _swig_repr
745
756
 
746
- def __init__(self, server, openplx_scene, time_step, autostepping_enabled):
757
+ def __init__(self, server, openplx_scene, input_queue, time_step, autostepping_enabled):
747
758
  r"""
748
- __init__(OsgClickInputListener self, std::shared_ptr< click::Server > & server, std::shared_ptr< openplx::Core::Object > const & openplx_scene, double time_step, bool autostepping_enabled) -> OsgClickInputListener
759
+ __init__(OsgClickInputListener self, std::shared_ptr< click::Server > & server, std::shared_ptr< openplx::Core::Object > const & openplx_scene, std::shared_ptr< agxopenplx::InputSignalQueue > input_queue, double time_step, bool autostepping_enabled) -> OsgClickInputListener
749
760
 
750
761
  Parameters
751
762
  ----------
752
763
  server: std::shared_ptr< click::Server > &
753
764
  openplx_scene: std::shared_ptr< openplx::Core::Object > const &
765
+ input_queue: std::shared_ptr< agxopenplx::InputSignalQueue >
754
766
  time_step: double
755
767
  autostepping_enabled: bool
756
768
 
757
769
  """
758
- _AgxOpenPlxPyApi.OsgClickInputListener_swiginit(self, _AgxOpenPlxPyApi.new_OsgClickInputListener(server, openplx_scene, time_step, autostepping_enabled))
770
+ _AgxOpenPlxPyApi.OsgClickInputListener_swiginit(self, _AgxOpenPlxPyApi.new_OsgClickInputListener(server, openplx_scene, input_queue, time_step, autostepping_enabled))
759
771
 
760
772
  def preFrame(self, app):
761
773
  r"""
@@ -794,16 +806,17 @@ class ClickOutputListener(agxSDK.StepEventListener):
794
806
  thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
795
807
  __repr__ = _swig_repr
796
808
 
797
- def __init__(self, server):
809
+ def __init__(self, server, output_queue):
798
810
  r"""
799
- __init__(ClickOutputListener self, std::shared_ptr< click::Server > & server) -> ClickOutputListener
811
+ __init__(ClickOutputListener self, std::shared_ptr< click::Server > & server, std::shared_ptr< agxopenplx::OutputSignalQueue > output_queue) -> ClickOutputListener
800
812
 
801
813
  Parameters
802
814
  ----------
803
815
  server: std::shared_ptr< click::Server > &
816
+ output_queue: std::shared_ptr< agxopenplx::OutputSignalQueue >
804
817
 
805
818
  """
806
- _AgxOpenPlxPyApi.ClickOutputListener_swiginit(self, _AgxOpenPlxPyApi.new_ClickOutputListener(server))
819
+ _AgxOpenPlxPyApi.ClickOutputListener_swiginit(self, _AgxOpenPlxPyApi.new_ClickOutputListener(server, output_queue))
807
820
 
808
821
  def post(self, prev_step):
809
822
  r"""
@@ -891,9 +904,9 @@ class OsgClickAdapter(object):
891
904
  r"""willSendResetMessage(OsgClickAdapter self) -> bool"""
892
905
  return _AgxOpenPlxPyApi.OsgClickAdapter_willSendResetMessage(self)
893
906
 
894
- def add_listeners(self, app, simulation, click_server_addr, openplx_scene, output_signal_listener):
907
+ def add_listeners(self, app, simulation, click_server_addr, openplx_scene, input_queue, output_queue, output_signal_listener):
895
908
  r"""
896
- add_listeners(OsgClickAdapter self, agxOSG::ExampleApplication * app, Simulation simulation, std::string const & click_server_addr, std::shared_ptr< openplx::Core::Object > const & openplx_scene, OutputSignalListener output_signal_listener)
909
+ add_listeners(OsgClickAdapter self, agxOSG::ExampleApplication * app, Simulation simulation, std::string const & click_server_addr, std::shared_ptr< openplx::Core::Object > const & openplx_scene, std::shared_ptr< agxopenplx::InputSignalQueue > input_queue, std::shared_ptr< agxopenplx::OutputSignalQueue > output_queue, OutputSignalListener output_signal_listener)
897
910
 
898
911
  Parameters
899
912
  ----------
@@ -901,23 +914,26 @@ class OsgClickAdapter(object):
901
914
  simulation: agxSDK::Simulation *
902
915
  click_server_addr: std::string const &
903
916
  openplx_scene: std::shared_ptr< openplx::Core::Object > const &
917
+ input_queue: std::shared_ptr< agxopenplx::InputSignalQueue >
918
+ output_queue: std::shared_ptr< agxopenplx::OutputSignalQueue >
904
919
  output_signal_listener: agxopenplx::OutputSignalListener *
905
920
 
906
921
  """
907
- return _AgxOpenPlxPyApi.OsgClickAdapter_add_listeners(self, app, simulation, click_server_addr, openplx_scene, output_signal_listener)
922
+ return _AgxOpenPlxPyApi.OsgClickAdapter_add_listeners(self, app, simulation, click_server_addr, openplx_scene, input_queue, output_queue, output_signal_listener)
908
923
 
909
- def createClickInputListener(self, openplx_scene, time_step, auto_stepping):
924
+ def createClickInputListener(self, openplx_scene, input_queue, time_step, auto_stepping):
910
925
  r"""
911
- createClickInputListener(OsgClickAdapter self, std::shared_ptr< openplx::Core::Object > const & openplx_scene, double time_step, bool auto_stepping) -> std::shared_ptr< agxopenplx::ClickInputListener >
926
+ createClickInputListener(OsgClickAdapter self, std::shared_ptr< openplx::Core::Object > const & openplx_scene, std::shared_ptr< agxopenplx::InputSignalQueue > input_queue, double time_step, bool auto_stepping) -> std::shared_ptr< agxopenplx::ClickInputListener >
912
927
 
913
928
  Parameters
914
929
  ----------
915
930
  openplx_scene: std::shared_ptr< openplx::Core::Object > const &
931
+ input_queue: std::shared_ptr< agxopenplx::InputSignalQueue >
916
932
  time_step: double
917
933
  auto_stepping: bool
918
934
 
919
935
  """
920
- return _AgxOpenPlxPyApi.OsgClickAdapter_createClickInputListener(self, openplx_scene, time_step, auto_stepping)
936
+ return _AgxOpenPlxPyApi.OsgClickAdapter_createClickInputListener(self, openplx_scene, input_queue, time_step, auto_stepping)
921
937
 
922
938
  def __init__(self):
923
939
  r"""__init__(OsgClickAdapter self) -> OsgClickAdapter"""
openplx/migrate.py CHANGED
@@ -11,12 +11,12 @@ import urllib.request
11
11
  import zipfile
12
12
  from io import BytesIO
13
13
  from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter, SUPPRESS
14
+ import agx
14
15
  from openplx import __version__, get_error_strings
15
16
  from openplx.Core import OpenPlxContext, parseFromFile, analyze, StringVector, DocumentVector
16
- from openplx.migrations import collect_migrations, ReplaceOp
17
+ from openplx.migrations import collect_migrations, ReplaceOp, split_version
17
18
  from openplx.versionaction import VersionAction
18
19
  from openplx import register_plugins
19
- import agx
20
20
 
21
21
  def download_package_version(package_name, version):
22
22
  """Download a specific version of a package from PyPI."""
@@ -26,6 +26,7 @@ def download_package_version(package_name, version):
26
26
  data = json.loads(content)
27
27
  return data['urls'][0]['url']
28
28
 
29
+
29
30
  def unzip_package(url, extract_to):
30
31
  """Download and unzip a package."""
31
32
  with urllib.request.urlopen(url, timeout=32) as response:
@@ -62,20 +63,16 @@ def has_errors(openplx_context):
62
63
  return True
63
64
  return False
64
65
 
65
- def refactor_openplx_file(openplxfile, bundle_path_vec, from_version, to_version) -> bool: # pylint: disable=too-many-locals
66
+ def refactor_openplx_file(migration, openplxfile, bundle_path_vec, from_version, to_version) -> bool: # pylint: disable=too-many-locals
66
67
  print(f"Migrating {openplxfile} from {from_version} to {to_version}")
67
- migrations = collect_migrations(from_version, to_version)
68
- print(f"Found {len(migrations)} migrations ", [m.__name__ for m in migrations])
69
-
70
68
  file_rename_migrations = []
71
- for migration in [m for m in migrations if m.__name__ == "rename_from_brick_to_openplx"]:
69
+ if migration.__name__ == "rename_from_brick_to_openplx":
72
70
  file_rename_migrations.append(migration(openplxfile))
73
- if (openplxfile.endswith("config.openplx") or openplxfile.endswith("config.brick")):
74
- for m in file_rename_migrations:
75
- m.apply_to(None, None)
76
- return True
71
+ if openplxfile.endswith("config.openplx") or openplxfile.endswith("config.brick"):
72
+ for m in file_rename_migrations:
73
+ m.apply_to(None, None)
74
+ return True
77
75
 
78
- migrations = [m for m in migrations if m.__name__ != "rename_from_brick_to_openplx"]
79
76
  openplx_context = OpenPlxContext(bundle_path_vec)
80
77
  register_plugins(openplx_context, None)
81
78
  documents = parse_and_analyze(openplxfile, openplx_context)
@@ -83,13 +80,11 @@ def refactor_openplx_file(openplxfile, bundle_path_vec, from_version, to_version
83
80
  if has_errors(openplx_context):
84
81
  return False
85
82
 
86
- order_group = [(key, list(group)) for key, group in itertools.groupby(migrations, lambda m: m.openplx_order)]
87
- order_group.sort(key=lambda pair: pair[0])
88
-
89
- for _, migration_group in order_group:
90
- ops = []
91
- for migration in migration_group:
92
- ops.extend(migration(documents))
83
+ if migration.__name__ == "rename_from_brick_to_openplx":
84
+ for m in file_rename_migrations:
85
+ m.apply_to(None, None)
86
+ else:
87
+ ops = migration(documents)
93
88
 
94
89
  for key, op_group in itertools.groupby(ops, lambda op: op.path):
95
90
  if Path(openplxfile).samefile(key):
@@ -100,20 +95,43 @@ def refactor_openplx_file(openplxfile, bundle_path_vec, from_version, to_version
100
95
  with open(key, 'w', encoding="utf8") as file:
101
96
  file.writelines(lines)
102
97
 
103
- for m in file_rename_migrations:
104
- m.apply_to(None, None)
105
-
106
98
  return True
107
99
 
108
- def run_openplx_migrate(args):
109
-
110
- # NOTE: Depending on version, we need to change the package_name
111
- package_name = 'brickbundles'
100
+ def config_file_path(openplxfile, version):
101
+ config_file_name = 'config.openplx'
102
+ if split_version(version) < (0, 15, 0):
103
+ config_file_name = 'config.brick'
104
+ if os.path.isdir(openplxfile):
105
+ return os.path.join(openplxfile, config_file_name)
106
+ return os.path.join(os.path.dirname(openplxfile), config_file_name)
107
+
108
+ def migrate_config_file_versions(config_path, from_version, to_version):
109
+ bundles = ["Math", "Physics", "Physics1D", "Physics3D",
110
+ "Robotics", "Urdf", "Terrain", "Vehicles",
111
+ "Simulation", "Visuals", "DriveTrain"]
112
+ add_versions = (split_version(from_version) < (0, 11, 0)
113
+ and split_version(to_version) >= (0, 11, 0))
114
+ if os.path.exists(config_path):
115
+ with open(config_path, 'r', encoding="utf8") as file:
116
+ lines = file.readlines()
117
+ lines = list(map(lambda line: line.replace(f"=={from_version}", f"=={to_version}"), lines))
118
+ if add_versions:
119
+ for i in range(len(lines)): # pylint: disable=consider-using-enumerate
120
+ for bundle in bundles:
121
+ lines[i] = lines[i].replace(f"\"{bundle}\"", f"\"{bundle}=={to_version}\"")
122
+ with open(config_path, 'w', encoding="utf8") as file:
123
+ file.writelines(lines)
124
+
125
+ def run_openplx_migrate_from_version(migration, from_version, to_version, openplxfile): # pylint: disable=too-many-locals
126
+ package_name = 'openplx-bundles'
127
+
128
+ if split_version(from_version) < (0, 15, 0):
129
+ package_name = 'brickbundles'
112
130
 
113
131
  # Download the package
114
- url = download_package_version(package_name, args.from_version)
132
+ url = download_package_version(package_name, from_version)
115
133
  if url is None:
116
- print(f"Could not find the source distribution for {package_name}=={args.from_version}.")
134
+ print(f"Could not find the source distribution for {package_name}=={from_version}.")
117
135
  return
118
136
 
119
137
  # Create a temporary directory
@@ -121,8 +139,8 @@ def run_openplx_migrate(args):
121
139
  tmp_path = str(Path(os.path.realpath(tmpdirname)).absolute())
122
140
  print(f"Extracting to temporary directory: {tmp_path}")
123
141
  unzip_package(url, tmp_path)
124
- print(f"Package {package_name}=={args.from_version} extracted to {tmp_path}")
125
- bundle_path = str((Path(tmp_path) / package_name).absolute())
142
+ print(f"Package {package_name}=={from_version} extracted to {tmp_path}")
143
+ bundle_path = str((Path(tmp_path) / package_name.replace("-", "")).absolute())
126
144
 
127
145
  print(f'Using bundle path {bundle_path}')
128
146
  print(os.listdir(bundle_path))
@@ -131,22 +149,38 @@ def run_openplx_migrate(args):
131
149
  bundle_path_vec.push_back(bundle_path)
132
150
  success = True
133
151
  # Apply the refactoring
134
- if os.path.isdir(args.openplxfile):
135
- for root, _, files in os.walk(args.openplxfile):
152
+ if os.path.isdir(openplxfile):
153
+ for root, _, files in os.walk(openplxfile):
136
154
  for file in files:
137
155
  if file.endswith(".openplx") or file.endswith(".brick"):
138
156
  openplxfile = os.path.join(root, file)
139
- if not refactor_openplx_file(openplxfile, bundle_path_vec, args.from_version, args.to_version):
157
+ if not refactor_openplx_file(migration, openplxfile,
158
+ bundle_path_vec, from_version, to_version):
140
159
  success = False
141
160
  else:
142
- if not refactor_openplx_file(args.openplxfile, bundle_path_vec, args.from_version, args.to_version):
161
+ if not refactor_openplx_file(migration, openplxfile,
162
+ bundle_path_vec, from_version, to_version):
143
163
  success = False
144
164
  if success:
145
- print(f"Refactor from {args.from_version} to {args.to_version} complete!")
165
+ print(f"Refactor from {from_version} to {to_version} complete!")
146
166
  else:
147
- print(f"Refactor from {args.from_version} to {args.to_version} failed due to errors!")
167
+ print(f"Refactor from {from_version} to {to_version} failed due to errors!")
148
168
  print("Note, some files might have been partially migrated.")
149
169
 
170
+
171
+ def run_openplx_migrate(args):
172
+ migrations = collect_migrations(args.from_version, args.to_version)
173
+ current_version = args.from_version
174
+ for migration in migrations:
175
+ migrate_config_file_versions(config_file_path(args.openplxfile, current_version),
176
+ current_version, migration.openplx_from_version)
177
+ run_openplx_migrate_from_version(migration, migration.openplx_from_version,
178
+ migration.openplx_to_version, args.openplxfile)
179
+ migrate_config_file_versions(
180
+ config_file_path(args.openplxfile, migration.openplx_from_version),
181
+ migration.openplx_from_version, migration.openplx_to_version)
182
+ current_version = migration.openplx_to_version
183
+
150
184
  def run():
151
185
  arguments, _ = parse_args()
152
186
  init = agx.AutoInit() # pylint: disable=W0612 # Unused variable 'init'