Skip to content

Commit

Permalink
Updating documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
cdgriffith committed Apr 21, 2014
1 parent 381e178 commit 69cbc20
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 44 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ clean:
$(PYTHON2) setup.py clean;
rm -rf *.egg-info;
rm -rf *.egg;
rm -rf cover;
rm -rf build;
rm -rf dist;

Expand Down
6 changes: 3 additions & 3 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

root = os.path.abspath(os.path.dirname(__file__))

sys.path.insert(0, os.path.abspath(os.path.join(root, '../..')))
sys.path.insert(0, os.path.abspath(os.path.join(root, '../../reusables')))

# -- General configuration ------------------------------------------------

Expand Down Expand Up @@ -58,9 +58,9 @@
# built documents.
#
# The short X.Y version.
version = '0.1.3'
version = '0.1.4'
# The full version, including alpha/beta/rc tags.
release = '0.1.3'
release = '0.1.4'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
73 changes: 43 additions & 30 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ As well as other fun and useful features.


Examples
~~~~~~~~
--------

.. code:: python
Expand All @@ -31,40 +31,59 @@ Examples
reusables.config_dict('my_config.cfg')
# {'Section 1': {'key 1': 'value 1', 'key2': 'Value2'}, 'Section 2': {}}
reusables.safe_path('/home/user/eViL User\0\\/newdir$^&*/new^%file.txt')
# '/home/user/eViL User__/newdir____/new__file.txt'
reusables.find_all_files(".", ext=reusables.exts.pictures)
# ['/home/user/background.jpg', '/home/user/private.png']
###
### DateTime Class - Adds easy formatting to datetime objects
###
reusables.DateTime().format("It's already {month-fullname} but it doesn't feel like {year-fullname} to me yet")
# "It's already April but it doesn't feel like 2014 to me yet"
DateTime Class
~~~~~~~~~~~~~~

Adds easy formatting to datetime objects. It also adds auto parsing for ISO formatted time.

current_time = reusables.DateTime.now() # same as datetime.datetime.now(), returned as DateTime object
.. code:: python
current_time.format("Wake up {son}, it's {hours}:{minutes} {period}! I don't care if it's a {day-fullname}, {command}!",
son="John",
command="Get out of bed!")
# "Wake up John, it's 09:51 AM! I don't care if it's a Saturday, Get out of bed!!"
current_time = reusables.DateTime() # same as datetime.datetime.now(), returned as DateTime object
###
### Namespace Class - Making dicts into easy to reference objects
###
current_time.format("Wake up {son}, it's {hours}:{minutes} {period}! I don't care if it's a {day-fullname}, {command}!",
son="John",
command="Get out of bed!")
# "Wake up John, it's 09:51 AM! I don't care if it's a Saturday, Get out of bed!!"
Overview
--------
Namespace Class
~~~~~~~~~~~~~~~

Making dicts into easy to reference objects. Similar to Bunch but designed so
that dictionaries are recursively made into namespaces, and can be
treated as either a dict or a namespace when accessed.

.. code:: python
from reusables import Namespace
my_breakfast = {"spam" : {"eggs": {"sausage": {"bacon": "yummy"}}}}
namespace_breakfast = Namespace(**my_breakfast)
print(namespace_breakfast.spam.eggs.sausage.bacon)
# yummy
print(namespace_breakfast.spam.eggs['sausage'].bacon)
# yummy
Reusables doesn't have an overall theme or niche of functionality. Python
is often held high by developers that it is a 'batteries' included, and this
is simply another assorted battery pack.
str(namespace_breakfast['spam'].eggs)
# "{'sausage': {'bacon': 'yummy'}}"
The main functions are all in a single file that can also be copied into
any project, or simply copy the code you need directly into your project.
dict(namespace_breakfast.spam.eggs['sausage'])
# {'bacon': 'yummy'}
repr(namespace_breakfast)
# "<Namespace: {'spam': {'eggs': {'sausage': {'...>"
Indices and tables
------------------

* :ref:`genindex`
* :ref:`search`

License
-------
Expand All @@ -90,10 +109,4 @@ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Indices and tables
------------------

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

8 changes: 2 additions & 6 deletions doc/source/reusables.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
.. currentmodule:: reusables

.. autoclass:: reusables.Namespace

.. autoclass:: reusables.DateTime

.. automodule:: reusables
:members:
2 changes: 1 addition & 1 deletion reusables/reusables.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def tree_view(dictionary, level=0, sep="| "):
View a dictionary as a tree.
"""
return "".join(["{0}{1}\n{2}".format(sep * level, k, tree_view(v, level + 1, sep=sep) if isinstance(v, dict)
else "{0}{1}\n".format(sep, v)) for k, v in dictionary.items()])
else "") for k, v in dictionary.items()])


def os_tree(directory):
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
url='https://github.com/cdgriffith/Reusables',
license='MIT',
author=attrs['author'],
tests_require=["nose >= 1.3", "coverage >= 3.6"],
install_requires=[],
tests_require=["nose >= 1.3", "coverage >= 3.6", "argparse"],
install_requires=["argparse"],
author_email='chris@cdgriffith.com',
description='Commonly Consumed Code Commodities',
long_description=long_description,
Expand All @@ -50,6 +50,6 @@
'Topic :: Software Development :: Libraries :: Python Modules',
],
extras_require={
'testing': ["nose >= 1.3", "coverage >= 3.6"],
'testing': ["nose >= 1.3", "coverage >= 3.6", "argparse"],
},
)
2 changes: 1 addition & 1 deletion test/test_reuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def test_namespace_tree(self):
namespace = reusables.Namespace(**test_dict)
result = namespace.tree_view(sep=" ")
assert result.startswith("key1\n") or result.startswith("Key 2\n")
assert "Key4" in result and " Value5\n" in result
assert "Key4" in result and " Value5\n" not in result

def test_path_single(self):
resp = reusables.safe_path('path')
Expand Down

0 comments on commit 69cbc20

Please sign in to comment.