Skip to content

Commit

Permalink
removed dependence on pkg_resources
Browse files Browse the repository at this point in the history
  • Loading branch information
cnheider committed Aug 1, 2023
1 parent 72ee626 commit 9eb0967
Show file tree
Hide file tree
Showing 28 changed files with 504 additions and 330 deletions.
21 changes: 13 additions & 8 deletions jord/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
from typing import Any
from warnings import warn

import pkg_resources
from importlib import resources
from importlib.metadata import PackageNotFoundError
from warg import package_is_editable
from apppath import AppPath
from warg import dist_is_editable

__project__ = "Jord"
__author__ = "Christian Heider Nielsen"
__version__ = "0.1.1"
__version__ = "0.1.2"
__doc__ = r"""
.. module:: jord
:platform: Unix, Windows
Expand All @@ -35,14 +37,13 @@
PROJECT_AUTHOR = __author__.lower().strip().replace(" ", "_")
PROJECT_ORGANISATION = "Automaps"
PROJECT_APP_PATH = AppPath(app_name=PROJECT_NAME, app_author=PROJECT_AUTHOR)
PACKAGE_DATA_PATH = Path(pkg_resources.resource_filename(PROJECT_NAME, "data"))
INCLUDE_PROJECT_READMES = False

distributions = {v.key: v for v in pkg_resources.working_set}
if PROJECT_NAME in distributions:
distribution = distributions[PROJECT_NAME]
DEVELOP = dist_is_editable(distribution)
else:
PACKAGE_DATA_PATH = resources.files(PROJECT_NAME) / "data"

try:
DEVELOP = package_is_editable(PROJECT_NAME)
except PackageNotFoundError as e:
DEVELOP = True


Expand Down Expand Up @@ -96,3 +97,7 @@ def get_version(append_time: Any = DEVELOP) -> str:
__version__ = get_version(append_time=True)

__version_info__ = tuple(int(segment) for segment in __version__.split("."))


if __name__ == "__main__":
print(PROJECT_APP_PATH.user_cache)
3 changes: 3 additions & 0 deletions jord/qgis_utilities/categorisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
from typing import Iterable, Sized, Callable, Generator

from PyQt5.Qt import QColor

# noinspection PyUnresolvedReferences
from qgis.core import (
QgsVectorLayer,
QgsSymbol,
QgsRendererCategory,
QgsCategorizedSymbolRenderer,
)

from warg import TripleNumber, QuadNumber, n_uint_mix_generator_builder

__all__ = ["categorise_layer"]
Expand Down
7 changes: 6 additions & 1 deletion jord/qgis_utilities/configuration/plugin_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

from typing import Any

from qgis.core import QgsSettings

from jord import PROJECT_NAME

Expand All @@ -24,6 +23,9 @@ def store_plugin_setting(key: str, value: Any, *, project_name: str = PROJECT_NA
:param project_name:
:return:
"""
# noinspection PyUnresolvedReferences
from qgis.core import QgsSettings

QgsSettings().setValue(f"{project_name}/{key}", value)


Expand All @@ -37,6 +39,9 @@ def read_plugin_setting(
:param project_name:
:return:
"""
# noinspection PyUnresolvedReferences
from qgis.core import QgsSettings

return QgsSettings().value(f"{project_name}/{key}", default_value)


Expand Down
12 changes: 9 additions & 3 deletions jord/qgis_utilities/configuration/project_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@
from logging import warning
from typing import Any, Mapping, Optional

from qgis.core import QgsProject

from jord import PROJECT_NAME

qgis_project = QgsProject.instance()


def restore_default_project_settings(
defaults: Optional[Mapping] = None, *, project_name: str = PROJECT_NAME
Expand All @@ -46,6 +43,11 @@ def store_project_setting(key: str, value: Any, *, project_name: str = PROJECT_N
:param project_name:
:return:
"""
# noinspection PyUnresolvedReferences
from qgis.core import QgsProject

qgis_project = QgsProject.instance()

if isinstance(value, bool):
qgis_project.writeEntryBool(project_name, key, value)
elif isinstance(value, float):
Expand Down Expand Up @@ -74,6 +76,10 @@ def read_project_setting(
:param project_name:
:return:
"""
# noinspection PyUnresolvedReferences
from qgis.core import QgsProject

qgis_project = QgsProject.instance()

# read values (returns a tuple with the value, and a status boolean
# which communicates whether the value retrieved could be converted to
Expand Down
17 changes: 17 additions & 0 deletions jord/qgis_utilities/enums.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from enum import Enum

# noinspection PyUnresolvedReferences
from qgis.core import (
QgsMultiBandColorRenderer,
QgsPalettedRasterRenderer,
Expand All @@ -10,10 +11,26 @@

__all__ = ["QgisRendererEnum"]

from jord.geojson_utilities import GeoJsonGeometryTypesEnum


class QgisRendererEnum(Enum):
multi_band = QgsMultiBandColorRenderer
paletted_raster = QgsPalettedRasterRenderer
single_band_color = QgsSingleBandColorDataRenderer
single_band_gray = QgsSingleBandGrayRenderer
single_band_pseudo = QgsSingleBandPseudoColorRenderer


class QgisLayerTypeEnum(Enum):
point = GeoJsonGeometryTypesEnum.point.value.__name__
multi_point = GeoJsonGeometryTypesEnum.multi_point.value.__name__
line_string = GeoJsonGeometryTypesEnum.line_string.value.__name__
multi_line_string = GeoJsonGeometryTypesEnum.multi_line_string.value.__name__
polygon = GeoJsonGeometryTypesEnum.polygon.value.__name__
multi_polygon = GeoJsonGeometryTypesEnum.multi_polygon.value.__name__
curve_polygon = "CurvePolygon"
multi_surface = "MultiSurface"
compound_curve = "CompoundCurve"
multi_curve = "MultiCurve"
no_geometry = "No Geometry"
1 change: 1 addition & 0 deletions jord/qgis_utilities/helpers/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QAction, QWidget

from jord.qgis_utilities.helpers.signals import reconnect_signal


Expand Down
7 changes: 7 additions & 0 deletions jord/qgis_utilities/helpers/drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@
Created on 02-12-2020
"""

# noinspection PyUnresolvedReferences
from qgis.PyQt import QtGui

# noinspection PyUnresolvedReferences
from qgis.PyQt.QtCore import Qt

# noinspection PyUnresolvedReferences
from qgis.core import QgsWkbTypes

# noinspection PyUnresolvedReferences
from qgis.gui import QgsMapCanvas, QgsRubberBand

__all__ = ["make_rubber_band"]
Expand Down
1 change: 1 addition & 0 deletions jord/qgis_utilities/helpers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from typing import Any, Optional, Tuple

# noinspection PyUnresolvedReferences
from qgis.PyQt import QtCore

__all__ = ["MyTableModel"]
Expand Down
1 change: 1 addition & 0 deletions jord/qgis_utilities/helpers/progress_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from typing import Tuple

# noinspection PyUnresolvedReferences
from qgis.PyQt import QtGui, QtWidgets

__all__ = ["dialog_progress_bar"]
Expand Down
23 changes: 21 additions & 2 deletions jord/qgis_utilities/helpers/sessions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from qgis.core import QgsMapLayer
from qgis.core import QgsMapLayer, QgsRasterDataProvider
from warg import AlsoDecorator

__all__ = ["QLayerEditSession"]
__all__ = ["QLayerEditSession", "RasterDataProviderEditSession"]


class QLayerEditSession(AlsoDecorator):
Expand All @@ -16,3 +16,22 @@ def __enter__(self):
def __exit__(self, exc_type, exc_val, exc_tb):
if self.map_layer:
self.map_layer.commitChanges()


class RasterDataProviderEditSession(AlsoDecorator):
def __init__(
self, raster_data_provider: QgsRasterDataProvider, auto_reload: bool = True
):
self.raster_data_provider = raster_data_provider
self.auto_reload = auto_reload

def __enter__(self):
if self.raster_data_provider:
self.raster_data_provider.setEditable(True)
return True

def __exit__(self, exc_type, exc_val, exc_tb):
if self.raster_data_provider:
self.raster_data_provider.setEditable(False)
if self.auto_reload:
self.raster_data_provider.reload()
1 change: 1 addition & 0 deletions jord/qgis_utilities/helpers/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from logging import warning

# noinspection PyUnresolvedReferences
from qgis.PyQt import QtCore

IS_DEBUGGING = False
Expand Down
3 changes: 3 additions & 0 deletions jord/qgis_utilities/helpers/timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
import time
from typing import Any

# noinspection PyUnresolvedReferences
from qgis.PyQt import QtGui

# noinspection PyUnresolvedReferences
from qgis.PyQt.QtCore import Qt

__all__ = ["qt_draw_timestamp"]
Expand Down
14 changes: 9 additions & 5 deletions jord/qgis_utilities/numpy_utilities/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@

import numpy
from PIL import Image

# noinspection PyUnresolvedReferences
from qgis.PyQt import QtGui

# noinspection PyUnresolvedReferences
from qgis.core import (
QgsCoordinateReferenceSystem,
QgsCoordinateTransform,
Expand Down Expand Up @@ -96,11 +100,11 @@ def get_coordinates_of_layer_extent(layer: QgsVectorLayer) -> list:
"""

layerRectangle = layer.extent()
layer_rectangle = layer.extent()

return [
layerRectangle.xMinimum(),
layerRectangle.yMinimum(),
layerRectangle.xMaximum(),
layerRectangle.yMaximum(),
layer_rectangle.xMinimum(),
layer_rectangle.yMinimum(),
layer_rectangle.xMaximum(),
layer_rectangle.yMaximum(),
]
4 changes: 1 addition & 3 deletions jord/qgis_utilities/numpy_utilities/data_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
from typing import Any

import numpy
from qgis.core import (
Qgis,
)
from qgis.core import Qgis


class QgisDataTypeEnum(Enum):
Expand Down
5 changes: 3 additions & 2 deletions jord/qgis_utilities/plugin_version.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# noinspection PyUnresolvedReferences
from pyplugin_installer.installer_data import repositories, plugins


__all__ = ["plugin_status"]


def plugin_status(plugin_key:str) -> str:
def plugin_status(plugin_key: str) -> str:
all_plugins = plugins.all()
if plugin_key in all_plugins:
return all_plugins[plugin_key]["status"]
return 'Not Found'
return "Not Found"


# utils.reloadPlugin()
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# noinspection PyUnresolvedReferences
from qgis.core import * # attach main QGIS library

# noinspection PyUnresolvedReferences
from qgis.utils import * # attach main python library


Expand Down
7 changes: 2 additions & 5 deletions jord/qgis_utilities/styling.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
from typing import Mapping

from PyQt5.QtGui import QColor
from warg import TripleNumber
import random
from itertools import cycle
from typing import Any, Iterable, Sized

from PyQt5.Qt import QColor

# noinspection PyUnresolvedReferences
from qgis.core import (
QgsVectorLayer,
QgsSymbol,
Expand Down
19 changes: 19 additions & 0 deletions jord/qlive_utilities/clients/arguments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import inspect
from enum import Enum
from typing import Callable


class ArgumentSatisfactionEnum(Enum):
none = "none"
args = "args"
kws = "kws"
argskws = "argskws"


def partial_satisfied(partial_fn: Callable) -> bool:
signature = inspect.signature(partial_fn.func)
try:
signature.bind(*partial_fn.args, **partial_fn.keywords)
return True
except TypeError:
return False
18 changes: 1 addition & 17 deletions jord/qlive_utilities/clients/auto.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from functools import partial
from typing import Callable
import inspect
from enum import Enum
from jord.qlive_utilities import (
QliveClient,
QliveRPCMethodEnum,
Expand All @@ -12,21 +10,7 @@

__all__ = ["AutoQliveClient"]


class DisSatisfactionEnum(Enum):
none = "none"
args = "args"
kws = "kws"
argskws = "argskws"


def partial_satisfied(partial_fn: Callable) -> bool:
signature = inspect.signature(partial_fn.func)
try:
signature.bind(*partial_fn.args, **partial_fn.keywords)
return True
except TypeError:
return False
from jord.qlive_utilities.clients.arguments import partial_satisfied


class AutoQliveClient(QliveClient):
Expand Down
6 changes: 6 additions & 0 deletions jord/qlive_utilities/clients/interfaced.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@
class InterfacedQliveClient(QliveClient):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

def raster(self):
...

def geometry(self):
...
Loading

0 comments on commit 9eb0967

Please sign in to comment.