-
Notifications
You must be signed in to change notification settings - Fork 4
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
pysndfile is unable to access filenames with non-latin-1 chars on windows #3
Comments
Hello, I would be interested to hear more about how you go about usng pysndfile on windows and I will certainly be happy to make the necessary changes in pysndfile. A few comments: Clearly we need ENABLE_SNDFILE_WINDOWS_PROTOTYPES to be set, this could be a configuration in setup.py setting a compiler macro, but also a condition in pysndfile.hh (pysndfile does not use sndfile.hh directly). You may try adding
directly into pysndfile.hh Further to generate the LPCWSTR in cython I think all is said here https://stackoverflow.com/questions/19650195/cython-convert-unicode-string-to-wchar-array one probably would also do this conditionally for all windows compilers in _pysndfile.pyx Here a mechanism that would help you to have windows specific code in _pysndfile.pyx I have made a proposal of the required changes as a starting point it would probably be better to set
|
I check that - the last point does not work, you would need to do it like this
|
Thanks! With your directions and hints, I have successfully been able to build a running version on Windows. sveinse@85d91cf The only thing I wasn't able to fix was the declaration of the windows variant of the handle in L115. It should read:
However I failed to insert a IF statement among that Also note the change on L690: I believe the PS! As we already have, you're free to use these suggestions freely under your existing copyright license. |
Thanks for the info, that sounds really good. Thanks as well for the suggestion with expanduser that's certainly much better. Concerning the remaining problem, after somewhat more searching I think now that it is not possible to insert an IF in the middle of a cppclass declaration. Sorry, I was too optimistic. It appears the correct way of doing this is adding two include files (.xpi) one for linux and the other for windows I have created a win32 branch with these changes, this could become version 1.3.4, please let me now whether it works for you. It would also interesing to know how you run the setup.py such that it finds your dll. I would add |
You find the experimental support of windows in pysndfile 1.3.4. I cannot test this, so don't hesitate to share your observations. |
Sorry for the delay, its summer vacation time around here. When I check out 1.3.4 from master and build on windows I get the following error message:
I haven't made any investigations into why yet, work in progress. PS! I've created a gist of an extract of the scripts I use for building and bundling pysndfile and libsndfile on Windows. https://gist.github.com/sveinse/97411b95d36a6b8c430d4d381b620ecb -- this is admittedly a cumbersome procedure. For my application, I've chosen to pre-package the binary libsndfile (using pysndfile_library.sh) and make a pysndfile wheel (using pysndfile_build.sh) and collect them into a separate binary repo. This way it is much simpler to reinstall the python venv and install pysndfile from wheel without needing all of the infrastructure of building the library and modules. See pysndfile_install.sh for that. |
Thanks for trying, in fact due to two problems with copy pasting 1.3.4 was completely broken, not only for windows but also for linux. I fixed a problem in the linux code and another problem in the windows part in 1.3.5. This should help for the overload problem you had in your built. In fact I simulated this under linux and had the same problem which is now gone in 1.3.5. I also fixed my test script such that I can check directly the new build which will hopefully prevent thee kind of errors in the future. Thanks for the gist, if you don't mind I would include that into the readme of pysndfile for others to follow. |
Thank you, this seems to work better. At least it does progress a little further, but I am currently running into the pesky unicode/codepage problems. Working on identifying the cause:
|
With regards to the gist, please go ahead. Please note that I have a similar procedure for Linux, albeit somewhat different. Windows always looks for depending libraries in the same dir as the file, so putting the libsndfile.dll next to the pysndfile site-packages dir works fine. On Linux however, the so loader doesn't by default look in the same directory, so for Linux I'm modifying rpath on the pysndfile binary to force it to find the injected libsndfile.so file. |
Ok, the unicode probelm is not a real problem, this is only for generating the LONG description in case the README changed, normally I test the modification time and run this only in case README.md is newer than LONG_DESCR, but it seems the test is not working under windows. |
I updated the repos with a new setup.py that no longer tests file dates but uses some sort of |
With regards to the gist I, will link the stuff from the README. But I don't exactly understand what you want to do with that on linux. Why would you not simply install libsndfile in the system and use that one? |
I update to master, and it still fails on unicode errors. Line 186 in setup.py. My temporary fix is to always use open(..., encoding='utf-8') in all places. I assume it is because the LONG_DESCR file has a utf-8 symbol in it somewhere, and for windows utf-8 isn't standard. py3 is quite pedantic about these things. Despite this, I'm still having problems compiling the c code. I just started debugging why it occurs. My theory is that the c compiler isn't picking up the proper windows overloaded variant of SndFileHandle(). I am going to check if the extra windows define is set like it should. Work in progress. As for the gist: The main reason is that I'd like to have the venv fully self contained. For windows I use pyinstaller to make distributable exe with the whole project, but I don't do that for Linux. I know this is beyond the concepts of what the venv intends to cover, but it still is useful. Very many different distros have very different libraries available, so that is a clutter too. |
The following patch seems to fix the utf-8 issue for me.
PS! Its really great that the module got a setup which is self contained on build dependencies, but having cython and numpy in pyproject.toml required=, makes my build spend 3 minutes just downloading and recompiling them each time the pysndfile is built. It doesn't even care if it is pre-installed in the venv beforehand, as it has to install it in its build environment. But this is how it should be, so I suppose this is just an effect of how slow Windows can be on certain ops. Its not your fault, so not a rant directed at you :D |
I think I found it by looking into the generated _pysndfile.cpp file. cython is apparently including pysndfile.hh before the ENABLE_SNDFILE_WINDOWS_PROTOTYPES is defined, and subsequently the windows function isn't declared properly. I'm not sure how you can let cython place the define before including pysndfile.hh thou...
|
That the LONG_DESCR is not ASCII seems to be a bug in pandoc. I don't think it is a good idea to have UTF8 chars in the RST file, I replace them in the setup now. I also moved the define to the top of the _pysndfile.pyx, I had concentrated all windows stuff in the sndfile_win32.pxi, this was apparently not a good idea. You find all this in the repos. With respect to the compile time due to the dependency handling: I fully agree, I had the same problem when I tried this, however when I tried with preinstalled numpy and cython it did not search for dependencies, that's why I thought this would not be so bad. Which version of pip do you use ? |
I think I have a workable solution. See the below patch for a summary of all changes. My comments to the patch:
Thank you.
|
Yes that's about how I did it, just not moving all the windows stuff to the pyx file, only the define. |
I'm not sure thats enough. The |
Sorry, yes I see, I updated now to have your version. I made a few more checks with the depencies. Indeed pip does not take into account installed versions, but if you use
then it did use the packages I had already installed. |
Great tip, thanks! I've built and tested it, and it works! Thank you. The only remaining blocker on Windows is the fix to
|
Ok, that are old entries that I don't need anymore, I removed those now. |
Everything is working. Closing the issue. I know that windows is not a platform you have access to, and thus it is easy to neglect or ignore. I thank you for the willingness to get this up and running on windows. Thank you! |
I'm having problems opening sound files with non-latin-1 characters in them on Windows:
This fails with:
I've linked pysndfile with the official windows library release of libsndfile.
I think the cause is due to this code: https://github.com/roebel/pysndfile/blob/master/_pysndfile.pyx#L670-L673
which calls https://github.com/erikd/libsndfile/blob/master/src/sndfile.hh#L82 . From what I have figured out, Windows doesn't natively do utf-8, so the existing assumption of using utf-8 is wrong. I think it needs to call the
LPCWSTR wpath
variant on Windows. Correspondingly the defineENABLE_SNDFILE_WINDOWS_PROTOTYPES
must be enabled and figuring out how to generate LPCWSTR strings from a python str object.I am currently working on investigating these issues and hopefully find a solution. I'm not very well-versed in cython or in windows, but I'm hoping that I am able, since I depend on having this fixed. I am aware that @roebel has disclamed not being a Windows user.
The text was updated successfully, but these errors were encountered: