Skip to content

Commit

Permalink
Update documentation, switch from nose to pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
cokelaer committed Jan 15, 2017
1 parent 2bf2793 commit 1cef79a
Show file tree
Hide file tree
Showing 20 changed files with 243 additions and 121 deletions.
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ install:
- pip install .
- pip install nose coverage ordereddict
- pip install coveralls
- pip install pytest pytest-cov
# # command to run tests, e.g. python setup.py test
script:
- python setup.py nosetests --with-coverage --cover-package easydev

#pytest -v --durations=10 test/ --cov=easydev --cov-report term-missing
script:
# - python setup.py nosetests --with-coverage --cover-package easydev
- pytest -v --durations=10 test/ --cov=easydev --cov-report term-missing
after_success:
coveralls

5 changes: 5 additions & 0 deletions doc/ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

.. rubric:: 0.9.31:
* mkdirs: when a simple path (no / in the path) was provided, this led to an
error, which is now fixed.
* Remove multigit from setup

.. rubric:: 0.9.30:
* isurl_reachable: add a second optional argument. Default behaviou not
changed but required for some non static URL
Expand Down
6 changes: 3 additions & 3 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
'sphinx.ext.coverage',
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
'sphinx.ext.autosummary',
'sphinx.ext.todo',
'sphinx.ext.ifconfig',
'sphinx.ext.viewcode',
Expand Down Expand Up @@ -247,8 +248,6 @@
# NOT in original quickstart
pngmath_use_preview = True

# The paper size ('letter' or 'a4').
latex_paper_size = 'a4'

# The font size ('10pt', '11pt' or '12pt').
latex_font_size = '10pt'
Expand Down Expand Up @@ -277,7 +276,7 @@
#latex_show_urls = False

# Additional stuff for the LaTeX preamble.
latex_preamble =r"""
latex_elements['preamble'] =r"""
\definecolor{VerbatimColor}{rgb}{.9,1,0.9}
\definecolor{VerbatimBorderColor}{rgb}{0,0,0}
Expand All @@ -303,6 +302,7 @@
"""

latex_elements['paper_size'] = 'a4'
# Documents to append as an appendix to all manuals.
#latex_appendices = []

Expand Down
25 changes: 5 additions & 20 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ Motivation


The package `easydev <http://pypi.python.org/pypi/easydev/>`_ provides
miscellaneous functions and files that are repeatidly used in other Python
packages.
miscellaneous functions and that are often used in other Python packages.
**easydev** should help developers in speeding up their own developments.

Some functions are very simple such as the :func:`~easydev.tools.swapdict`,
which inverts the keys/values in a dictionary (assuming unique keys):
Expand All @@ -41,7 +41,8 @@ which inverts the keys/values in a dictionary (assuming unique keys):
{1: 'a', 2: 'b'}

Other functions such as the progress bar (:mod:`~easydev.progressbar`) are more
complex and **easydev** should be very useful in speeding up development.
complex.

Another example is the :func:`~easydev.tools.AttrDict` function: it makes the keys of a dictionary
accessible as attributes. Meaning that you can get or set the values quickly as
follows:
Expand All @@ -56,26 +57,10 @@ follows:
>>> d.a
10

Another example is the :mod:`~easydev.multicore` module that provides
a simple tool to perform a multi-core analysis in Python. Note, however,
that specialised library would surely cover more aspects. Yet, in a few lines
of code many applications would work out of the box with this code::

from easydev.multicore import MultiProcessing
mp = MultiProcessing(maxcpu=4)
mp.add_job(test_func, 2)
mp.add_job(test_func, 1)
mp.run()


There are many such functions in **easydev** and the best would be to have a
There are many such functions in **easydev** and the best is to have a
look at the :ref:`quickstart` section for more examples and the :ref:`ref_guide` guide for an
exhaustive list of tools available.

There are also a few applications installed with **easydev**. One is the
**browse** application that is equivalent to **open** under Mac. The interest is
that it is multi-platform.

Note also that **easydev** was starting a few years ago and that some
functionalities did not exist back then. Some functionalities available in
easydev may now exist in standard modules of Python.
Expand Down
163 changes: 116 additions & 47 deletions doc/source/quickstart.rst
Original file line number Diff line number Diff line change
@@ -1,19 +1,103 @@
.. _quickstart:

Quick Start
User Guide
###############

There is no quickstart or tutorial in **easydev** since it is a set of
versatile tools. The documentation is the :ref:`ref_guide`.
There is no tutorial *per-se* in **easydev** since it is a set of
versatile and independent functionalities.

However, here are some general tools.
Here below, we describe some of available tools.

.. contents::

Progress bar
==============

Many tasks may take a while to end. If within a loop, a progress bar is usually
quite handy to keep track of the computation. **easydev** provides a Progress bar
that can be used in python, IPython, and IPython notebooks::

from easydev import Progress
p = Progress(1000)
for i in range(0,1000):
# do something.
p.animate(i+1)

Swapping key and value in a dictionary with swapdict
=======================================================

In Python, dictionaries are used everywhere. Sometimes, it is convenient
to swap the keys and values (values become keys and vice-versa).
The :func:`~easydev.tools.swapdict` can be used for that purpose:

.. doctest::

>>> from easydev import swapdict
>>> d = {'a':1, 'b':2}
>>> inv = swapdict(d)
>>> inv
{1: 'a', 2: 'b'}

.. note:: values must be unique

The tools module
======================

In addition to the *swapdict* function, the :mod:`easydev.tools` module has
many more functionalities.

.. autosummary::
:nosignatures:

~easydev.tools.precision
~easydev.tools.check_param_in_list
~easydev.tools.shellcmd
~easydev.tools.execute
~easydev.tools.touch
~easydev.tools.swapdict
~easydev.tools.mkdirs
~easydev.tools.AttrDict
~easydev.tools.DevTools

For :class:`~easydev.tools.DevTools` and :class:`~easydev.tools.AttrDict`,
please see :ref:`devtools` and :ref:`attrdict` sections, respetively.

Check validity of a values
----------------------------

The :func:`~easydev.tools.check_param_in_list` is used to check the validity of a parameter::

>>> mode = "on"
>>> check_param_in_list(mode, ["on", "off"])
True

.. _attrdict:

AttrDict
-------------

This is a very convenient class to expose keys of a dictionary-like object as
attributes:

.. code-block:: python
>>> from easydev import AttrDict
>>> d = AttrDict({'val1':1})
>>> d.val1
1
This works also if you want to set a value::

d.val2 = 2

.. _devtools:

The DevTools class
========================

We will tend to put small utilities within this :class:`easydev.tools.DevTools`.
Little by little, small tools have been added in **easydev**. To make life easier such tools
have been gatherered within a single class called :class:`easydev.tools.DevTools`.

Usually, we can create just an instance and add it in a class as an accessible
set of functionalities. Consider the following example:

Expand Down Expand Up @@ -53,21 +137,22 @@ line 7. You would need to type::
if x >2:
raise ValueError('the value provided is incorrect....')

The DevTools has more functionalities than those presented here and
will be extended little by little.
Timer
=========

Progress bar
==============
Timer populate a list variable with time spent in **with** statements
::

Many tasks may take a while to end and users may want to known the progress.
Here is a simple Progress bar that would work in python and IPython, and IPython
notebooks::
from easydev import Timer
import time
times = []
with Timer(times):
time.sleep(0.1)
with Timer(imes):
time.sleep(0.2)
sum(times)

from easydev import Progress
p = Progress(1000)
for i in range(0,1000):
# do something.
p.animate(i+1)

Profiling
================
Expand All @@ -85,6 +170,20 @@ the do_profile decorator (requires the package line_profiler)::
time.sleep(0.1)
test(1,2)

Data related
==================

You can split a list into chunks using
:func:`~easydev.chunks.split_into_chunks`:

.. doctest::

>>> from easydev import split_into_chunks
>>> data = [1,1,2,2,3,3]
>>> list(split_into_chunks(data, 3))
[[1, 2], [1, 3], [2, 3]]

Note that it is an iterator (hence the list cast).


Sphinx tools
Expand Down Expand Up @@ -164,36 +263,6 @@ Simply create a python file that contains the following code::
mysetup = Multisetup(curdir='.', commands=sys.argv[1:], packages=packages)
mysetup.run()

The tools module
======================

In addition to the DevTools presented above, the :mod:`easydev.tools` module
also provide some other functionalities.


Check validity of a values
----------------------------

The module :mod:`~easydev.tools` provides a few simple functions amongst which,
the :func:`~easydev.tools.checkParam` is used to check the validity of a parameter::

>>> mode = "on"
>>> checkParam(mode, ["on", "off"])
True


AttrDict
-------------

This is a very convenient class to expose keys of a dictionary-like object as
attributes:

.. code-block:: python
>>> from easydev import AttrDict
>>> d = AttrdDict({'val1':1})
>>> d.val1
1


Create a package layout in one command
Expand Down
15 changes: 14 additions & 1 deletion doc/source/references.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ browse
:inherited-members:
:synopsis:

chunks
==========

.. automodule:: easydev.chunks
:members:
:inherited-members:
:synopsis:

codecs
==========
Expand Down Expand Up @@ -142,9 +149,15 @@ sphinx themes
:inherited-members:
:synopsis:

timer
================

.. automodule:: easydev.timer
:members:
:undoc-members:

tools
===================================================================
================

.. automodule:: easydev.tools
:members:
Expand Down
2 changes: 1 addition & 1 deletion easydev/browser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- python -*-
#
# Copyright (c) 2011-2012
# Copyright (c) 2011-2017
#
# File author(s): Thomas Cokelaer <cokelaer@gmail.com>
#
Expand Down
Loading

0 comments on commit 1cef79a

Please sign in to comment.