Fiona
Fiona copied to clipboard
Use absolute paths when reporting errors
Expected behavior and actual behavior.
This morning I accidentally re-discovered that Path('.').parent != Path('..'). This is not a problem caused by Fiona; however, it took an hour longer to debug than it would have if Fiona reported absolute paths in error messages rather relative paths.
The project layout l was dealing with looks like this:
.
├── data
│ ├── zip2d
│ └── zip2d-complete.tar.gz
├── lazy-install.sh
├── pyproject.toml
├── README.md
├── requirements.txt
└── src
└── zip2d.py
The current behavior, reporting erroneous paths as relative, made it ambiguous as to whether the path was relative to the script that was being executed or if it was relative to the current working directory. Furthermore, I initially believed that this might be a bug in Fiona's relative path handling (not realizing that pathlib had such an unintuitive behavior.) An absolute path- or even making the relative path unambiguous by prefixing the relative path with the one that it is relative to- would have cut this hours-long debug session down to minutes.
Expected: error messages contain absolute paths so that they are unambiguous.
Actual: fiona.errors.DriverIOError: Failed to create file ../data/zip2d/zip2d.shp: No such file or directory
Steps to reproduce the problem.
$ cat lazy-install.sh
#!/bin/sh
set -eu
/usr/bin/python3 -m venv venv
. venv/bin/activate
pip install -U pip setuptools wheel
pip install -r requirements.txt
wget https://www2.census.gov/geo/tiger/TIGER2019/ZCTA5/tl_2019_us_zcta510.zip -O data/tiger.zip
unzip data/tiger.zip -d data/tl_2019_us_zcta510
./src/zip2d.py
$ cat requirements.txt
Fiona
Shapely
Operating system
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.4 LTS
Release: 20.04
Codename: focal
Fiona and GDAL version and provenance
$ . venv/bin/activate && pip list | grep Fiona && pip --version | sed -e "s/$(whoami)/ubuntu_user/g" -e "s/$(hostname)/ubuntu_host/g"
Fiona 1.8.21
pip 22.1.2 from /mnt/ubuntu_host.1/home/ubuntu_user/dev/zip2d/venv/lib/python3.8/site-packages/pip (python 3.8)
For example: the 1.7.10.post1 manylinux1 wheel installed from PyPI using pip version 9.0.1.
For example: GDAL 2.1.0 installed via Homebrew
Can you share the zip2d.py script? I'd like to see how you're using fiona.open in it.
Closing. These particular error messages are provided by GDAL. It's an upstream issue.
Closing. These particular error messages are provided by GDAL. It's an upstream issue.
Hey sorry I didn't respond to your previous comment! A series of life events pulled me away from GitHub. In any case, closing seems very appropriate and just wanted to say thank you for looking into this.