internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: psychopy/psychopy

Issue:
iohub.server.sendResponse: Incorrect MAX_PACKET_SIZE
We are working on [integrating Pupil Core into PsychoPy's ioHub](https://github.com/pupil-labs/psychopy/tree/pupil-labs-pupil-core-eye-tracker) but are currently receiving a series of similar error messages:
```py
=============================
Error trying to send data to experiment process:
max_pkt_sz: 32748
reply_data_sz: 29407
pkt_cnt: -1
packet index, byte index: -1-1
Traceback (most recent call last):
  File "/Users/papr/work/tmp/psychopy/psychopy/iohub/server.py", line 370, in sendResponse
    self.socket.sendto(reply_data, address)
  File "/Users/papr/.pyenv/versions/3.6.10/envs/psychopy/lib/python3.6/site-packages/gevent/_socketcommon.py", line 703, in sendto
    return self._sock.sendto(*args)
OSError: [Errno 40] Message too long
=============================
```
As you can see `max_pkt_sz >= reply_data_sz`, but `reply_data_sz` is still too large for a single-message transfer. Therefore, I am assuming that [`max_pkt_sz` is calculated incorrectly](https://github.com/pupil-labs/psychopy/blob/bac0f417c1ce37b53cd5afe65d84aee77aab8de1/psychopy/iohub/server.py#L354).

Issue reproduced on
- macOS 11.4 Big Sur, Python 3.9
- macOS 10.15.7 Catalina, Python 3.6


Discussion:

Resolving patch:
diff --git a/psychopy/iohub/net.py b/psychopy/iohub/net.py
--- a/psychopy/iohub/net.py
+++ b/psychopy/iohub/net.py
@@ -21,7 +21,10 @@
 from .errors import print2err, printExceptionDetailsToStdErr
 from .util import NumPyRingBuffer as RingBuffer
 
-MAX_PACKET_SIZE = 64 * 1024
+if Computer.platform == 'win32':
+    MAX_PACKET_SIZE = 64 * 1024
+else:
+    MAX_PACKET_SIZE = 16 * 1024
 
 class SocketConnection(object): # pylint: disable=too-many-instance-attributes
     def __init__(
diff --git a/psychopy/iohub/server.py b/psychopy/iohub/server.py
--- a/psychopy/iohub/server.py
+++ b/psychopy/iohub/server.py
@@ -34,8 +34,6 @@
 from .devices.deviceConfigValidation import validateDeviceConfiguration
 getTime = Computer.getTime
 
-MAX_PACKET_SIZE = 64 * 1024
-
 # pylint: disable=protected-access
 # pylint: disable=broad-except
 
@@ -361,9 +359,12 @@ def sendResponse(self, data, address):
                 pkt_cnt = int(reply_data_sz // max_pkt_sz) + 1
                 mpr_payload = ('IOHUB_MULTIPACKET_RESPONSE', pkt_cnt)
                 self.sendResponse(mpr_payload, address)
+                gevent.sleep(0.0001)
                 for p in xrange(pkt_cnt - 1):
                     si = p*max_pkt_sz
                     self.socket.sendto(reply_data[si:si+max_pkt_sz], address)
+                    # macOS hangs if we do not sleep gevent between each msg packet
+                    gevent.sleep(0.0001)
                 si = (p+1)*max_pkt_sz
                 self.socket.sendto(reply_data[si:reply_data_sz], address)
             else:


Test patch:
Repository: psychopy/psychopy

Issue:
Moving folder of already synced Pavlovia project breaks on next sync
On first sync, the local path of the project is stored - when you move the whole folder to a new location, this local path isn't updated. Possible solution is to update local path on save/sync if it's different than is stored.


Discussion:
I think there are a few of these sort of issues where once the project is created we assume it's there still with no `try...except` to catch the error if it's moved

Resolving patch:
diff --git a/psychopy/app/pavlovia_ui/project.py b/psychopy/app/pavlovia_ui/project.py
--- a/psychopy/app/pavlovia_ui/project.py
+++ b/psychopy/app/pavlovia_ui/project.py
@@ -8,6 +8,7 @@
 import time
 import os
 import traceback
+from pathlib import Path
 
 from .functions import (setLocalPath, showCommitDialog, logInPavlovia,
                         noGitWarning)
@@ -423,10 +424,15 @@ def syncProject(parent, project=None, closeFrameWhenDone=False):
     isCoder = hasattr(parent, 'currentDoc')
 
     # Test and reject sync from invalid folders
+    if project:
+        expectedPath = Path(project.localRoot)
+    else:
+        expectedPath = None
+
     if isCoder:
-        currentPath = os.path.dirname(parent.currentDoc.filename)
+        currentPath = Path(parent.currentDoc.filename).parent
     else:
-        currentPath = os.path.dirname(parent.filename)
+        currentPath = Path(parent.filename).parent
 
     currentPath = os.path.normcase(os.path.expanduser(currentPath))
     invalidFolders = [os.path.normcase(os.path.expanduser('~/Desktop')),
@@ -440,6 +446,11 @@ def syncProject(parent, project=None, closeFrameWhenDone=False):
                       "Project Sync Error",
                       wx.ICON_QUESTION | wx.OK)
         return -1
+    # If paths don't match, update project path to local
+    if expectedPath:
+        if not currentPath == expectedPath:
+            project.localRoot = str(currentPath)
+
 
     if not project and "BuilderFrame" in repr(parent):
         # try getting one from the frame


Test patch:
Repository: psychopy/psychopy

Issue:
Keyword argument `colorSpace` is not a supported parameter name of `Color.__init__`
These [LGTM.com errors](https://lgtm.com/projects/g/psychopy/psychopy/alerts/?severity=error) originate here:
https://github.com/psychopy/psychopy/blob/5711431f37b0dc1b0449d7e7e975fa73911f9782/psychopy/visual/radial.py#L122-L124
https://github.com/psychopy/psychopy/blob/5711431f37b0dc1b0449d7e7e975fa73911f9782/psychopy/visual/radial.py#L126-L128
https://github.com/psychopy/psychopy/blob/5711431f37b0dc1b0449d7e7e975fa73911f9782/psychopy/visual/radial.py#L130-L132

And indeed `Color.__init__` does not have a `colorSpace` keyword argument, only `space`:
https://github.com/psychopy/psychopy/blob/5711431f37b0dc1b0449d7e7e975fa73911f9782/psychopy/colors.py#L234-L239



Discussion:

Resolving patch:
diff --git a/psychopy/visual/radial.py b/psychopy/visual/radial.py
--- a/psychopy/visual/radial.py
+++ b/psychopy/visual/radial.py
@@ -120,16 +120,16 @@ def __init__(self,
         self.colorSpace = colorSpace
         if rgb != None:
             logging.warning("Use of rgb arguments to stimuli are deprecated."
-                            " Please use color and colorSpace args instead")
-            self.color = Color(rgb, colorSpace='rgb')
+                            " Please use color and colorSpace args instead.")
+            self.color = Color(rgb, space='rgb')
         elif dkl != None:
-            logging.warning("Use of dkl arguments to stimuli are deprecated. "
-                            "Please use color and colorSpace args instead")
-            self.color = Color(dkl, colorSpace='dkl')
+            logging.warning("Use of dkl arguments to stimuli are deprecated."
+                            " Please use color and colorSpace args instead.")
+            self.color = Color(dkl, space='dkl')
         elif lms != None:
             logging.warning("Use of lms arguments to stimuli are deprecated."
-                            " Please use color and colorSpace args instead")
-            self.color = Color(lms, colorSpace='lms')
+                            " Please use color and colorSpace args instead.")
+            self.color = Color(lms, space='lms')
         else:
             self.color = color
 


Test patch:
Repository: psychopy/psychopy

Issue:
Transpiler: True in expInfo not translated to true in JS
If the user uses "True" in the expInfo to generate a checkbox in the startup that produced an error online because `True` is not translated to `true` in Javascript. 


Discussion:

Resolving patch:
diff --git a/psychopy/experiment/components/settings/__init__.py b/psychopy/experiment/components/settings/__init__.py
--- a/psychopy/experiment/components/settings/__init__.py
+++ b/psychopy/experiment/components/settings/__init__.py
@@ -545,7 +545,7 @@ def getInfo(self):
                                         "as a list of values."
                                         .format(val))
                 elif val in ['True', 'False']:
-                    infoDict[key] = ast.literal_eval(val)
+                    infoDict[key] = Param(val=val, valType='bool')
 
         except (ValueError, SyntaxError):
             """under Python3 {'participant':'', 'session':02} raises an error because 
@@ -799,10 +799,16 @@ def writeInitCodeJS(self, buff, version, localDateTime, modular=True):
                     "\n").format(version=useVer)
             buff.writeIndentedLines(code)
 
+        # Convert each item to str
+        expInfoStr = "{"
+        for key, value in self.getInfo().items():
+            expInfoStr += f"'{key}': {value}, "
+        expInfoStr = expInfoStr[:-2] + "}"
+
         code = ("\n// store info about the experiment session:\n"
                 "let expName = '%s';  // from the Builder filename that created this script\n"
                 "let expInfo = %s;\n"
-                "\n" % (jsFilename, self.getInfo()))
+                "\n" % (jsFilename, expInfoStr))
         buff.writeIndentedLines(code)
 
     def writeExpSetupCodeJS(self, buff, version):


Test patch:
Repository: psychopy/psychopy

Issue:
Keyword argument `keepMatrix` is not a supported parameter name of method `ImageStim.draw`
This [LGTM.com error](https://lgtm.com/projects/g/psychopy/psychopy/alerts/?severity=error) originates here:
https://github.com/psychopy/psychopy/blob/5711431f37b0dc1b0449d7e7e975fa73911f9782/psychopy/visual/aperture.py#L171-L172

And indeed `self._shape` can either be an [`ImageStim`](https://github.com/psychopy/psychopy/blob/release/psychopy/visual/image.py) or a [`BaseShapeStim`](https://github.com/psychopy/psychopy/blob/release/psychopy/visual/shape.py):
https://github.com/psychopy/psychopy/blob/5711431f37b0dc1b0449d7e7e975fa73911f9782/psychopy/visual/aperture.py#L121-L128

While `BaseShapeStim.draw` does have a `keepMatrix` keyword argument:
https://github.com/psychopy/psychopy/blob/5711431f37b0dc1b0449d7e7e975fa73911f9782/psychopy/visual/shape.py#L297
`ImageStim.draw` does not:
https://github.com/psychopy/psychopy/blob/5711431f37b0dc1b0449d7e7e975fa73911f9782/psychopy/visual/image.py#L243


Discussion:
What happens is that `Aperture` methods check `self.__dict__['filename']` to decide whether `self._shape` is an `ImageStim` or a `BaseShapeStim`. LGTM.com doesn't know it's the same - and future maintainers won't know that either.

The initial branching is OK:
https://github.com/psychopy/psychopy/blob/5711431f37b0dc1b0449d7e7e975fa73911f9782/psychopy/visual/aperture.py#L121-L128

Perhaps further branching should check the type of `self._shape` instead of `self.__dict__['filename']` as is the case now:
https://github.com/psychopy/psychopy/blob/5711431f37b0dc1b0449d7e7e975fa73911f9782/psychopy/visual/aperture.py#L165-L172

Resolving patch:
diff --git a/psychopy/visual/aperture.py b/psychopy/visual/aperture.py
--- a/psychopy/visual/aperture.py
+++ b/psychopy/visual/aperture.py
@@ -164,7 +164,7 @@ def _reset(self):
             GL.glStencilFunc(GL.GL_NEVER, 0, 0)
             GL.glStencilOp(GL.GL_INCR, GL.GL_INCR, GL.GL_INCR)
 
-            if self.__dict__['filename']:
+            if isinstance(self._shape, ImageStim):
                 GL.glEnable(GL.GL_ALPHA_TEST)
                 GL.glAlphaFunc(GL.GL_GREATER, 0)
                 self._shape.draw()


Test patch:
Repository: psychopy/psychopy

Issue:
Pavlovia online experiment only recording final audio trial
It looks like the boilerplate might need tweaking to better support multiple audio clips, [forum thread &rarr;](https://discourse.psychopy.org/t/26265)


Discussion:

Resolving patch:
diff --git a/psychopy/experiment/components/microphone/__init__.py b/psychopy/experiment/components/microphone/__init__.py
--- a/psychopy/experiment/components/microphone/__init__.py
+++ b/psychopy/experiment/components/microphone/__init__.py
@@ -422,7 +422,7 @@ def writeRoutineEndCodeJS(self, buff):
         buff.writeIndentedLines(code % inits)
         buff.setIndentLevel(1, relative=True)
         code = (
-                "tag: %(filename)s,\n"
+                "tag: %(filename)s + Date.now(),\n"
                 "flush: false\n"
         )
         buff.writeIndentedLines(code % inits)


Test patch:
Repository: psychopy/psychopy

Issue:
404 errors on some of the page in the HELP menus
Version used
- psychopy: 2021.2.3

https://www.psychopy.org/builder/builder.html
https://www.psychopy.org/api/api.html


Discussion:

Resolving patch:
diff --git a/psychopy/app/urls.py b/psychopy/app/urls.py
--- a/psychopy/app/urls.py
+++ b/psychopy/app/urls.py
@@ -6,7 +6,7 @@
 urls = dict()
 
 # links based on string names
-urls['builder'] = "https://www.psychopy.org/builder/builder.html"
+urls['builder'] = "https://www.psychopy.org/builder"
 urls['builder.loops'] = "https://www.psychopy.org/builder/flow.html#loops"
 # NB. builder components get their urls defined by the component code
 # (so a custom component can have a url)
@@ -24,7 +24,7 @@
 
 # links keyed by wxIDs (e.g. menu item IDs)
 urls['psychopyHome'] = "https://www.psychopy.org/"
-urls['psychopyReference'] = "https://www.psychopy.org/api/api.html"
+urls['psychopyReference'] = "https://www.psychopy.org/api"
 urls['coderTutorial'] = "https://www.psychopy.org/coder/tutorial1.html"
 urls['builderHelp'] = urls['builder']
 urls['builderDemos'] = "http://code.google.com/p/psychopy/downloads/list?can=2&q=demos"


Test patch:
Repository: psychopy/psychopy

Issue:
Publishing before saving only pushes changes to .js, not .psyexp nor .py
If after making changes through Builder one clicks "Sync with the web project" without also clicking "Save current experiment file", a commit will be pushed with changes to the `.js` files only.

It appears that in order for a commit to reflect the same changes on the three files (`.psyexp`, `.py`, and `.js`), one would have to take three distinct actions (respectively: save, render to python, and render to js - the last one interchangeable with publishing to Pavlovia).

I believe it is desirable that those three files are kept as much in sync as possible, and that the button that syncs to Pavlovia (ie. GitLab) should trigger Save, and perhaps also rendering a new Python file.

PsychoPy v2021.2.0
Windows10



Discussion:

Resolving patch:
diff --git a/psychopy/app/builder/builder.py b/psychopy/app/builder/builder.py
--- a/psychopy/app/builder/builder.py
+++ b/psychopy/app/builder/builder.py
@@ -1365,6 +1365,7 @@ def _getExportPref(self, pref):
             return True
 
     def onPavloviaSync(self, evt=None):
+        self.fileSave(self.filename)
         if self._getExportPref('on sync'):
             htmlPath = self._getHtmlPath(self.filename)
             if htmlPath:


Test patch:
Repository: psychopy/psychopy

Issue:
Dollar sign turns code into text
#https://discourse.psychopy.org/t/bug-dollar-sign-turns-code-into-text/24659

In PsychoPy 2021.2.3 (using Javascript):

The dollar sign ($) as code indicator in any TextBox’s Text property appears to be foiled by another dollar sign.

So this works: `$Math.E+'%'` generates `2.72%` as expected.
But this does not: `$Math.E+'$'` generates `Math.E+'$'` instead of `2.72$`.
This also behaves strangely: `$Math.E+'\$'` generates `2.72\$` instead of `2.72$`.

![Screenshot from 2021-08-23 18-43-01](https://user-images.githubusercontent.com/62275680/131434794-5212ebfb-5bb8-4e63-9908-11809daf5f45.png)



Discussion:
I think the correct solution to this should be to use `$Math.E+'\$'` - the reason this doesn't work is a fix we put in for file paths which replaces all `\` with `/`. The changes in #4229 should fix this, so I'll make a point of testing this out again once that's pulled in!

Resolving patch:
diff --git a/psychopy/experiment/params.py b/psychopy/experiment/params.py
--- a/psychopy/experiment/params.py
+++ b/psychopy/experiment/params.py
@@ -345,8 +345,8 @@ def dollarSyntax(self):
                 if len(re.findall(r"\$", val)) == len(re.findall(r"\$", inComment)):
                     # Return if all $ are commented out
                     return True, val
-                if len(re.findall(r"\$", val)) - len(re.findall(r"\$", inComment)) == len(re.findall(r"\\\$", inQuotes)):
-                    # Return if all non-commended $ are in strings and escaped
+                if len(re.findall(r"\$", val)) - len(re.findall(r"\$", inComment)) == len(re.findall(r"\$", inQuotes)):
+                    # Return if all non-commended $ are in strings
                     return True, val
             else:
                 # If value does not begin with an unescaped $, treat it as a string


Test patch:
Repository: psychopy/psychopy

Issue:
DotStim no longer animates dynamically
The DotStim last worked in version 2021.1.4. Since then, the initial frame of the stimulus will display but the dots are static and do not update dynamically.

Steps to reproduce: run the `dots.py` demo from within Coder. The dots do not animate. 

A work-around for the issue is placing this at the top of the script:

    import psychopy
    psychopy.useVersion('2021.1.4')


Discussion:

Resolving patch:
diff --git a/psychopy/visual/dot.py b/psychopy/visual/dot.py
--- a/psychopy/visual/dot.py
+++ b/psychopy/visual/dot.py
@@ -575,7 +575,7 @@ def _newDotsXY(self, nDots):
 
     def refreshDots(self):
         """Callable user function to choose a new set of dots."""
-        self._verticesBase = self._dotsXY = self._newDotsXY(self.nDots)
+        self.vertices = self._verticesBase = self._dotsXY = self._newDotsXY(self.nDots)
 
         # Don't allocate another array if the new number of dots is equal to
         # the last.
@@ -660,5 +660,7 @@ def _update_dotsXY(self):
         if nOutOfBounds:
             self._verticesBase[outofbounds, :] = self._newDotsXY(nOutOfBounds)
 
+        self.vertices = self._verticesBase
+
         # update the pixel XY coordinates in pixels (using _BaseVisual class)
         self._updateVertices()


Test patch:
diff --git a/psychopy/tests/test_visual/test_dots.py b/psychopy/tests/test_visual/test_dots.py
new file mode 100644
--- /dev/null
+++ b/psychopy/tests/test_visual/test_dots.py
@@ -0,0 +1,37 @@
+import numpy as np
+from psychopy import visual
+
+
+class TestDots:
+
+    @classmethod
+    def setup(self):
+        self.win = visual.Window([128, 128], pos=[50,50], allowGUI=False, autoLog=False)
+
+    def test_movement(self):
+        # Window needs to be black so that adding 2 screens doesn't make a white screen
+        self.win.color = "black"
+        self.win.flip()
+        # Create dots
+        obj = visual.DotStim(
+            self.win, nDots=1,
+            fieldPos=(0, 0), fieldSize=(1, 1), units="height",
+            dotSize=(32, 32), dotLife=0, noiseDots='direction',
+            dir=0, speed=0.25, coherence=1
+        )
+        # Draw dots
+        obj.draw()
+        # Get screenshot 1
+        screen1 = np.array(self.win._getFrame(buffer="back"))
+        self.win.flip()
+        # Draw again, triggering position update
+        obj.draw()
+        # Get screenshot 2
+        screen2 = np.array(self.win._getFrame(buffer="back"))
+        self.win.flip()
+        # Create compound screenshot with a dot in BOTH positions
+        compound = np.clip(screen1 + screen2, 0, 255)
+        # If dots have moved, then there should be more white on the compound screen than on either original
+        assert compound.mean() > screen1.mean() and compound.mean() > screen2.mean(), (
+            "Dot stimulus does not appear to have moved across two frames."
+        )
\ No newline at end of file
Repository: psychopy/psychopy

Issue:
visual.ShapeStim ctypes.ArgumentError
I got this error when I set the autoDraw to True for a visual.shapeStim stimulus:
  
File "C:\Computer Science\Educ 464\Experiments\hollow_dots\hollow_dots_lastrun.py", line 446, in <module>
    win.flip()
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\window.py", line 1082, in flip
    thisStim.draw()
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\shape.py", line 609, in draw
    GL.glLineWidth(self.lineWidth)
ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type

This is the (abridged) code:
**Begin Routine:**
reference_dot_xs = np.random.randint(-150, -10, num_reference_dots)
reference_dot_ys = np.random.randint(-70, 70, num_reference_dots)
reference_dot_xys = np.stack((reference_dot_xs, reference_dot_xs), axis=-1)

reference_dot_stim = visual.ShapeStim(
    win=win, 
    units="pix",
    colorSpace="rgb",
    lineWidth="5",
    lineColor="black",
    fillColor="black",
    vertices=reference_dot_xys,
    size=5,
    autoDraw=False
)

**Each Frame:**
frame += 1
if frame == 29:
    target_dot_stim.autoDraw = True
    reference_dot_stim.autoDraw = True
elif frame == 41:
    target_dot_stim.autoDraw = False
    reference_dot_stim.autoDraw = False



Discussion:
The problem is that you've supplied `"5"` as the lineWidth rather than `5`; this is something the class could handle so I'll add in a quick conversion so in future it knows that `"5"` just means 5, but in the meantime removing the quotes should fix your code :)

Resolving patch:
diff --git a/psychopy/visual/shape.py b/psychopy/visual/shape.py
--- a/psychopy/visual/shape.py
+++ b/psychopy/visual/shape.py
@@ -193,7 +193,11 @@ def lineWidth(self, value):
 
         :ref:`Operations <attrib-operations>` supported.
         """
-        if isinstance(self, psychopy.visual.Line) and isinstance(value, (int, float)):
+        # Enforce float
+        if not isinstance(value, (float, int)):
+            value = float(value)
+
+        if isinstance(self, psychopy.visual.Line):
             if value > 127:
                 logging.warning("lineWidth is greater than max width supported by OpenGL. For lines thicker than 127px, please use a filled Rect instead.")
         self.__dict__['lineWidth'] = value


Test patch: