Skip to content

pythonlib: fix pygrass Module tests by making it picklable#1407

Merged
petrasovaa merged 3 commits into
OSGeo:masterfrom
petrasovaa:module-fix-pickling
Mar 15, 2021
Merged

pythonlib: fix pygrass Module tests by making it picklable#1407
petrasovaa merged 3 commits into
OSGeo:masterfrom
petrasovaa:module-fix-pickling

Conversation

@petrasovaa

Copy link
Copy Markdown
Contributor

To make it picklable, set popen attribute to None and add __reduce__ to TypeDict.
Slightly changes API by making popen a private variable.

Slightly changes API by making popen a private variable
@petrasovaa

Copy link
Copy Markdown
Contributor Author

This should fix https://trac.osgeo.org/grass/ticket/3799

@wenzeslaus wenzeslaus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think some related fixes are needed in t.rast.accumulate code which now fails with AttributeError: 'Module' object has no attribute 'popen', for example in this context:

Running test.t.rast.accdetect.reverse (./temporal/t.rast.accdetect)...
========================================================================
+ g.region s=0 n=80 w=0 e=120 b=0 t=50 res=10 -p
+ export GRASS_OVERWRITE=1
+ r.mapcalc expr=temp_6 = 5
+ r.mapcalc expr=temp_5 = 10
+ r.mapcalc expr=temp_4 = 15
+ r.mapcalc expr=temp_3 = 20
+ r.mapcalc expr=temp_2 = 25
+ r.mapcalc expr=temp_1 = 30
+ t.create type=strds temporaltype=absolute output=temp_abs1 title=A test descr=A test
Default TGIS driver / database set to:
driver: sqlite
database: $GISDBASE/$LOCATION_NAME/$MAPSET/tgis/sqlite.db
WARNING: Temporal database connection defined as:
/home/runner/nc_spm_full_v2alpha2/__temporal_t_rast_accdetect_test.t.rast.accdetect.reverse/tgis/sqlite.db
But database file does not exist.
Creating temporal database: /home/runner/nc_spm_full_v2alpha2/__temporal_t_rast_accdetect_test.t.rast.accdetect.reverse/tgis/sqlite.db
+ t.register -i type=raster input=temp_abs1 maps=temp_1,temp_2,temp_3,temp_4,temp_5,temp_6 start=2001-01-01 increment=2 months
Gathering map information...
0..ERROR: Unable to read band reference file for raster map <temp_1@__temporal_t_rast_accdetect_test.t.rast.accdetect.reverse>
ERROR: Unable to read band reference file for raster map <temp_2@__temporal_t_rast_accdetect_test.t.rast.accdetect.reverse>
ERROR: Unable to read band reference file for raster map <temp_3@__temporal_t_rast_accdetect_test.t.rast.accdetect.reverse>
ERROR: Unable to read band reference file for raster map <temp_4@__temporal_t_rast_accdetect_test.t.rast.accdetect.reverse>
ERROR: Unable to read band reference file for raster map <temp_5@__temporal_t_rast_accdetect_test.t.rast.accdetect.reverse>
ERROR: Unable to read band reference file for raster map <temp_6@__temporal_t_rast_accdetect_test.t.rast.accdetect.reverse>
100
Registering maps in the temporal database...
Registering maps in the space time dataset...
0..Updating space time dataset...
100
+ t.rast.accumulate -r input=temp_abs1 output=temp_accumulation base=temp_acc limits=10,25 start=2001-01-01 gran=2 months cycle=12 months suffix=num%03
Processing cycle 2001-01-01 00:00:00 - 2002-01-01 00:00:00
0..12..25..37..50..62..75..87..100
Traceback (most recent call last):
  File "scripts/t.rast.accumulate", line 569, in <module>
    main()
  File "scripts/t.rast.accumulate", line 499, in main
    if accmod.popen.returncode != 0:
AttributeError: 'Module' object has no attribute 'popen'
========================================================================
test.t.rast.accdetect.reverse from ./temporal/t.rast.accdetect failed
Running test.t.rast.accdetect (./temporal/t.rast.accdetect)...
========================================================================
+ g.region s=0 n=80 w=0 e=120 b=0 t=50 res=10 -p
+ export GRASS_OVERWRITE=1
+ r.mapcalc expr=temp_1 = 5
+ r.mapcalc expr=temp_2 = 10
+ r.mapcalc expr=temp_3 = 15
+ r.mapcalc expr=temp_4 = 20
+ r.mapcalc expr=temp_5 = 25
+ r.mapcalc expr=temp_6 = 30
+ t.create type=strds temporaltype=absolute output=temp_abs1 title=A test descr=A test
Default TGIS driver / database set to:
driver: sqlite
database: $GISDBASE/$LOCATION_NAME/$MAPSET/tgis/sqlite.db
WARNING: Temporal database connection defined as:
/home/runner/nc_spm_full_v2alpha2/__temporal_t_rast_accdetect_test.t.rast.accdetect/tgis/sqlite.db
But database file does not exist.
Creating temporal database: /home/runner/nc_spm_full_v2alpha2/__temporal_t_rast_accdetect_test.t.rast.accdetect/tgis/sqlite.db
+ t.register -i type=raster input=temp_abs1 maps=temp_1,temp_2,temp_3,temp_4,temp_5,temp_6 start=2001-01-01 increment=2 months
Gathering map information...
0..ERROR: Unable to read band reference file for raster map <temp_1@__temporal_t_rast_accdetect_test.t.rast.accdetect>
ERROR: Unable to read band reference file for raster map <temp_2@__temporal_t_rast_accdetect_test.t.rast.accdetect>
ERROR: Unable to read band reference file for raster map <temp_3@__temporal_t_rast_accdetect_test.t.rast.accdetect>
ERROR: Unable to read band reference file for raster map <temp_4@__temporal_t_rast_accdetect_test.t.rast.accdetect>
ERROR: Unable to read band reference file for raster map <temp_5@__temporal_t_rast_accdetect_test.t.rast.accdetect>
ERROR: Unable to read band reference file for raster map <temp_6@__temporal_t_rast_accdetect_test.t.rast.accdetect>
100
Registering maps in the temporal database...
Registering maps in the space time dataset...
0..Updating space time dataset...
100
+ t.rast.accumulate input=temp_abs1 output=temp_accumulation base=temp_acc limits=10,25 start=2001-01-01 gran=2 months cycle=12 months suffix=num%03
Processing cycle 2001-01-01 00:00:00 - 2002-01-01 00:00:00
0..12..25..37..50..62..75..87..100
Traceback (most recent call last):
  File "scripts/t.rast.accumulate", line 569, in <module>
    main()
  File "scripts/t.rast.accumulate", line 499, in main
    if accmod.popen.returncode != 0:
AttributeError: 'Module' object has no attribute 'popen'
========================================================================

@petrasovaa petrasovaa requested a review from wenzeslaus March 15, 2021 03:22
@petrasovaa petrasovaa merged commit 34d2d9b into OSGeo:master Mar 15, 2021
@petrasovaa petrasovaa deleted the module-fix-pickling branch March 15, 2021 03:25
lindakarlovska pushed a commit to lindakarlovska/grass that referenced this pull request Mar 15, 2021
Slightly changes API by making popen a private variable
marisn pushed a commit to marisn/grass that referenced this pull request Mar 22, 2021
Slightly changes API by making popen a private variable
petrasovaa added a commit to petrasovaa/grass that referenced this pull request May 31, 2021
petrasovaa added a commit that referenced this pull request May 31, 2021
@neteler neteler added this to the 8.0.0 milestone Dec 9, 2021
ninsbl pushed a commit to ninsbl/grass that referenced this pull request Oct 26, 2022
Slightly changes API by making popen a private variable
ninsbl pushed a commit to ninsbl/grass that referenced this pull request Feb 17, 2023
Slightly changes API by making popen a private variable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants