pyogrio icon indicating copy to clipboard operation
pyogrio copied to clipboard

ENH: Centralize the "driver" properties

Open theroggy opened this issue 2 years ago • 2 comments

Centralize the "driver" properties by expanding on the current DRIVERS dict as a dict/class/enum to add e.g. following things as properties:

  • drivername
  • has_0_based_fid
  • supports_mixed_single_multi (to replace the DRIVERS_NO_MIXED_SINGLE_MULTI dict)
  • supported_write modes? (could reuse the info in _ogr.pyx)
  • ...

theroggy avatar Apr 22 '22 21:04 theroggy

That sounds as a good idea.

It could be something like a simple class like, or using dataclasses:

from dataclasses import dataclass

@dataclass
class DriverInfo:
    name: str
    ext: str
    ...

    def __str__(self):
        return self.name

GeoPackage = DriverInfo("GPKG", ext="gpkg", ...)

and then we can parametrize the tests with those objects, and inside the tests use driver.name or driver.ext etc?

jorisvandenbossche avatar Apr 29 '22 07:04 jorisvandenbossche

This is what I use in geofileops:

  • https://github.com/geofileops/geofileops/blob/master/geofileops/util/geofiletype.py
  • + https://github.com/geofileops/geofileops/blob/master/geofileops/util/geofiletypes.csv
  • Too few tests can be found here: https://github.com/geofileops/geofileops/blob/master/tests/test_geofiletype.py

It's a combination of a dataclass that's filled up using a .csv configuration file + an enum to support typo-safety when using drivers.

An advantage is that the properties are maintained in a .csv, which gives a good overview and easy way to maintain all properties if many drivers and many properties need to be maintained.

A disadvantage is that the properties are maintained in a .csv, which gives some odd plumbing code. So I think there should be cleaner ways to deal with this... but didn't think of any at the time of writing.

Anyway, it could give some inspiration... both on things that might be good ideas and things that aren't ;-).

theroggy avatar Apr 29 '22 09:04 theroggy