Skip to content

Commit

Permalink
Merge pull request #2180 from dvbridges/versionFilter
Browse files Browse the repository at this point in the history
BF/ENH: Filters incompatible version of PsychoPy for Experiment Settings
  • Loading branch information
peircej committed Jan 11, 2019
2 parents f74c578 + 3e20eea commit eef1b90
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
4 changes: 2 additions & 2 deletions psychopy/app/builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from ... import experiment
from .. import stdOutRich, dialogs
from ..icons import getAllIcons
from psychopy import logging, constants
from psychopy import logging, constants, __version__
from psychopy.tools.filetools import mergeFolder
from .dialogs import (DlgComponentProperties, DlgExperimentProperties,
DlgCodeComponentProperties)
Expand Down Expand Up @@ -2231,7 +2231,7 @@ def generateScript(self, experimentPath, target="PsychoPy"):
'-o', experimentPath]
# if version is not specified then don't touch useVersion at all
version = self.exp.settings.params['Use version'].val
if version not in [None, 'None', '']:
if version not in [None, 'None', '', __version__]:
cmd.extend(['-v', version])
logging.info(' '.join(cmd))
out = subprocess.check_output(cmd)
Expand Down
4 changes: 2 additions & 2 deletions psychopy/app/builder/dialogs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ def __init__(self, dlg, label, param, parent, fieldName,
# settings. If remote info has become available in the meantime,
# now populate with that as well
if vc._remoteVersionsCache:
options = vc.versionOptions(local=False)
versions = vc.availableVersions(local=False)
options = vc._versionFilter(vc.versionOptions(local=False))
versions = vc._versionFilter(vc.availableVersions(local=False))
param.allowedVals = (options + [''] + versions)
if fieldName in ['text', 'customize_everything', 'customize']:
# for text input we need a bigger (multiline) box
Expand Down
31 changes: 27 additions & 4 deletions psychopy/tools/versionchooser.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import sys
import subprocess # for git commandline invocation
from subprocess import CalledProcessError
import re
import psychopy # for currently loaded version
from psychopy import prefs
from psychopy import logging, tools, web, constants
Expand Down Expand Up @@ -87,8 +86,10 @@ def useVersion(requestedVersion):
_clone(requestedVersion) # Allow the versions subdirectory to be built

if constants.PY3:
py3Compatible = [ver for ver in availableVersions() if not re.search('(0|1).(7|8)', ver)]
py3Compatible.reverse()
py3Compatible = _versionFilter(versionOptions(local=False))
py3Compatible += _versionFilter(availableVersions(local=False))
py3Compatible.sort(reverse=True)

if reqdMajorMinorPatch not in py3Compatible:
msg = _translate("Please request a version of PsychoPy that is compatible with Python 3.\n"
"You can choose from the following versions: {}.\n"
Expand Down Expand Up @@ -149,6 +150,7 @@ def _switchToVersion(requestedVersion):
a site-packages directory, which should *not* be removed as it may
contain other relevant and needed packages.
"""

if not os.path.exists(prefs.paths['userPrefsDir']):
os.mkdir(prefs.paths['userPrefsDir'])
try:
Expand Down Expand Up @@ -225,18 +227,39 @@ def _remoteVersions(forceCheck=False):
return _remoteVersionsCache


def _versionFilter(versions):
"""Returns all versions that are compatible with the Python version running PsychoPy
Parameters
----------
versions: list
All available (valid) selections for the version to be chosen
Returns
-------
list
All valid selections for the version to be chosen that are compatible with Python version used
"""

if constants.PY3:
return [V for V in versions if V == 'latest' or float(V[:3]) >= 1.9]
return versions


def availableVersions(local=True, forceCheck=False):
"""Return all available (valid) selections for the version to be chosen.
Use local=False to obtain those only available via download
(i.e., not yet local but could be).
Everything returned has the form Major.minor.patchLevel, as strings.
"""

if local:
return _localVersions(forceCheck)
else:
return sorted(
list(set(_localVersions(forceCheck) + _remoteVersions(
list(set([psychopy.__version__] + _localVersions(forceCheck) + _remoteVersions(
forceCheck))),
reverse=True)

Expand Down

0 comments on commit eef1b90

Please sign in to comment.