Skip to content

Commit a8df840

Browse files
updating rendered version
1 parent 77357a2 commit a8df840

File tree

6 files changed

+61
-46
lines changed

6 files changed

+61
-46
lines changed

_sources/interfacing_with_c/c_python.rst.txt

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,57 @@
1+
########################
12
Interfacing C and Python
2-
################################
3+
########################
34

4-
Sorry, not much here
5+
Sorry, not much here yet.
56

67
NOTE: this is all about the CPython interpreter -- not PyPy, IronPython, JPython, etc.
78

89
Documentation:
9-
================
10+
==============
1011

1112
Core docs for the C API:
1213

1314

1415

1516

1617
Interfacing methods:
17-
======================
18+
====================
1819

1920
There a bunch of ways to interface C and Python:
2021

2122
Hand write against the C API:
22-
------------------------------
23+
-----------------------------
2324

24-
The python interpeter exposes a full API to all teh pyton objects, etc. You can essentially do anything, but it's a lot of hand-work.
25+
The python interpeter exposes a full API to all the python objects, etc. You can essentially do anything, but it's a lot of hand-work.
2526

2627
And reference counting is really hard to get right!
2728

28-
http://docs.python.org/2/c-api/
29+
http://docs.python.org/3/c-api/
2930

3031
Cython:
31-
------------------
32+
-------
3233

3334
Cython can be described as a "python-like language for writing python extensions"
3435

35-
It can be used essentially to speed up Python, but also to Call Python from C
36+
It can be used essentially to speed up Python, but also to call Python from C.
3637

3738
(derived from Pyrex)
3839

3940
XDress
40-
........
41+
......
4142

4243
ctypes
43-
--------
44+
------
4445

4546

4647
SWIG, SIP, ETC.
47-
----------------
48+
---------------
4849

4950
Auto wrapper generators.
5051

5152

5253
EXAMPLE:
53-
============
54+
========
55+
56+
Same as the one for fortran: a automatic gain control filter.
5457

55-
Same as the one for fortran: a automatic gain control filter.

_sources/interfacing_with_c/fortran_python.rst.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Interfacing Fortran and Python
2-
################################
2+
##############################
33

44
Documentation:
5-
================
5+
==============
66

77
A nice reference for Python for Fortran programmers:
88

@@ -16,7 +16,7 @@ http://fortran90.org/src/best-practices.html
1616
http://fortran90.org/src/best-practices.html#interfacing-with-python
1717

1818
Interfacing methods:
19-
======================
19+
====================
2020

2121
There a a handful of ways to interface Fortran and Python:
2222

@@ -75,7 +75,7 @@ The problem at hand is an automatic gain control function function, expressed in
7575
end
7676

7777
f2py:
78-
-------
78+
-----
7979

8080
f2py is a command line utility that comes with numpy. You can build a default simple wrapper with the f2py command::
8181

@@ -108,7 +108,7 @@ So it can be called like so::
108108
where `signal` and `filtered` are 1-d arrays of float32 values, both of the same length.
109109

110110
Giving f2py extra information:
111-
...............................
111+
..............................
112112

113113
f2py can build an interface to a fortran subroutine, but it can't do it all that well without some extra information. For instnce, note from the docstring that the argument `ampagc` is listed as an input argument, when it is really intended to be used for output.
114114

_sources/where_to_put_your_code.rst.txt

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Where to put your custom code?
33
******************************
44

5+
(You can find this page at: http://bit.ly/JustPackage)
6+
57
A suggestion for how to manage your personal library of python functions you might use for scripting, data analysis, etc.
68

79
TL; DR
@@ -14,16 +16,19 @@ Make a "package" out of it so you can manage it in one place, and use it in othe
1416
Introduction
1517
------------
1618

17-
Many folks find they have a collection of little scripts and utilities that they want to be able to use and re-use for various projects. It is really NOT a good idea to simply copy and paste these around for use with each project -- you will regret that!
19+
Many scientists and engineers that do a little coding find they have a collection of little scripts and utilities that they want to be able to use and re-use for various projects. It is really NOT a good idea to simply copy and paste these around for use with each project -- you will regret that!
1820

1921
It is also not a good idea to use the ``PYTHONPATH`` environment variable to set up a directory in which to dump stuff. (Google a bit if you want to know why).
2022

2123
The best way to do this with Python is to use the Python package mechanism.
2224

23-
A Python "package" is a collection of modules and scripts -- we usually think of these as something carefully developed for particular purpose and distributed to a wide audience for re-use -- the packages you can install with pip.
25+
A Python "package" is a collection of modules and scripts -- we usually think of these as something carefully developed for a particular purpose and distributed to a wide audience for re-use -- the packages you can install with pip.
2426

2527
Indeed that is the case, but the "collection of modules and scripts" part can be used for your own code that no one else is ever going to touch, and the overhead is small if you use it only this way.
2628

29+
The challenge is that most of the documentation about python packaging is focused on creating a package of a library that you want to distribute to the community. In that case, it's very important to have full and proper meta data, tests, documentation, etc. As a result, the packaging documentation makes the whole process seem complicated and cumbersome.
30+
31+
But making a simple package for your own use can be very simple, and very useful.
2732

2833
Step by step:
2934
-------------
@@ -47,7 +52,7 @@ The inner my_code dir is now a python "package" -- any directory with a ``__init
4752

4853
The ``setup.py`` file is where you specify for python how this package is setup. You can do a lot in there, and if you ever want to share your code with anyone else, you should follow:
4954

50-
https://packaging.python.org/tutorials/distributing-packages/.
55+
https://packaging.python.org/tutorials/distributing-packages/
5156

5257
But for now, we are going to make it as *simple* as possible::
5358

@@ -84,15 +89,19 @@ Create a file for your code, and put it in the inner my_code dir:
8489

8590
OK -- now you have a (useless) package with some code in it - how to use it?
8691

87-
To use this package, you need to "install" it into the python environment that you want to use. Some of us have a single python install -- maybe Anaconda's root environment, or the python.org python installer, or ... Some of us use virtualenv, or pipienv, or conda environments. In any case, get yourself into that environment at a command line and put yourself (``cd`` in Terminal, DOS box, etc...) in the outer my_code dir, and type::
92+
To use this package, you need to "install" it into the python environment that you want to use. Some of us have a single python install -- maybe Anaconda's root environment, or the python.org python installer, or ...
93+
94+
Some of us use virtualenv, or pipienv, or conda environments. In any case, get yourself into that environment at a command line and put yourself (``cd`` in Terminal, DOS box, etc...) in the outer my_code dir (where the setup.py is), and type::
8895

8996
pip install -e .
9097

91-
``pip install`` installs a package. ``-e`` means "do an editable install", and the dot (``.``) means, install the package in the current directory. ``pip`` will look for a ``setup.py`` file in the current working dir. And editable install is like install, but instead of copying the code into the python environment, it adds it to the Python search path (only that particular environment's Python) so you can import it, but it will always be importing the current version of the files if you change things.
98+
``pip install`` installs a package. ``-e`` means "do an editable install", and the dot (``.``) tells pip to install the package in the current directory. ``pip`` will look for a ``setup.py`` file in the current working dir. An editable install is like install, but instead of copying the code into the python environment, it adds it to the Python search path (only that particular environment's Python) so you can import it, but it will always be importing the current version of the files if you change things.
99+
100+
This means you can be actively maintaining your shared code, and other projects that use it will always get the latest version.
92101

93-
This means you can be activly maintaining your shared code, and other projects that use it will always get the latest version.
102+
Now you can fire up Python (or iPython, or a Jupyter notebook, or write code in a script, or...) and do:
94103

95-
Now you can fire up Python (or iPython, or a Jupyter notebook, or write code in a script, or...) and do: ::
104+
.. code-block:: ipython
96105
97106
In [2]: from my_code import some_code
98107
@@ -112,13 +121,13 @@ If you have only a little bit of code, you can do all this with a single module,
112121

113122
If you have more than a few modules, it would probably make sense to keep them in separate packages, organized by functionality.
114123

115-
This is only the very simplest way to do it what you really SHOULD do is be more formal about the process:
124+
This is only the very simplest way to do it. What you really SHOULD do is be more formal about the process:
116125
- Do some versioning of the package
117126
- Keep it in source code version control system (like git, etc)
118-
- add tests of your code...
127+
- add tests of your code...
119128

120129
and others...
121130

122-
Look up "Software Carpentry" for many more ideas how better to manage your Software for Science.
131+
Look up "Software Carpentry" for many more ideas about how better to manage your Software for Science.
123132

124133

interfacing_with_c/c_python.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@
158158

159159
<div class="section" id="interfacing-c-and-python">
160160
<h1>Interfacing C and Python<a class="headerlink" href="#interfacing-c-and-python" title="Permalink to this headline"></a></h1>
161-
<p>Sorry, not much here</p>
161+
<p>Sorry, not much here yet.</p>
162162
<p>NOTE: this is all about the CPython interpreter – not PyPy, IronPython, JPython, etc.</p>
163163
<div class="section" id="documentation">
164164
<h2>Documentation:<a class="headerlink" href="#documentation" title="Permalink to this headline"></a></h2>
@@ -169,14 +169,14 @@ <h2>Interfacing methods:<a class="headerlink" href="#interfacing-methods" title=
169169
<p>There a bunch of ways to interface C and Python:</p>
170170
<div class="section" id="hand-write-against-the-c-api">
171171
<h3>Hand write against the C API:<a class="headerlink" href="#hand-write-against-the-c-api" title="Permalink to this headline"></a></h3>
172-
<p>The python interpeter exposes a full API to all teh pyton objects, etc. You can essentially do anything, but it’s a lot of hand-work.</p>
172+
<p>The python interpeter exposes a full API to all the python objects, etc. You can essentially do anything, but it’s a lot of hand-work.</p>
173173
<p>And reference counting is really hard to get right!</p>
174-
<p><a class="reference external" href="http://docs.python.org/2/c-api/">http://docs.python.org/2/c-api/</a></p>
174+
<p><a class="reference external" href="http://docs.python.org/3/c-api/">http://docs.python.org/3/c-api/</a></p>
175175
</div>
176176
<div class="section" id="cython">
177177
<h3>Cython:<a class="headerlink" href="#cython" title="Permalink to this headline"></a></h3>
178178
<p>Cython can be described as a “python-like language for writing python extensions”</p>
179-
<p>It can be used essentially to speed up Python, but also to Call Python from C</p>
179+
<p>It can be used essentially to speed up Python, but also to call Python from C.</p>
180180
<p>(derived from Pyrex)</p>
181181
<div class="section" id="xdress">
182182
<h4>XDress<a class="headerlink" href="#xdress" title="Permalink to this headline"></a></h4>

0 commit comments

Comments
 (0)