Skip to content

Commit

Permalink
Merge pull request #33 from Riverscapes/dev
Browse files Browse the repository at this point in the history
0.5.2 HOTFIX For filepaths on OSX
  • Loading branch information
MattReimer authored Aug 11, 2021
2 parents 32eae72 + 208eb78 commit de68cbe
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 14 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,26 @@ clone this repo to `qrave_toolbar_dev` so that `qrave_toolbar` is what gets used

## On OSX

You need this user setting to be on (it's in the user settings preferences)
before you start you need to set an environment variable to tell VSCode where QGIS's version of python is. This will depend on which shell you're using (The default is bash but we tend to use zsh)

1. You need to add the following line at the bottom of your `~/.bashrc` or `~/.zshrc` file:

```bash
export QGIS_PATH=/Applications/QGIS.app
```

***NOTE: This path must not end in a slash and must match what's on your system. If you're using the LTR version of QGIS this path might be something like `/Applications/QGIS-LTR.app`***

After this is done you need to restart VSCode completely (not just relloading the window).

2. You need this user setting to be on (it's in the user settings preferences)

```
"terminal.integrated.allowWorkspaceConfiguration": true
```

3. Open up the `Workspaces/OSXDev.code-workspace` using VSCode. This file contains all the right environment variables necessary to find and work with QGIS python libraries.


## Development resources

Expand Down
9 changes: 4 additions & 5 deletions Workspaces/OSXDev.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
// "editor.background": "#1c2c2a"
},
"terminal.integrated.env.osx": {
"QGIS_PREFIX_PATH": "/Applications/QGIS.app/Contents",
"QGIS_PATH": "/Applications/QGIS.app/Contents",
"PYTHONPATH": "/Applications/QGIS.app/Contents/Resources/python:/Applications/QGIS.app/Contents/Resources/python/site-packages:/Applications/QGIS.app/Contents/Resources/python/site-packages/PyQt5",
"PATH": "${env:PATH}:/Applications/QGIS.app/Contents/MacOS/bin"
"PYTHONPATH": "${env:QGIS_PATH}/Contents/Resources/python:${env:QGIS_PATH}/Contents/Resources/python/site-packages:${env:QGIS_PATH}/Contents/Resources/python/site-packages/PyQt5",
"PATH": "${env:PATH}:${env:QGIS_PATH}/Contents/MacOS/bin"
},
"python.pythonPath": "/Applications/QGIS.app/Contents/MacOS/bin/python3.8",
// NOTE: For this to work you need an env file with "QGIS_PATH=/Applications/QGIS-LTR.app/Contents" or whatever your path is
"python.pythonPath": "${env:QGIS_PATH}/Contents/MacOS/bin/python3.8",
},
"launch": {
"configurations": [],
Expand Down
2 changes: 1 addition & 1 deletion __version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.5.1"
__version__ = "0.5.2"
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ sphinxcontrib-serializinghtml==1.1.4
toml==0.10.2
typed-ast==1.4.3
typing-extensions==3.7.4.3
urllib3==1.25.9
urllib3>=1.26.5
virtualenv==20.4.3
wrapt==1.12.1
wxPython==4.0.7
Expand Down
7 changes: 6 additions & 1 deletion src/classes/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def _build_views(self):
self.qproject.appendRow(curr_item)

def _recurse_tree(self, bl_el=None, proj_el=None, parent: QStandardItem = None):
settings = Settings()
if self.business_logic is None:
return
if bl_el is None:
Expand Down Expand Up @@ -167,7 +168,7 @@ def _recurse_tree(self, bl_el=None, proj_el=None, parent: QStandardItem = None):
children_container = bl_el.find('Children')

# If there are children then this is a branch
if children_container:
if children_container is not None:
curr_item.setIcon(QIcon(':/plugins/qrave_toolbar/BrowseFolder.png'))
if is_root is True:
curr_item.setData(ProjectTreeData(QRaveTreeTypes.PROJECT_ROOT, project=self, data=dict(children_container.attrib)), Qt.UserRole),
Expand Down Expand Up @@ -221,6 +222,10 @@ def _recurse_tree(self, bl_el=None, proj_el=None, parent: QStandardItem = None):
curr_item.setData(ProjectTreeData(QRaveTreeTypes.LEAF, project=self, data=map_layer), Qt.UserRole)

if not map_layer.exists:
settings.msg_bar(
'Missing File',
'Error finding file with path={}'.format(map_layer.layer_uri),
Qgis.Warning)
curr_item.setData(QBrush(Qt.red), Qt.ForegroundRole)
curr_item_font = curr_item.font()
curr_item_font.setItalic(True)
Expand Down
14 changes: 9 additions & 5 deletions src/classes/qrave_map_layer.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from __future__ import annotations
import os
from typing import Dict, Union
from typing import Dict
from qgis.core import Qgis, QgsProject, QgsRasterLayer, QgsVectorLayer
from qgis.PyQt.QtCore import Qt, QModelIndex, QUrl
from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtGui import QStandardItem
from .rspaths import parse_rel_path
from .settings import CONSTANTS, Settings

SYMBOLOGY_DIR = os.path.join(os.path.dirname(__file__), '..', '..', 'resources', 'symbology')
Expand Down Expand Up @@ -58,11 +59,14 @@ def __init__(self,
layer_name: str = None,
tile_type: str = None
):

self.label = label
self.layer_uri = layer_uri

if isinstance(layer_uri, str) and len(layer_uri) > 0 and layer_type != QRaveMapLayer.LayerTypes.WEBTILE:
self.layer_uri = os.path.abspath(layer_uri)
# If this is a real file then sanitize the URI
if isinstance(self.layer_uri, str) and len(layer_uri) > 0 and layer_type != QRaveMapLayer.LayerTypes.WEBTILE:
sani_path = parse_rel_path(layer_uri)
self.layer_uri = os.path.abspath(sani_path)

self.bl_attr = bl_attr
self.meta = meta
Expand All @@ -75,7 +79,7 @@ def __init__(self,
settings.log('Layer type "{}" is not valid'.format(layer_type), Qgis.Critical)
self.layer_type = layer_type

self.exists = self.layer_type == QRaveMapLayer.LayerTypes.WEBTILE or os.path.isfile(layer_uri)
self.exists = self.layer_type == QRaveMapLayer.LayerTypes.WEBTILE or os.path.isfile(self.layer_uri)

@staticmethod
def _addgrouptomap(sGroupName, sGroupOrder, parentGroup):
Expand Down
29 changes: 29 additions & 0 deletions src/classes/rspaths.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
""" handling of paths across operating systems
NOTE: this originally came from riverscapes-tools and was unit tested there
"""
from pathlib import Path, PurePosixPath


def parse_rel_path(path: str) -> str:
""" Path handling across platforms is gnarly.
This method returns the correct path for your operating system regardless of
whether the input is a windows path or a linux path
Args:
path ([type]): [description]
Returns:
[type]: [description]
"""
new_path = Path(path.replace('\\', '/')).resolve()
return str(new_path)


def parse_posix_path(path: str) -> str:
"""This method returns a posix path no matter if you pass it a windows or a linux path
Args:
path ([type]): [description]
"""
new_path = PurePosixPath(path.replace('\\', '/'))
return str(new_path)

0 comments on commit de68cbe

Please sign in to comment.