OSGeo / grass

GRASS GIS - free and open-source geospatial processing engine
https://grass.osgeo.org
Other
852 stars 309 forks source link

[Bug] winGRASS: g.extension fails if precompiled zip-files contains some cruft files #1477

Open hellik opened 3 years ago

hellik commented 3 years ago

Describe the bug first reported by @veroandreo in [GRASS-user] error in g.extension while installing i.fusion.hpf in windows

some more findings are here

downloading the zipped addon, which is used by g.extension in windows, from here:
https://wingrass.fsv.cvut.cz/grass78/x86_64/addons/latest/

in the subfolder i.fusion.hpf\etc\i.fusion.hpf, there is a subfolder __pycache__

i.fusion.hpf\etc\i.fusion.hpf\__pycache__>ls

constants.cpython-37.pyc
high_pass_filter.cpython-37.pyc

the compiled python bytecode shouldn't be there in the zip file.

g,extension fails if there are some cruft files inside the precompiled zip-files used by winGRASS.

To Reproduce Steps to reproduce the behavior:

  1. start winGRASS
  2. g.extension extension=i.fusion.hpf
  3. See error:

in winGRASS 7.8.5

g.extension extension=i.fusion.hpf                                              
Downloading precompiled GRASS Addons <i.fusion.hpf>...
Fetching <i.fusion.hpf> from <http://wingrass.fsv.cvut.cz/grass78/x86_64/addons/grass-7.8.5/i.fusion.hpf.zip> (be patient)...
Traceback (most recent call last):
  File
"C:\OSGEO4~1\apps\grass\grass78/scripts/g.extension.py",
line 2350, in <module>
    sys.exit(main())
  File
"C:\OSGEO4~1\apps\grass\grass78/scripts/g.extension.py",
line 2330, in main
    install_extension(source=source, url=url, xmlurl=xmlurl,
branch=branch)
  File
"C:\OSGEO4~1\apps\grass\grass78/scripts/g.extension.py",
line 871, in install_extension
    ret1, new_modules_ext, new_files_ext =
install_extension_win(extension)
  File
"C:\OSGEO4~1\apps\grass\grass78/scripts/g.extension.py",
line 1259, in install_extension_win
    for line in file:
  File "C:\OSGEO4~1\apps\Python37\lib\fileinput.py", line
252, in __next__
    line = self._readline()
  File "C:\OSGEO4~1\apps\Python37\lib\fileinput.py", line
366, in _readline
    return self._readline()
  File "C:\OSGEO4~1\apps\Python37\lib\encodings\cp1252.py",
line 23, in decode
    return
codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d
in position 401: character maps to <undefined>

in winGRASS 7.9.dev

g.extension extension=i.fusion.hpf                                              
Downloading precompiled GRASS Addons <i.fusion.hpf>...
Fetching <i.fusion.hpf> from <http://wingrass.fsv.cvut.cz/grass79/x86_64/addons/grass-7.9.dev/i.fusion.hpf.zip> (be patient)...
Traceback (most recent call last):
  File
"C:\OSGEO4~1\apps\grass\grass79/scripts/g.extension.py",
line 2484, in <module>
    sys.exit(main())
  File
"C:\OSGEO4~1\apps\grass\grass79/scripts/g.extension.py",
line 2463, in main
    install_extension(source=source, url=url, xmlurl=xmlurl,
branch=branch)
  File
"C:\OSGEO4~1\apps\grass\grass79/scripts/g.extension.py",
line 892, in install_extension
    ret1, new_modules_ext, new_files_ext =
install_extension_win(extension)
  File
"C:\OSGEO4~1\apps\grass\grass79/scripts/g.extension.py",
line 1308, in install_extension_win
    for line in file:
  File "C:\OSGEO4~1\apps\Python37\lib\fileinput.py", line
252, in __next__
    line = self._readline()
  File "C:\OSGEO4~1\apps\Python37\lib\fileinput.py", line
366, in _readline
    return self._readline()
  File "C:\OSGEO4~1\apps\Python37\lib\encodings\cp1252.py",
line 23, in decode
    return
codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d
in position 401: character maps to <undefined>

Expected behavior

or

System description

OS: windows

GRASS Version: 7.8.5                                                            
Code revision: 2b6ab2893  
GRASS Version: 7.9.dev                                                          
Code revision: a344250d3 
neteler commented 3 years ago

Skipping the unwanted files (*.pyc and __pycache__) might be the best. It would probably go here:

https://github.com/OSGeo/grass/blob/f596255917f974cafec921677037b3e228ce69f0/scripts/g.extension/g.extension.py#L1464

neteler commented 3 years ago

Keeping open for backport.