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
Update cpp examples #2324
Update cpp examples #2324
Conversation
Fixed some typos and grammar stuff. Added a comment to help c++ newcomers on the Rectangle heap allocation.
Add a section for building the extension, and running a test import
Fix spelling error in rect.pyx Remove rect.cpp from the commit. Should not have been added.
… section "specifying the language in the setup.py" outside the tutorial to make the tutorial simpler.
the initial memory allocation raises an exception due to a failure, this | ||
will let Cython safely raise an appropriate Python exception instead | ||
(see below). Without this declaration, C++ exceptions originating from | ||
(see below). Without this declaration, C++ exceptions originating from |
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 personally find double spaces between sentences helpful as they provide a clearer separation. Also, at least Emacs can make use of them for jumping from sentence to sentence. I'm not suggesting to blindly add them everywhere, but I also don't see a reason to change them to single spaces when they are there already.
|
||
.. literalinclude:: ../../examples/userguide/wrapping_CPlusPlus/setup.py | ||
|
||
Run ``$python setup.py build_ext --inplace`` |
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.
Should be $ python
(to suggest a shell command) and not $python
(which suggests a shell variable).
|
||
Run ``$python setup.py build_ext --inplace`` | ||
|
||
Create :file:`test_import.py`: |
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.
First thing that popped up in my mind when I read this line was "why?". The previous paragraph says "it is necessary to have a file ...", so is it also necessary now to have a test_import.py
file? Probably not. ;)
|
||
Cython will generate and compile the :file:`rect.cpp` file (from | ||
:file:`rect.pyx`), then it will compile :file:`Rectangle.cpp` | ||
(implementation of the ``Rectangle`` class) and link both objects files |
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.
"object files"
:file:`Rectangle.cpp` code file:: | ||
|
||
# distutils: language = c++ | ||
# distutils: sources = Rectangle.cpp |
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 it's worth repeating here that the file path is relative to the working directory of the distutils run (which is usually the project root where the setup.py
resides).
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 added a note below.
|
||
You can now test your wrapper with ``$python test_import.py``. |
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.
Ah, yes, that is much better.
This PR is an update of the PR #2070 . Thanks @Myles1 for this it!
This PR necessitate the other PR Enable tests for all the files in the example directory #2296 to be merged into master before.
Changes on the last commit (modification done after #2070):
docs/examples
directory. As such, they are all tested (with modecompile
)..rst
file. This was motivated by the fact that this section wasn't necessary to follow the tutorial, and allow us to make a tutorial that is short and to the point. The reader still have access to the section by going further down.