Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove _loading, copy into __init__ #1168

Merged
merged 2 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ All issue numbers are relative to https://github.com/Toblerity/Fiona/issues.

Changes:

* The fiona._loading module, which supports DLL loading on Windows,
has been moved into __init__.py and is no longer used anywhere else (#1168).
* Move project metadata to pyproject.toml (#1165).
* Update drvsupport.py to reflect new format capabilities in GDAL 3.6.0
(#1122).
Expand Down
75 changes: 39 additions & 36 deletions fiona/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,42 +76,45 @@
class Path:
pass

# TODO: remove this? Or at least move it, flake8 complains.
if sys.platform == "win32":
libdir = os.path.join(os.path.dirname(__file__), ".libs")
os.environ["PATH"] = os.environ["PATH"] + ";" + libdir

import fiona._loading

with fiona._loading.add_gdal_dll_directories():
from fiona.collection import BytesCollection, Collection
from fiona.drvsupport import supported_drivers
from fiona.env import ensure_env_with_credentials, Env
from fiona.errors import FionaDeprecationWarning
from fiona._env import driver_count
from fiona._env import (
calc_gdal_version_num,
get_gdal_version_num,
get_gdal_release_name,
get_gdal_version_tuple,
)
from fiona.io import MemoryFile
from fiona.ogrext import (
_bounds,
_listlayers,
_listdir,
FIELD_TYPES_MAP,
_remove,
_remove_layer,
)
from fiona.path import ParsedPath, parse_path, vsi_path
from fiona.vfs import parse_paths as vfs_parse_paths
from fiona._show_versions import show_versions

# These modules are imported by fiona.ogrext, but are also import here to
# help tools like cx_Freeze find them automatically
from fiona import _geometry, _err, rfc3339
import uuid
if platform.system() == "Windows":
_whl_dir = os.path.join(os.path.dirname(__file__), ".libs")
if os.path.exists(_whl_dir):
os.add_dll_directory(_whl_dir)
else:
if "PATH" in os.environ:
for p in os.environ["PATH"].split(os.pathsep):
if glob.glob(os.path.join(p, "gdal*.dll")):
os.add_dll_directory(p)


from fiona.collection import BytesCollection, Collection
from fiona.drvsupport import supported_drivers
from fiona.env import ensure_env_with_credentials, Env
from fiona.errors import FionaDeprecationWarning
from fiona._env import driver_count
from fiona._env import (
calc_gdal_version_num,
get_gdal_version_num,
get_gdal_release_name,
get_gdal_version_tuple,
)
from fiona.io import MemoryFile
from fiona.ogrext import (
_bounds,
_listlayers,
_listdir,
FIELD_TYPES_MAP,
_remove,
_remove_layer,
)
from fiona.path import ParsedPath, parse_path, vsi_path
from fiona.vfs import parse_paths as vfs_parse_paths
from fiona._show_versions import show_versions

# These modules are imported by fiona.ogrext, but are also import here to
# help tools like cx_Freeze find them automatically
from fiona import _geometry, _err, rfc3339
import uuid


__all__ = ['bounds', 'listlayers', 'listdir', 'open', 'prop_type', 'prop_width']
Expand Down
53 changes: 25 additions & 28 deletions fiona/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,31 @@
import warnings
from collections import OrderedDict

import fiona._loading

with fiona._loading.add_gdal_dll_directories():
from fiona import compat, vfs
from fiona.ogrext import Iterator, ItemsIterator, KeysIterator
from fiona.ogrext import Session, WritingSession
from fiona.ogrext import buffer_to_virtual_file, remove_virtual_file, GEOMETRY_TYPES
from fiona.errors import (
DriverError,
SchemaError,
CRSError,
UnsupportedGeometryTypeError,
UnsupportedOperation,
DriverSupportError,
)
from fiona.logutils import FieldSkipLogFilter
from fiona.crs import CRS
from fiona._env import get_gdal_release_name, get_gdal_version_tuple
from fiona.env import env_ctx_if_needed
from fiona.errors import FionaDeprecationWarning
from fiona.drvsupport import (
driver_from_extension,
supported_drivers,
driver_mode_mingdal,
_driver_converts_field_type_silently_to_str,
_driver_supports_field,
)
from fiona.path import Path, vsi_path, parse_path
from fiona import compat, vfs
from fiona.ogrext import Iterator, ItemsIterator, KeysIterator
from fiona.ogrext import Session, WritingSession
from fiona.ogrext import buffer_to_virtual_file, remove_virtual_file, GEOMETRY_TYPES
from fiona.errors import (
DriverError,
SchemaError,
CRSError,
UnsupportedGeometryTypeError,
UnsupportedOperation,
DriverSupportError,
)
from fiona.logutils import FieldSkipLogFilter
from fiona.crs import CRS
from fiona._env import get_gdal_release_name, get_gdal_version_tuple
from fiona.env import env_ctx_if_needed
from fiona.errors import FionaDeprecationWarning
from fiona.drvsupport import (
driver_from_extension,
supported_drivers,
driver_mode_mingdal,
_driver_converts_field_type_silently_to_str,
_driver_supports_field,
)
from fiona.path import Path, vsi_path, parse_path


_GDAL_VERSION_TUPLE = get_gdal_version_tuple()
Expand Down
29 changes: 13 additions & 16 deletions fiona/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,19 @@

import attr

import fiona._loading

with fiona._loading.add_gdal_dll_directories():
from fiona._env import (
GDALDataFinder,
GDALEnv,
PROJDataFinder,
calc_gdal_version_num,
get_gdal_config,
get_gdal_release_name,
get_gdal_version_num,
set_gdal_config,
set_proj_data_search_path,
)
from fiona.errors import EnvError, FionaDeprecationWarning, GDALVersionError
from fiona.session import Session, DummySession
from fiona._env import (
GDALDataFinder,
GDALEnv,
PROJDataFinder,
calc_gdal_version_num,
get_gdal_config,
get_gdal_release_name,
get_gdal_version_num,
set_gdal_config,
set_proj_data_search_path,
)
from fiona.errors import EnvError, FionaDeprecationWarning, GDALVersionError
from fiona.session import Session, DummySession


class ThreadEnv(threading.local):
Expand Down
4 changes: 1 addition & 3 deletions fiona/fio/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
import click

import fiona
import fiona._loading
with fiona._loading.add_gdal_dll_directories():
from fiona._env import GDALDataFinder, PROJDataFinder
from fiona._env import GDALDataFinder, PROJDataFinder


@click.command(short_help="Print information about the fio environment.")
Expand Down
11 changes: 5 additions & 6 deletions fiona/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@

from collections import OrderedDict
import logging
import fiona._loading
with fiona._loading.add_gdal_dll_directories():
from fiona.ogrext import MemoryFileBase
from fiona.collection import Collection
from fiona.meta import supports_vsi
from fiona.errors import DriverError

from fiona.ogrext import MemoryFileBase
from fiona.collection import Collection
from fiona.meta import supports_vsi
from fiona.errors import DriverError

log = logging.getLogger(__name__)

Expand Down
8 changes: 4 additions & 4 deletions fiona/meta.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import xml.etree.ElementTree as ET
import logging
import xml.etree.ElementTree as ET

import fiona
with fiona._loading.add_gdal_dll_directories():
from fiona.ogrext import _get_metadata_item
from fiona.env import require_gdal_version
from fiona.env import require_gdal_version
from fiona.ogrext import _get_metadata_item

log = logging.getLogger(__name__)

Expand Down
5 changes: 1 addition & 4 deletions fiona/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import logging
import os

import fiona._loading

with fiona._loading.add_gdal_dll_directories():
from fiona.path import parse_path, UnparsedPath
from fiona.path import parse_path, UnparsedPath

log = logging.getLogger(__name__)

Expand Down
11 changes: 4 additions & 7 deletions fiona/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

from warnings import warn

import fiona._loading

with fiona._loading.add_gdal_dll_directories():
from fiona._transform import _transform, _transform_geom
from fiona.compat import DICT_TYPES
from fiona.errors import FionaDeprecationWarning
from fiona.model import _guard_model_object, Geometry
from fiona._transform import _transform, _transform_geom
from fiona.compat import DICT_TYPES
from fiona.errors import FionaDeprecationWarning
from fiona.model import _guard_model_object, Geometry


def transform(src_crs, dst_crs, xs, ys):
Expand Down