Skip to content
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

Merged
merged 9 commits into from Jun 16, 2018
Merged

Conversation

gabrieldemarmiesse
Copy link
Contributor

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):

  • The examples have all been put into files and are now in the docs/examples directory. As such, they are all tested (with mode compile).
  • The section Specify C++ language in setup.py have been moved out of the tutorial and have been put at the end of the .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.

Myles1 and others added 8 commits January 13, 2018 18:58
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
Copy link
Contributor

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``
Copy link
Contributor

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`:
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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).

Copy link
Contributor Author

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``.
Copy link
Contributor

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.

@scoder scoder merged commit 9564b99 into cython:master Jun 16, 2018
@gabrieldemarmiesse gabrieldemarmiesse deleted the update_cpp_examples branch June 17, 2018 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants