Apostrophes in filenames are incorrectly converted to octal codes

Aperta Adatta ai principianti
#5,014 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
backend

Direzione di ricerca

Inizia leggendo il codice per la costruzione degli argomenti usato da build_arg_list e la discussione nella PR #4987. Traccia il modo in cui vengono effettuati l’escaping delle opzioni relative ai nomi dei file, poi aggiungi un test di regressione che mostri che un apostrofo resta letterale in un percorso di file; l’esempio fornito riproduce il problema. Il lavoro è completo quando il test passa e i percorsi di file con apostrofi arrivano a GMT senza modifiche.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Description of the problem

On Windows, sphdistance returns normally for outgrid="cell's.nc", but the file is missing. Using cells.nc produces the expected grid. I also reproduced this with grdcut. The native GMT CLI wrote cell's.nc successfully, and its grid matched the PyGMT control at all 18 points.

build_arg_list({"G": "cell's.nc"})[0] returns r"-Gcell\234s.nc". The apostrophe has been converted to a PostScript escape before the filename reaches GMT. File options need the literal path. Discussion in #4987

Minimal Complete Verifiable Example
from pathlib import Path
from tempfile import TemporaryDirectory

import pygmt

with TemporaryDirectory() as tmp:
    for name in ("cells.nc", "cell's.nc"):
        path = Path(tmp) / name
        pygmt.sphdistance(
            x=[85.5, 82.3, 85.8, 86.5],
            y=[22.3, 22.6, 22.4, 23.3],
            region=[82, 87, 22, 24],
            spacing=1,
            outgrid=path,
        )
        assert path.is_file(), name
Full error message

GMT writes the following diagnostic to stderr on Windows. The temporary directory is abbreviated.

sphdistance (gmtapi_export_grid): Not a supported grid format [<temp>\cell\234s.nc]
[Session pygmt-session (5)]: Error returned from GMT API: GMT_GRID_WRITE_ERROR (19)
[Session pygmt-session (5)]: Error returned from GMT API: GMT_GRID_WRITE_ERROR (19)
[Session pygmt-session (5)]: Error returned from GMT API: GMT_GRID_WRITE_ERROR (19)

The second assertion raises AssertionError: cell's.nc.

System information

Reproduced with the PyGMT v0.19.0 wheel and with main at f0c88198e6543f21bc4f7f1eca3f5359f9d9b20e. The following pygmt.show_versions() output is from v0.19.0, with local installation paths shortened.

PyGMT information:
  version: v0.19.0
System information:
  python: 3.12.0 (tags/v3.12.0:0fb18b0, Oct  2 2023, 13:03:39) [MSC v.1935 64 bit (AMD64)]
  executable: <venv>/Scripts/python.exe
  machine: Windows-11-10.0.26300-SP0
Dependency information:
  numpy: 2.2.6
  pandas: 2.3.3
  xarray: 2026.9.0
  packaging: 26.4
  contextily: None
  geopandas: None
  IPython: None
  pyarrow: None
  rioxarray: None
  gdal: 3.12.4
  ghostscript: 10.07.1
GMT library information:
  version: 6.8.0
  padding: 2
  share dir: <GMT>/share
  plugin dir: <GMT>/bin/gmt_plugins
  library path: <GMT>/bin/gmt.dll
  cores: 32
  grid layout: rows
  image layout:
  binary version: 6.8.0
Lingua principale
Python
Stelle
882
Fork
261
Merge medio
1g 3h
PR unite (30g)
29

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di GenericMappingTools/pygmt

Tutte le issue di GenericMappingTools/pygmt

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.