Default paths for "Create Test ..." PA

Issue #579 resolved
Benjamin Jakimow created an issue

Default paths for “Create Test…” PAs seem to be constructed relative to the current working directory. These PAs therefore fail if the EnMAP-Box has been started from an directory without writing access (e.g. C:\Windows\System32):

Processing algorithm
Algorithm 'Create Test Classifier (RandomForest)' starting
Input parameters:
{ 'outClassifier' : './outClassifier.pkl' }

Traceback (most recent call last):
File "D:\Repositories\enmap-box\enmapboxgeoalgorithms\provider.py", line 152, in processAlgorithm
result = self.processAlgorithm_()
File "D:\Repositories\enmap-box\enmapboxgeoalgorithms\algorithms.py", line 594, in processAlgorithm_
enmapboxtestdata.createClassifier().pickle(filename=filename)
File "D:\Repositories\enmap-box\hubflow\core.py", line 522, in pickle
with open(filename, 'wb') as f:
PermissionError: [Errno 13] Permission denied: './outClassifier.pkl'

Traceback (most recent call last):
File "D:\Repositories\enmap-box\enmapboxgeoalgorithms\provider.py", line 152, in processAlgorithm
result = self.processAlgorithm_()
File "D:\Repositories\enmap-box\enmapboxgeoalgorithms\algorithms.py", line 594, in processAlgorithm_
enmapboxtestdata.createClassifier().pickle(filename=filename)
File "D:\Repositories\enmap-box\hubflow\core.py", line 522, in pickle
with open(filename, 'wb') as f:
PermissionError: [Errno 13] Permission denied: './outClassifier.pkl'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "D:\Repositories\enmap-box\enmapboxgeoalgorithms\provider.py", line 166, in processAlgorithm
raise Exception('unexpected error')
Exception: unexpected error

Execution failed after 1.16 seconds

This can be avoided by using a “temp” directory or the user’s home directory as root, if the users has specified a relative path only, like “outClassifier.pkl”

Comments (11)

  1. Andreas Janz

    In QGIS the QGIS Processing delivers a proper temp path relative to the user profile. I replicated this behaviour in case of relative pathes.

  2. Benjamin Jakimow reporter

    How does this default path look like in your case @Andreas Rabe?

    On my windows it’s

    1. within the EnMAP-Box plugin folder. The folder will be deleted with each plugin update
    2. within the AppData folder. This one is hidden by default in the windows explorer

  3. Andreas Janz

    {'outClassifier': 'C:\\Users\\janzandr\\AppData\\Local\\Temp\\QGIS-PythonTestConfigPath51l8ft76\\profiles\\default\\processing\\outputs\\outClassifier.pkl'}

    Internally I use the following:

            if not isabs(filename):
                filename = abspath(join(QgsApplication.qgisSettingsDirPath(), 'processing', 'outputs', filename))
    

  4. Andreas Janz

    within the AppData folder. This one is hidden by default in the windows explorer

    That is correct! In QGIS the relative path is also made absolute by using a folder under AppData.

  5. Andreas Janz

    In QGIS it is: {'outClassifier': 'C:/Users/janzandr/AppData/Roaming/QGIS/QGIS3/profiles/default/processing/outputs/outClassifier.pkl'}

  6. Benjamin Jakimow reporter

    Are you sure it’s the QGIS default to write temp data outputs below a profile settings folder?

    When running the “Create constant raster layer” PA, my temp file gets written to AppData/Local/Temp. This directory is also returned by QDir.tempPath(). So this “core” PA would not write to somewhere below AppData/Roaming/QGIS/QGIS3/profiles.

    QGIS version: 3.16.0-Hannover
    QGIS code revision: 43b64b13f3
    Qt version: 5.11.2
    GDAL version: 3.1.4
    GEOS version: 3.8.1-CAPI-1.13.3
    PROJ version: Rel. 6.3.2, May 1st, 2020
    Processing algorithm
    Algorithm 'Create constant raster layer' starting
    Input parameters:
    { 'EXTENT' : '-179.900024414,179.900024414,-89.900001526,83.634101868 [EPSG:4326]', 'NUMBER' : 1, 'OUTPUT' : 'TEMPORARY_OUTPUT', 'OUTPUT_TYPE' : 5, 'PIXEL_SIZE' : 50, 'TARGET_CRS' : QgsCoordinateReferenceSystem('EPSG:4326') }
    
    Execution completed in 0.11 seconds
    Results:
    {'OUTPUT': 'C:/Users/geo_beja/AppData/Local/Temp/processing_mXqVbU/0b904a362e464dba9e7237f433cfbb9f/OUTPUT.tif'}
    
    Loading resulting layers
    Algorithm 'Create constant raster layer' finished
    

  7. Andreas Janz

    QGIS behaves different if you put a basename, e.g. …

    … or an empty string:

    Not saying that that makes much sense.

  8. Benjamin Jakimow reporter

    Alright. Without basename it goes to QDir.tempPath(), with basename to the active user profile folder

  9. Log in to comment