Skip to content

Commit f234a24

Browse files
cleaned it up a bit
1 parent e5cc381 commit f234a24

File tree

4 files changed

+51
-35
lines changed

4 files changed

+51
-35
lines changed

Sources/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434
'sphinx.ext.intersphinx',
3535
'sphinx.ext.todo',
3636
'sphinx.ext.coverage',
37-
'sphinx.ext.pngmath',
37+
'sphinx.ext.imgmath',
3838
'sphinx.ext.ifconfig',
3939
'IPython.sphinxext.ipython_console_highlighting',
40-
'IPython.sphinxext.ipython_directive',
40+
# 'IPython.sphinxext.ipython_directive',
4141
]
4242

4343
# Add any paths that contain templates here, relative to this directory.

Sources/source/interfacing_with_c/c_python.rst

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/source/interfacing_with_c/fortran_python.rst

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/source/where_to_put_your_code.rst

Lines changed: 28 additions & 14 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,13 +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

21-
The best way to do this with Python is to use the python package mechanism.
23+
The best way to do this with Python is to use the Python package mechanism.
24+
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.
26+
27+
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.
28+
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.
2230

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. 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.
31+
But making a simple package for your own use can be very simple, and very useful.
2432

2533
Step by step:
2634
-------------
@@ -33,18 +41,18 @@ Step by step:
3341

3442
4) In the outer dir, put in a file (we'll fill it in later) called ``setup.py``.
3543

36-
So you shoudl have::
44+
So you should have::
3745

3846
my_code
3947
my_code
4048
__init__.py
4149
setup.py
4250

43-
The inner my_code dir is now a python "package" -- any directory with a __init__.py file is a package. But how to use it?
51+
The inner my_code dir is now a python "package" -- any directory with a ``__init__.py`` file is a package. But how to use it?
4452

45-
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:
53+
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:
4654

47-
https://packaging.python.org/tutorials/distributing-packages/.
55+
https://packaging.python.org/tutorials/distributing-packages/
4856

4957
But for now, we are going to make it as *simple* as possible::
5058

@@ -56,6 +64,7 @@ But for now, we are going to make it as *simple* as possible::
5664

5765
That's it -- really! There is a lot you can do here to support multiple packages, scripts, etc, but this is enough to get you started.
5866

67+
5968
Putting in your code
6069
--------------------
6170

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

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

83-
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 conda environments. In any case, get yourself into that environment with a command line 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::
95+
96+
pip install -e .
8497

85-
python setup.py develop
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.
8699

87-
"develop" is like install, but instead of copying the code into the python environment, it adds it to the python search path (only that particular python instances search path!) so you can import it, but it will always be importing the current version of the files if you change things.
100+
This means you can be actively maintaining your shared code, and other projects that use it will always get the latest version.
88101

89-
Now you can fire up python (or ipython, or a Jupyter notebook, or write code in a script, or...) and do::
102+
Now you can fire up Python (or iPython, or a Jupyter notebook, or write code in a script, or...) and do:
90103

91-
from my_code import some_code
104+
.. code-block:: ipython
92105
93106
In [2]: from my_code import some_code
94107
@@ -108,12 +121,13 @@ If you have only a little bit of code, you can do all this with a single module,
108121

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

111-
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:
112125
- Do some versioning of the package
113126
- Keep it in source code version control system (like git, etc)
127+
- add tests of your code...
114128

115129
and others...
116130

117-
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.
118132

119133

0 commit comments

Comments
 (0)