Skip to content

Commit 9fbedce

Browse files
authored
Version 0.9.0 (#45)
+ Adding datetime_format, dtf methods + Adding datetime_from_iso, dtiso methods + Adding catch_it and retry_it wrappers + Adding CONTRIBUTING file + Changing Namespace now operates more like "dict" on init, and can accept both iterable and kwargs + Changing major structure of reusables to better group similar functionality + Changing wrapper time_it now uses .time for older versions instead of the .clock + Depreciation Warning: get_logger is changing to setup_logger + Breaking change: log_exception has new and changed kwargs + Breaking change: removing Cookie Management in favor of separate library + Breaking change: removing sort_by + Breaking change: removing namespace.from_dict() + Breaking change: removing DateTime class in favor of singular methods datetime_format and datetime_from_iso
1 parent 36673df commit 9fbedce

33 files changed

+1779
-2291
lines changed

.coveragerc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,14 @@ exclude_lines =
3232
elif size > self.max_tasks
3333
raise NotImplementedError
3434
return self.result_queue
35-
except (Exception, KeyboardInterrupt)
35+
except \(Exception
3636
if _os.path.isfile
3737
elif _os.path.isfile
3838
raise InvalidSchema
3939
pass
4040
_logger
4141
t += 1
4242
us = 0
43+
write\(
44+
if err_non_exist
45+
logger.warning

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ python:
1212
- "pypy"
1313
before_install:
1414
- sudo apt-get -qq update
15-
- sudo apt-get install -y unrar sqlite3
15+
- sudo apt-get install -y unrar
1616
install:
1717
- pip install -r requirements.txt
1818
- pip install -r requirements-test.txt

CHANGES.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
Changelog
22
=========
33

4+
Version 0.9.0
5+
-------------
6+
7+
- Adding datetime_format, dtf methods
8+
- Adding datetime_from_iso, dtiso methods
9+
- Adding catch_it and retry_it wrappers
10+
- Adding CONTRIBUTING file
11+
- Changing Namespace now operates more like "dict" on init, and can accept both iterable and kwargs
12+
- Changing major structure of reusables to better group similar functionality
13+
- Changing wrapper time_it now uses .time for older versions instead of the .clock
14+
- Depreciation Warning: get_logger is changing to setup_logger
15+
- Breaking change: log_exception has new and changed kwargs
16+
- Breaking change: removing Cookie Management in favor of separate library
17+
- Breaking change: removing sort_by
18+
- Breaking change: removing namespace.from_dict()
19+
- Breaking change: removing DateTime class in favor of singular methods datetime_format and datetime_from_iso
20+
421
Version 0.8.0
522
-------------
623

CONTRIBUTING.rst

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Contributing to Reusables
2+
=========================
3+
4+
Thank you for looking into supporting Reusables. Any constructive input
5+
is greatly appreciated!
6+
7+
Questions and Ideas
8+
-------------------
9+
10+
Even if you don't have code contributions, but just an idea, or a question about
11+
Reusables, please feel free to open an issue!
12+
13+
Reporting Bugs
14+
--------------
15+
16+
- Please include sample code and traceback (or unexpected behavior)
17+
of the error you are experiencing.
18+
19+
- Python version and Operating System.
20+
21+
Pull Requests
22+
-------------
23+
24+
- Follow PEP8
25+
26+
- New features should have
27+
- Reasoning for addition in pull request
28+
- Docstring with code block example and parameters
29+
- Tests with as much coverage as reasonable
30+
- Tests should go through both sad and happy paths
31+
32+
- Bug fixes should include
33+
- Explain under which circumstances the bug occurs in the pull request
34+
- Tests for new happy and sad paths
35+
- Test proving error without new code

Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ VENVS ?= $(HOME)/.virtualenvs
44
PYTHON2 = $(VENVS)/builder2.7/bin/python2.7
55
PYTHON2BIN = $(VENVS)/builder2.7/bin
66
PYTHON3BIN = $(VENVS)/builder3.6/bin
7-
PYTHON3 = $(VENVS)/builder3.5/bin/python3.6
7+
PYTHON3 = $(VENVS)/builder3.6/bin/python3.6
88
PYTHONS = $(VENVS)/builder2.6/bin/python2.6 $(VENVS)/builder2.7/bin/python2.7 $(VENVS)/builder3.5/bin/python3.5 $(VENVS)/builder3.3/bin/python3.3 $(VENVS)/builder3.4/bin/python3.4 $(VENVS)/builder3.6/bin/python3.6
99
PYPY = $(VENVS)/builderpypy/bin/python
1010

@@ -40,8 +40,8 @@ build:
4040
"$$python" setup.py bdist_egg; \
4141
done
4242

43-
rstcheck:
44-
$(PYTHON2BIN)/rstcheck README.rst;
43+
checkdocs:
44+
$(PYTHON2) setup.py checkdocs;
4545

4646

4747
register:
@@ -50,7 +50,7 @@ register:
5050
install:
5151
sudo $(PYTHON2) setup.py build install;
5252

53-
upload: clean test register build
53+
upload: clean checkdocs test register build
5454
$(PYTHON2) setup.py sdist upload;
5555
$(PYTHON2) setup.py bdist_wheel upload;
5656
$(PYTHON3) setup.py bdist_wheel upload;
@@ -83,5 +83,5 @@ develop:
8383
virtualenv -p python3.5 $(VENVS)/builder3.5;
8484
virtualenv -p python3.6 $(VENVS)/builder3.6;
8585
virtualenv -p pypy $(VENVS)/builderpypy;
86-
$(PYTHON2BIN)/pip install rstcheck --upgrade;
87-
$(PYTHON3BIN)/pip install tox;
86+
$(PYTHON2BIN)/pip install collective.checkdocs wheel Pygments --upgrade;
87+
$(PYTHON3BIN)/pip install tox wheel;

README.rst

Lines changed: 39 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,35 @@ Reusables
88
Overview
99
--------
1010

11-
The reusables library is a reference of python functions and classes that
11+
The reusables library is a cookbook of python functions and classes that
1212
programmers may find themselves often recreating.
1313

1414
It includes:
1515

16-
- Archiving and extraction for zip, tar, gz, bz2, and rar (extraction only)
16+
- Archiving and extraction for zip, tar, gz, bz2, and rar
1717
- Path (file and folders) management
1818
- Fast logging setup and tools
1919
- Namespace (dict to class modules with child recursion)
2020
- Friendly datetime formatting
2121
- Config to dict parsing
2222
- Common regular expressions and file extensions
23-
- Unique function wrappers
23+
- Helpful wrappers
2424
- Bash analogues
2525
- Easy downloading
2626
- Multiprocessing helpers
27-
- Cookie Management for Firefox and Chrome
27+
28+
Install
29+
~~~~~~~
30+
31+
Reusables is on PyPI, so can be easily installed with pip or easy_install.
32+
33+
.. code::
34+
35+
pip install reusables
36+
37+
38+
There are no required decencies. If this doesn't work, it's broken, raise
39+
a github issue.
2840

2941
Reusables is designed to not require any imports outside the standard library,
3042
but can be supplemented with those found in the requirements.txt file for
@@ -110,6 +122,8 @@ here's both.
110122
Namespace
111123
~~~~~~~~~
112124

125+
Check out Box_, a much improved version as its own library.
126+
113127
Dictionary management class, similar to Bunch, but designed so
114128
that sub-dictionaries are recursively made into namespaces.
115129

@@ -139,7 +153,7 @@ Logging
139153

140154
.. code:: python
141155
142-
logger = reusables.get_logger(__name__)
156+
logger = reusables.setup_logger(__name__)
143157
# By default it adds a stream logger to sys.stderr
144158
145159
logger.info("Test")
@@ -178,7 +192,7 @@ Because ReStructuredText tables don't preserve whitespace (even with literals),
178192
reusables.log_formats.keys()
179193
# ['common', 'level_first', 'threaded', 'easy_read', 'easy_thread', 'detailed']
180194
181-
logger = reusables.get_logger(__name__, log_format=reusables.log_formats.threaded)
195+
logger = reusables.setup_logger(__name__, log_format=reusables.log_formats.threaded)
182196
reusables.add_timed_rotating_file_handler(logger, "timed.log", level=logging.ERROR, log_format=reusables.log_formats.detailed)
183197
184198
@@ -237,16 +251,29 @@ That's right, str.endswith_ (as well as str.startswith_) accept a tuple to searc
237251
Wrappers
238252
~~~~~~~~
239253

254+
**unique**
255+
240256
There are tons of wrappers for caching and saving inputs and outputs, this is a
241257
different take that requires the function returns a result not yet provided.
242258

243259
.. code:: python
244260
245261
@reusables.unique(max_retries=100, error_text="All UIDs taken!")
246262
def gen_small_uid():
247-
import random
248263
return random.randint(0, 100)
249264
265+
**time_it**
266+
267+
Easily time the execution time of a function, using the high precision
268+
perf_conuter on Python 3.3+, otherwise clock.
269+
270+
.. code:: python
271+
272+
@reusables.time_it()
273+
def test_it():
274+
return time.sleep(float(f"0.{random.randint(1, 9)}"))
275+
276+
250277
251278
Command line helpers
252279
--------------------
@@ -298,19 +325,19 @@ instances, such as 'touch' and 'download'.
298325
DateTime
299326
~~~~~~~~
300327

301-
Easy formatting for datetime objects. It also adds auto parsing for ISO formatted time.
328+
Easy formatting for datetime objects. Also parsing for ISO formatted time.
302329

303330

304331
.. code:: python
305332
306-
current_time = reusables.DateTime() # same as datetime.datetime.now(), as DateTime object
307-
308-
current_time.format("Wake up {son}, it's {hours}:{minutes} {periods}!"
333+
reusables.datetime_format("Wake up {son}, it's {hours}:{minutes} {periods}!"
309334
"I don't care if it's a {day-fullname}, {command}!",
310335
son="John",
311336
command="Get out of bed!")
312337
# "Wake up John, it's 09:51 AM! I don't care if it's a Saturday, Get out of bed!!"
313338
339+
reusables.datetime_from_iso('2017-03-10T12:56:55.031863')
340+
# datetime.datetime(2017, 3, 10, 12, 56, 55, 31863)
314341
315342
316343
Examples based on Mon Mar 28 13:27:11 2016
@@ -344,24 +371,6 @@ Examples based on Mon Mar 28 13:27:11 2016
344371
===================== =================== ===========================
345372

346373

347-
Cookie Management
348-
~~~~~~~~~~~~~~~~~
349-
350-
Firefox and Chrome Cookie management. (Chrome requires SQLite 3.8 or greater.)
351-
352-
.. code:: python
353-
354-
fox = reusables.FirefoxCookies()
355-
# Automatically uses the DB of the default profile, can specify db=<path>
356-
357-
fox.add_cookie("example.com", "MyCookie", "Cookie contents!")
358-
359-
fox.find_cookies(host="Example")
360-
# [{'host': u'example.com', 'name': u'MyCookie', 'value': u'Cookie contents!'}]
361-
362-
fox.delete_cookie("example.com", "MyCookie")
363-
364-
365374
FAQ
366375
---
367376

@@ -372,17 +381,6 @@ functionality you want to see! Only requirements are that it's well thought out
372381
(to be merged will need documentation and basic unittests as well, but not a requirement for opening the PR).
373382
Please don't hesitate if you're new to python! Even the smallest PR contributions will earn a mention in a brand new Contributors section.
374383

375-
376-
**Why all the underscored imports?**
377-
378-
The rational behind this is just like the standard library, so that the user is sure anything they have access to is solely from this library
379-
and not one of it's imports. Several variables are also hidden like this, as they are only to be used by the library itself. For example, loggers
380-
should not have their objects modified by direct reference, but rather obtained through 'logging.getLogger('reusables')', as it helps sort out those who
381-
know what they are doing.
382-
383-
I could use __all__ and just expose what I want, but I feel that people should be allowed to copy a single file or function out of here,
384-
and have a clear understanding what is designed to be exposed without being an interpreter.
385-
386384
**Unrar not installed?**
387385

388386
A common error to see, especially on Windows based systems, is: "rarfile.RarCannotExec: Unrar not installed? (rarfile.UNRAR_TOOL='unrar')"
@@ -391,13 +389,6 @@ This is probably because unrar is not downloaded or linked properly. Download Un
391389
from http://www.rarlab.com/rar_add.htm and follow these instructions before
392390
trying again: http://rarfile.readthedocs.org/en/latest/faq.html?highlight=windows#how-can-i-get-it-work-on-windows
393391

394-
**I can't figure out how upgrade SQLite on Windows to 3.8 or higher instead of 3.6**
395-
396-
Me neither. ¯\\_(ツ)_/¯
397-
398-
Using Python 3.6 magically fixed it for me. If you ever figure it out, please let me know.
399-
400-
401392
License
402393
-------
403394

@@ -437,6 +428,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
437428
.. _str.startswith: https://docs.python.org/2/library/stdtypes.html#str.startswith
438429
.. _readthedocs.org: http://reusables.readthedocs.io/en/latest/
439430
.. _docs: https://docs.python.org/3/library/logging.html#logrecord-attributes
431+
.. _Box: https://pypi.python.org/pypi/python-box
440432

441433
Additional Info
442434
---------------

reusables/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
#
66
# Copyright (c) 2014-2017 - Chris Griffith - MIT License
77
from __future__ import absolute_import
8-
from .reusables import *
98
from .namespace import *
109
from .dt import *
1110
from .log import *
12-
from .browser import *
1311
from .wrappers import *
14-
from .multiprocess_helpers import *
1512
from .web import *
1613
from .shared_variables import *
17-
from .numbers import *
14+
from .cli import *
15+
from .file_operations import *
16+
from .processes import *
17+
from .string_manipulation import *
1818

1919
__author__ = "Chris Griffith"
20-
__version__ = "0.8.0"
20+
__version__ = "0.9.0"

0 commit comments

Comments
 (0)