-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move to Python 3.8 #36
Comments
See sergey-shandar/getboost#43, currently no nuget packet seems to be available for boost python which is correctly build against python 3. Initial test branch created at https://github.com/chcg/PythonScript/tree/python36_test. |
…ckage, due to missing boost python3 nuget package
…ckage, due to missing boost python3 nuget package
…ckage, due to missing boost python3 nuget package
boostorg/python#129 is closed and apparently fixed as of April. That should fix sergey-shandar/getboost#43. Edit: sergey-shandar/getboost#43 is closed now. |
…ckage, due to missing boost python3 nuget package
Ideas on this task from Claudia:
|
…ckage, due to missing boost python3 nuget package
…ckage, due to missing boost python3 nuget package
update to python 3.8.2 - update tp boost 1.71 - fixed some x64 compiler warnings - fix msi build - updated python 3.7.5 lib data - moved extra libs into full python 3.7.5 add unicode filename testfile update to python 3.7.3 update boost to 1.70 update to python 3.7.1 and boost 1.68 initial try of build adaptations for python 3 support, see #36 on blockage, due to missing boost python3 nuget package
update to python 3.8.2 - update tp boost 1.71 - fixed some x64 compiler warnings - fix msi build - updated python 3.7.5 lib data - moved extra libs into full python 3.7.5 add unicode filename testfile update to python 3.7.3 update boost to 1.70 update to python 3.7.1 and boost 1.68 initial try of build adaptations for python 3 support, see #36 on blockage, due to missing boost python3 nuget package
update to python 3.8.2 - update tp boost 1.71 - fixed some x64 compiler warnings - fix msi build - updated python 3.7.5 lib data - moved extra libs into full python 3.7.5 add unicode filename testfile update to python 3.7.3 update boost to 1.70 update to python 3.7.1 and boost 1.68 initial try of build adaptations for python 3 support, see #36 on blockage, due to missing boost python3 nuget package
Great to see that moving to py3 is going to be done. |
Most of the unit tests are already running. I just added the correction to use the python modules provided with the plugin installation. So I think you could already start migrating the scripts. The major drawback I think is just that non UTF-8 files are not working correctly yet as could be seen with still failing https://github.com/bruderstein/PythonScript/blob/master/PythonScript/python_tests/tests/ReplaceAnsiTestCase.py . |
Yes, this is a area which needs to be addressed. What I found is needed is something like this cdef inline _encode(self, unicode text):
return text.encode('mbcs' if self.call(self.sci_pointer, SCI_GETCODEPAGE, 0, 0) == 0 else 'utf-8')
cdef inline unicode _decode(self, char* text):
return text.decode('mbcs' if self.call(self.sci_pointer, SCI_GETCODEPAGE, 0, 0) == 0 else 'utf-8')
cdef inline unicode _decode_const(self, const char* text):
return text.decode('mbcs' if self.call(self.sci_pointer, SCI_GETCODEPAGE, 0, 0) == 0 else 'utf-8')
cdef inline unicode _decode_with_length(self, const char* text, size_t length):
return text[:length].decode('mbcs' if self.call(self.sci_pointer, SCI_GETCODEPAGE, 0, 0) == 0 else 'utf-8') the encode returns a bytestring whereas the decode, obviously, returns unicode. editor.appendText('Hello World') <-- I would suggest using this instead of forcing users to do but that would mean that the appendText call needs to do something like cpdef void appendText(self, unicode text):
''' Append a string to the end of the document without changing the selection. '''
encoded = self._encode(text)
self.call(<sptr_t>self.sci_pointer, SCI_APPENDTEXT, <uptr_t>(len(encoded)), <sptr_t><char*>encoded) Yes, this is a little overhead but using b'' strings doesn't feel natural for python3 developers and of course getText is something like cpdef unicode getText(self):
''' Retrieve all the text in the document. Returns number of characters retrieved. Result is NUL-terminated. '''
buffer_size = self.call(<sptr_t>self.sci_pointer, SCI_GETTEXT, 0, 0)
if buffer_size:
buffer = bytes(buffer_size+1)
self.call(<sptr_t>self.sci_pointer, SCI_GETTEXT, <uptr_t>buffer_size, <sptr_t><char*>buffer)
return self._decode(buffer[:-1])
return '' Unfortunately I don't know if boost::python provides a way to make this work easily. |
I tried the latest build with a fresh npp 7.8.6 and it crashed. The string(unicode/bytestring) conversions seems already to work. Concerning the crash I assume something is missing in lib. I will check this out. |
@Ekopalypse Did you use 3.0.0 or already 3.0.1? 3.0.1 should fix the problem starting with the locally provided python modules from the pythonscript zip file. |
What I've described was done with 3.0.1, sorry for not being clear. |
@chcg - I don't know why but the first time I tested 3.0.1 it didn't work with the package I've downloaded but today with a clean npp and PS setup (the zipped x86 and x64) everything was ok, I mean from setup point of view. By the way, with Python3 there is, although not officially supported by python, a way to use pip, |
@Ekopalypse Good news that 3.0.1 fixed what was expected to be fixed.
|
@chcg Concerning pip, do you see any chance that I can simulate the PluginAdmin workflow? |
@Ekopalypse
More info here: https://npp-user-manual.org/docs/plugins/#plugins-admin |
By the way, your work on this feature request is awesome and very much appreciated. Good job guys |
and https://github.com/notepad-plus-plus/wingup/blob/master/src/winmain.cpp#L957 what happens on a update. So from my understanding the existing dir is moved to backup, replaced by the zip and on success the backup is deleted. This would make pip data disappear on each update, if it is installed in the pythonscript plugin dir. |
So the obvious solution would be to have pip and all installed modules in the plugins\config directory, |
My current state is the following:
whereas it should look like this That means, that all scripts, except of Disable Virtual Space, Enable Virtual Space, GotoLineCol_Barebones, InsertRuler and StartWithLocalPthon, do have the issues that with utf8 enocded files they might run into an offset error Note, the rectangle should include the ending bracket. and with ansi files they throw an UnicodeDecodeError: 'utf-8' codec can't decode byte beside this, the following has been observed. CTags Based Autocompletion Formatter MultiEdit Multiples_SR RegexTester GotoLineCol |
I'm trying to find out what the issue with the HideLines and the Formatter scripts, corrupts the last line to format, are because these errors doesn't seem to be encoding related. |
I assume the problem with HideLines is not within the script but within the getStringFromObject function. From what I understand it returns the raw string, as it is typed, instead of the bytes. |
By changing the code for getStringFromObject to std::string ScintillaWrapper::getStringFromObject(boost::python::object o)
{
std::string raw;
if (PyUnicode_Check(o.ptr()))
{
boost::python::object utf8Text = o.attr("__str__")();
raw = std::string(boost::python::extract<const char *>(utf8Text));
}
else if(PyBytes_Check(o.ptr()))
{
raw.assign(PyBytes_AsString(o.ptr()), PyBytes_Size(o.ptr()));
}
else
{
boost::python::object rawString = o.attr("__str__")();
raw = std::string(boost::python::extract<const char *>(rawString), _len(rawString));
}
return raw;
} HideLines script works as well as adding byte strings But I'm not sure if this is the way to go as this is working around the boost::python lib, isn't it? |
I did a similar change:
for the byte case. The else case is probably not working any more. The issues which I faced with this are happening on reading back data from scintilla and setting the right ANSI encoding. |
If I understand the documentation correctly, using PyBytes_AsString without a length argument breaks HideLines, because the string would only be returned until the first \0 is received. The problem with reading text as in getText, getTextRange ... could be solved by using PyUnicode_FromEncodedObject, I guess. The second argument is the encoding. The question I ask myself is whether this is not already somehow covered in boost::python. By the way, are you trying to solve it for every possible ANSI encoding? I mean, isn't it enough to use ANSI aka what is the current system locale aka what Python calls mbcs? Update: PyUnicode_FromEncodedObject might not be the right choice because if the encoding is set to, lets say, cp1252 then a script would expect a string like |
How can we start using python3x ? These edge cases will not affect me. |
@pete312 |
why need manual unpack?
download msi and right click - install.
it will automatically put files in the correct location, wherever npp
needs them? or is there some catch?
Thanks.
--
Rawat
…On 7/7/2020 7:56 PM, Ekopalypse wrote:
@pete312 <https://github.com/pete312>
download a zip from
https://github.com/bruderstein/PythonScript/releases/tag/v3.0.1.
Depending on your notepad++ configuration you either have to unpack into
%APPDATA%\notepad++ or
into the installation directory of notepad++.
—
|
@vsrawat |
Fixed compilation and object file linkage of test project
…cons add support fluent ui icons
I know I've generally been told that "ANSI/codepages" are the reason that PythonScript 3 has never moved out of Alpha. But there has been nothing on this issue in 4 years, other than a comment in 2023 that this issue was the tracker for PS3. The original list of test failures in ANSI were fixed years ago. So what remains to be solved? What is still holding up the transition from PS3 being alpha to releasing it into Plugins Admin? Is there an actionable and testable list of things that still remain to be fixed/implemented, so that if someone wanted to contribute to that part of the effort, they would know what is needed? (It can be frustrating in the Forum to have to support both PS2 and PS3 for scripts that I publish, because while I already made the transition to PS3 for my own use, the average Forum member will only install whatever's available in PluginsAdmin, so any public scripts have to work for PS2 as well, or average Forum members aren't likely to be able to use them. Every time I have to fix something, like here, because of differences in behavior or features between Python2.7+libraries and Python3.12+libraries, I am reminded yet again of how much I really wish PS3 were in Plugins Admin rather than just alpha.) |
The issue still exists and is not easy to fix, I think. And I can understand your frustration. |
Failing tests are internal ones from The main issue is within
Most likely to overcome that problem the code needs a switch to internally handle the text as byte buffer again and not as python 3 does as utf8 stream. |
Questions:
|
|
As far as I understand, even with the latest Python version it is not possible to host multiple runtimes in one process |
Was I or anyone else suggesting this? |
If there will be two versions in the PluginAdmin, there will be people who install both and then ... |
Well, appropriate warnings should be added to description in PluginAdmin... And really, maybe a deprecation warning for PS2 (I believe it is behind in new features and functions anyway). |
What I have in mind is replacing PythonScript(2) in PluginAdmin with PythonScript(3), so it appears as update and the old PS(2) installation is replaced and there should be no issue with a parallel installation of both variants. |
Python 2.7 is about to become obsolete. Could the scripting host be upgraded?
The text was updated successfully, but these errors were encountered: