-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Make python bindings article partially work on win #157
Conversation
@Znunu More significantly, the CFFI build is failing on (at least) python3.7. CFFI really doesn't like #ifdef directives. Looking at it, this makes some sense as it can't know what the value of that is until compilation time. :( Does the CFFI portion work on Windows? We might need to think some more about the best way to present this. |
CFFI didn't work for me either. tbh I didn't intend to make that portion portable, but I didn't realize I broke it, so I went ahead and tried anyway. Like you mentioned, it didn't like the directives, so I added some code that filters them out. |
Hello? |
Hey! @Znunu - this got away from me. I'll take a look this weekend. Thanks for the ping! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Znunu
This is getting close! I left a couple of comments and some fixes to get linux back and running.
THANK YOU!!!!
and, again, thanks for the ding on this last week. Been getting behind on things. :)
print_banner("Building C Library") | ||
cmd = "gcc -c -Wall -Werror -fpic cmult.c -I /usr/include/python3.7" | ||
invoke.run(cmd) | ||
invoke.run("gcc -shared -o cmult.so cmult.o") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you really want this to be -o libcmult.so
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh - I see the problem now. I"ll suggest a change in ctypes_test.py to work around this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now reviewing my comments this looks strange - these two were the first comments I made getting things to work. Then I went back and did the full review. :)
c_lib = ctypes.CDLL(libname) | ||
lib_ext = ".dll" if sys.platform.startswith("win") else ".so" | ||
libname = pathlib.Path() / f"cmult{lib_ext}" | ||
c_lib = ctypes.CDLL(libname.resolve().__str__()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Linux and mac users are really gong to expect libcmult.so
. I'd recommend doing this instead of line 9:
if sys.platform.startswith("win"):
libname = "cmult.dll"
else:
libname = "libcmult.so"
and then just using libname
instead of the fstring on line 10.
|
||
|
||
@invoke.task(build_cmult) | ||
@invoke.task() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the build on windows taking significant time? If not, I'd prefer to leave the dependency here. It makes the individual targets a bit more fool-proof.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it doesn't. On windows, the problem is that it'll only build if we supply the argument pointing to visual studio.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahhh. I get it. That's fine. I missed that point.
@@ -1,4 +1,5 @@ | |||
#!/usr/bin/env python3 | |||
# IDE might complain with "no module found" here, even when it exists |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because it doesn't exist when you start out. :) CFFI creates the module when you run the build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but my IDE, PyCharm, didn't want to acknowledge it, even after making it. I actually lost a lot of time figuring out what the problem is, since I didn't even bother to try and run it, lol
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's odd. I wonder what pycharm is doing, but not enough to actually go find out, you know. :)
overview article. | ||
|
||
If anything is causing trouble get in touch at | ||
Znunu @ github or VimVim @ fcZBB2v @ discord""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I appreciate you taking ownership for your work, but I'd propose rephrasing this to:
"Special thanks to Znunu @ github for working through the Windows compatibility issues."
(which, I know, would sound if you said it, but it will sound like it's coming from me when we merge it :) )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not so important for me to be credited. Just wanted to add a quick and easy way for someone to get in touch. Someone might encounter a bug or have a problem, and thus open the file. Maybe I'm doing this the wrong way. I can remove it again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've got a question in with Dan to see what he wants. I'll let you know when he gets back to me (I've set a reminder that if I don't hear from him by Tuesday night, I'll ding him again.)
else: | ||
c.run("rm -rf {}".format(pattern)) | ||
if on_win: | ||
c.run("rmdir /s /q Release >nul 2>&1") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I'm missing something but could we replace those delete/rm commands with something Python-native that works across platforms?
E.g. https://stackoverflow.com/questions/6996603/how-to-delete-a-file-or-folder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doh! Can't believe I missed this. Thanks, @dbader
if on_win: | ||
invoke.run("python cffi_test.py") | ||
else: | ||
invoke.run("python3 cffi_test.py", pty=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be
invoke.run("python cffi_test.py", pty=not on_win)
straight up python
will work on the other systems. I was just being pedantic. :)
Uhhhh.... I hope I'm doing this review thing correctly |
You're doing great on the review! No worries on that front - any shortcomings are from my slow response time. :) |
Never mind that comment. Turns out I checked |
"*.dll", | ||
"*.exp", | ||
"*.lib", | ||
"*.pyx", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha! This is a problem. I missed this one at first. The *.pyx file is actually hand-build and need to NOT be removed.
This causes the invoke build-cython test-cython
sequence to fail.
This is super close! I think fixing the clean target and then getting feedback from Dan on the other comment and we should be done. THANK YOU again for this work! I really appreciate it and I hope you've learned some! Sounds like this is your first time through a PR process? If so, you're doing great! (actually, you're doing great even if it's NOT your first time, but that's be pedantic.) |
No problem, I'm happy to contribute and appreciate your cooperation :) |
This looks good! |
Hey - I heard back from Dan - He wants us to pull the reference to you in the tasks.py and add a shout out to you in the README.md. There ISN'T a readme in this directory (shame on me), so I'll propose this:
Thank you again for the hard work on this! Dan was impressed that we have a PR! |
@Znunu - I went ahead and wrote a README.md for the directory. It might be easier (in terms of git merging etc) if you just add it. Here's the text:
This should be done inside a virtual environment. Once that is installed, you can use the Special thanks to "znunu at github.com" for getting these examples running on a Windows platform!
|
I added the readme. Thanks for writing one! Removed the reference from both tasks.py and readme.md, don't care about being credited. Tried to add Dan's suggestion as well |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Great work on this, @Znunu - I really appreciate you stepping up and helping! |
This PR fixes some of the problems that I brought up in issue 151