Skip to content

Commit

Permalink
Fix version number reporting ambiguity
Browse files Browse the repository at this point in the history
Fixes #68
  • Loading branch information
nyalldawson committed Jul 21, 2020
1 parent b536ef9 commit 76ec933
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
10 changes: 9 additions & 1 deletion processing_r/processing/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class RAlgorithmProvider(QgsProcessingProvider):
Processing provider for executing R scripts
"""

VERSION = '2.2.1'

def __init__(self):
super().__init__()
self.algs = []
Expand All @@ -50,6 +52,8 @@ def __init__(self):
self.contextMenuActions = [EditScriptAction(),
DeleteScriptAction()]

self.r_version = None

def load(self):
"""
Called when first loading provider
Expand Down Expand Up @@ -86,6 +90,7 @@ def load(self):
ProviderContextMenuActions.registerProviderContextMenuActions(self.contextMenuActions)
ProcessingConfig.readSettings()
self.refreshAlgorithms()
self.r_version = RUtils.get_r_version()
return True

def unload(self):
Expand Down Expand Up @@ -122,7 +127,10 @@ def versionInfo(self):
"""
Provider plugin version
"""
return "2.2.0"
if not self.r_version:
return "QGIS R Provider version {}".format(self.VERSION)

return "QGIS R Provider version {}, {}".format(self.VERSION, self.r_version)

def id(self):
"""
Expand Down
24 changes: 24 additions & 0 deletions processing_r/processing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,30 @@ def check_r_is_installed() -> Optional[str]:

return html

@staticmethod
def get_r_version() -> Optional[str]:
"""
Returns the current installed R version, or None if R is not found
"""
if RUtils.is_windows() and not RUtils.r_binary_folder():
return None

command = [RUtils.path_to_r_executable(), '--version']
try:
with subprocess.Popen(command,
stdout=subprocess.PIPE,
stdin=subprocess.DEVNULL,
stderr=subprocess.STDOUT,
universal_newlines=True,
**RUtils.get_process_keywords()) as proc:
for line in proc.stdout:
if ('R version' in line) or ('R Under development' in line):
return line
except FileNotFoundError:
pass

return None

@staticmethod
def get_required_packages(code):
"""
Expand Down

0 comments on commit 76ec933

Please sign in to comment.