[chirp_devel] python2/3 MemoryMap?
![](https://secure.gravatar.com/avatar/c3524c96b01edbb2b52733cc5b5ff328.jpg?s=120&d=mm&r=g)
I'm trying to write a driver that works with both Python 2 and Python 3. It works and passes all tests, but it cannot create a memory savable memory map when it downloads from the radio. I can choose MemoryMapBytes, which works in Py3, or MemoryMap, which is implemented in both but which results in a mmap that cannot be written to a file. I'm now officially lost, which is my usual state. Any suggestions?
![](https://secure.gravatar.com/avatar/50985ef0199366434400d43517dae9a8.jpg?s=120&d=mm&r=g)
I'm trying to write a driver that works with both Python 2 and Python 3. It works and passes all tests, but it cannot create a memory savable memory map when it downloads from the radio. I can choose MemoryMapBytes, which works in Py3, or MemoryMap, which is implemented in both but which results in a mmap that cannot be written to a file. I'm now officially lost, which is my usual state. Any suggestions?
I'm not sure what you mean, so showing code would be a lot more helpful. I've converted a bunch of radios in the py3 branch that work on py2 and py3 at the same time, so you can look for examples there. Most have a first commit that just makes them work with MemoryMap (i.e. compat mode) first, followed by one that makes them byte-clean using MemoryMapBytes. Note that you won't be able to make a driver that works on both on the main branch of course.
--Dan
![](https://secure.gravatar.com/avatar/c3524c96b01edbb2b52733cc5b5ff328.jpg?s=120&d=mm&r=g)
OK, I did in fact make my driver work on both py3 and the (py2) main branch. I built my image into a bytearray, then converted to bytes, use MemoryMap: bytearraymmap = bytearray(radio._imagesize) readimageinto bytearray(bytearraymmap) self._mmap= memmap.MemoryMap(bytes(bytearraymmap))
This code works in both places. The py3 version will eventually need to be cleaned up to use the MemoryMapBytes, simply to avoid the array copy, but that's minor. We could add a stub version of MemoryMapBytes to py2 to simplify the transition.
On Sun, Feb 17, 2019 at 3:04 PM Dan Smith via chirp_devel < chirp_devel@intrepid.danplanet.com> wrote:
I'm trying to write a driver that works with both Python 2 and Python 3.
It works and passes all tests, but it cannot create a memory savable memory map when it downloads from the radio.
I can choose MemoryMapBytes, which works in Py3, or MemoryMap, which is
implemented in both but which results in a mmap that cannot be written to a file. I'm now officially lost, which is my usual state. Any suggestions?
I'm not sure what you mean, so showing code would be a lot more helpful. I've converted a bunch of radios in the py3 branch that work on py2 and py3 at the same time, so you can look for examples there. Most have a first commit that just makes them work with MemoryMap (i.e. compat mode) first, followed by one that makes them byte-clean using MemoryMapBytes. Note that you won't be able to make a driver that works on both on the main branch of course.
--Dan
chirp_devel mailing list chirp_devel@intrepid.danplanet.com http://intrepid.danplanet.com/mailman/listinfo/chirp_devel Developer docs: http://chirp.danplanet.com/projects/chirp/wiki/Developers
![](https://secure.gravatar.com/avatar/50985ef0199366434400d43517dae9a8.jpg?s=120&d=mm&r=g)
OK, I did in fact make my driver work on both py3 and the (py2) main branch. I built my image into a bytearray, then converted to bytes, use MemoryMap: bytearraymmap = bytearray(radio._imagesize) readimageinto bytearray(bytearraymmap) self._mmap= memmap.MemoryMap(bytes(bytearraymmap))
You might be able to run stuff against your driver in the main branch, but you can't run the whole app, and the run_tests.py file isn't even syntax-compatible under python3:
$ python3 tests/run_tests.py File "tests/run_tests.py", line 134 except Exception, e: ^ SyntaxError: invalid syntax
This code works in both places. The py3 version will eventually need to be cleaned up to use the MemoryMapBytes, simply to avoid the array copy, but that's minor. We could add a stub version of MemoryMapBytes to py2 to simplify the transition.
If you meant the same driver file can work on the default and py3 branch, then sure, that's just not what I meant.
--Dan
![](https://secure.gravatar.com/avatar/c3524c96b01edbb2b52733cc5b5ff328.jpg?s=120&d=mm&r=g)
now I'm confused (my usual state...) I am in fact running the identical driver on both branches and it is running as part of chirpw and chirpc. I fixed the syntax errors in run_tests on the py3 branch and stripped almost all drivers out of the drivers directory. That's what I've been running to pass the unit test on the py3 branch since you told me how: dgc@vivomini /export/srcs/CHIRP3/chirp.hg/tests $ ./run_tests -d Yaesu_FT-4XR Failed to import /export/srcs/CHIRP3/chirp.hg/chirp/drivers/rfinder: invalid syntax (rfinder.py, line 290) Yaesu FT-4XR Clone PASSED: All tests Yaesu FT-4XR Edges PASSED: All tests Yaesu FT-4XR BruteForce PASSED: All tests Yaesu FT-4XR CopyAll PASSED: All tests Yaesu FT-4XR Banks PASSED: All tests Yaesu FT-4XR Detect PASSED: All tests Yaesu FT-4XR Settings PASSED: All tests ---------------------------------------------------------------------- Results: TOTAL : 7 PASSED : 7 SKIPPED: 0 FAILED : 0 CRASHED: 0
On Sun, Feb 17, 2019 at 3:24 PM Dan Smith via chirp_devel < chirp_devel@intrepid.danplanet.com> wrote:
OK, I did in fact make my driver work on both py3 and the (py2) main
branch. I built my image into a bytearray, then converted to bytes,
use MemoryMap: bytearraymmap = bytearray(radio._imagesize) readimageinto bytearray(bytearraymmap) self._mmap= memmap.MemoryMap(bytes(bytearraymmap))
You might be able to run stuff against your driver in the main branch, but you can't run the whole app, and the run_tests.py file isn't even syntax-compatible under python3:
$ python3 tests/run_tests.py File "tests/run_tests.py", line 134 except Exception, e: ^ SyntaxError: invalid syntax
This code works in both places. The py3 version will eventually need to
be cleaned up to use the MemoryMapBytes, simply to avoid the
array copy, but that's minor. We could add a stub version of
MemoryMapBytes to py2 to simplify the transition.
If you meant the same driver file can work on the default and py3 branch, then sure, that's just not what I meant.
--Dan _______________________________________________ chirp_devel mailing list chirp_devel@intrepid.danplanet.com http://intrepid.danplanet.com/mailman/listinfo/chirp_devel Developer docs: http://chirp.danplanet.com/projects/chirp/wiki/Developers
![](https://secure.gravatar.com/avatar/50985ef0199366434400d43517dae9a8.jpg?s=120&d=mm&r=g)
now I'm confused (my usual state...) I am in fact running the identical driver on both branches and it is running as part of chirpw and chirpc. I fixed the syntax errors in run_tests on the py3 branch and stripped almost all drivers out of the drivers directory.
Yeah, something must be confused. There shouldn't be syntax errors in run_tests.py on the py3 branch:
$ hg id 3f7c8255f0d1 (py3) tip $ python3 -c 'from tests import run_tests' >/dev/null $ hg checkout default 92 files updated, 0 files merged, 10 files removed, 0 files unresolved $ python3 -c 'from tests import run_tests' >/dev/null Traceback (most recent call last): File "<string>", line 1, in <module> File "/danplanet/users/dan/dev/py3chirp/tests/__init__.py", line 8, in <module> from chirp import directory File "/danplanet/users/dan/dev/py3chirp/chirp/directory.py", line 21, in <module> from chirp.drivers import icf, rfinder File "/danplanet/users/dan/dev/py3chirp/chirp/drivers/icf.py", line 112 except errors.InvalidDataError, e: ^ SyntaxError: invalid syntax
--Dan
![](https://secure.gravatar.com/avatar/c3524c96b01edbb2b52733cc5b5ff328.jpg?s=120&d=mm&r=g)
I got ttat error, but the fix was trivial and my test does not use that module.
On Sun, Feb 17, 2019 at 4:06 PM Dan Smith via chirp_devel < chirp_devel@intrepid.danplanet.com> wrote:
now I'm confused (my usual state...) I am in fact running the identical
driver on both branches and it is running as part of chirpw and chirpc. I fixed the syntax errors in run_tests on the py3 branch and stripped almost all drivers out of the drivers directory.
Yeah, something must be confused. There shouldn't be syntax errors in run_tests.py on the py3 branch:
$ hg id 3f7c8255f0d1 (py3) tip $ python3 -c 'from tests import run_tests' >/dev/null $ hg checkout default 92 files updated, 0 files merged, 10 files removed, 0 files unresolved $ python3 -c 'from tests import run_tests' >/dev/null Traceback (most recent call last): File "<string>", line 1, in <module> File "/danplanet/users/dan/dev/py3chirp/tests/__init__.py", line 8, in
<module> > from chirp import directory > File "/danplanet/users/dan/dev/py3chirp/chirp/directory.py", line 21, in <module> > from chirp.drivers import icf, rfinder > File "/danplanet/users/dan/dev/py3chirp/chirp/drivers/icf.py", line 112 > except errors.InvalidDataError, e: > ^ > SyntaxError: invalid syntax
--Dan _______________________________________________ chirp_devel mailing list chirp_devel@intrepid.danplanet.com http://intrepid.danplanet.com/mailman/listinfo/chirp_devel Developer docs: http://chirp.danplanet.com/projects/chirp/wiki/Developers
participants (2)
-
Dan Clemmensen
-
Dan Smith