Skip to content

Commit 36673df

Browse files
authored
Version 0.8.0 (#34)
- Adding log_exception wrapper - Adding ProtectedDict - Adding hooks for Tasker main loop - Adding roman number functions - Adding directory_duplicates function - Adding integer to words functions - Adding option to enable scandir package walk instead of os.walk - Adding url_to_ip and ip_to_url functions - Adding hex_digest kwarg to file_hash - Adding args and kwargs to time_it and log_exception wrappers - Fixing file_hash checks by just passing to hashlib - Changing functions to remove 'all' from them, extract_all, archive_all, find_all_files and find_all_files_generator - Changing time_it function to use time.perf_counter on 3.3+ and time.clock on 2.6-3.2 - Depreciation Warning: extract_all is changing to extract - Depreciation Warning: archive_all is changing to archive - Depreciation Warning: find_all_files is changing to find_files - Depreciation Warning: find_all_files_generator is changing to find_files_generator - Depreciation Warning: count_all_files is changing to count_files - Breaking change: Removing reuse wrapper - Breaking change: archive_all now detects type based off name, should supply extension to name - Breaking change: time_it message now takes args seconds, args, kwargs and does not allow positionals - Breaking change: os_tree will no longer return an empty dictionary on failure, but include the base directory supplied - Breaking change: renaming splice to cut
1 parent 1ca926c commit 36673df

35 files changed

+1301
-348
lines changed

.coveragerc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ omit =
55
*/test/*
66
*/pypy/*
77
*/nose/*
8+
*/.*/*
9+
*/*.egg-info/*
810
exclude_lines =
911
pragma: no cover
1012
except Exception
@@ -25,3 +27,16 @@ exclude_lines =
2527
self.free_tasks
2628
self.busy_tasks
2729
self.current_tasks
30+
except KeyError
31+
if size < self.max_tasks
32+
elif size > self.max_tasks
33+
raise NotImplementedError
34+
return self.result_queue
35+
except (Exception, KeyboardInterrupt)
36+
if _os.path.isfile
37+
elif _os.path.isfile
38+
raise InvalidSchema
39+
pass
40+
_logger
41+
t += 1
42+
us = 0

.pep8speaks.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
scanner:
2+
diff_only: False
3+
4+
pycodestyle:
5+
max-line-length: 100

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ python:
77
- "3.3"
88
- "3.4"
99
- "3.5"
10-
- "3.6-dev"
10+
- "3.6"
11+
- "3.7-dev"
1112
- "pypy"
1213
before_install:
1314
- sudo apt-get -qq update
@@ -16,5 +17,5 @@ install:
1617
- pip install -r requirements.txt
1718
- pip install -r requirements-test.txt
1819
- pip install coveralls
19-
script: nosetests --with-coverage -vv --cover-package=reusables test
20+
script: pytest --cov=reusables
2021
after_success: coveralls

AUTHORS.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Reusables is written and maintained by Chris Griffith <chris@cdgriffith.com>.
2+
3+
A big thank you to everyone that has helped! From PRs to suggestions and bug
4+
reporting, all input is greatly appreciated!
5+
6+
- Clara Griffith (beautiousmax)
7+
- Hellowlol

CHANGES.rst

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

4+
Version 0.8.0
5+
-------------
6+
7+
- Adding log_exception wrapper
8+
- Adding ProtectedDict
9+
- Adding hooks for Tasker main loop
10+
- Adding roman number functions
11+
- Adding directory_duplicates function
12+
- Adding integer to words functions
13+
- Adding option to enable scandir package walk instead of os.walk
14+
- Adding url_to_ip and ip_to_url functions
15+
- Adding hex_digest kwarg to file_hash
16+
- Adding args and kwargs to time_it and log_exception wrappers
17+
- Fixing file_hash checks by just passing to hashlib
18+
- Changing functions to remove 'all' from them, extract_all, archive_all, find_all_files and find_all_files_generator
19+
- Changing time_it function to use time.perf_counter on 3.3+ and time.clock on 2.6-3.2
20+
- Depreciation Warning: extract_all is changing to extract
21+
- Depreciation Warning: archive_all is changing to archive
22+
- Depreciation Warning: find_all_files is changing to find_files
23+
- Depreciation Warning: find_all_files_generator is changing to find_files_generator
24+
- Depreciation Warning: count_all_files is changing to count_files
25+
- Breaking change: Removing reuse wrapper
26+
- Breaking change: archive_all now detects type based off name, should supply extension to name
27+
- Breaking change: time_it message now takes args seconds, args, kwargs and does not allow positionals
28+
- Breaking change: os_tree will no longer return an empty dictionary on failure, but include the base directory supplied
29+
- Breaking change: renaming splice to cut
30+
431
Version 0.7.0
532
-------------
633

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2014 Chris Griffith
3+
Copyright (c) 2014-2017 Chris Griffith
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of
66
this software and associated documentation files (the "Software"), to deal in

Makefile

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ HOME ?= $HOME
22
CWD = $(shell pwd)
33
VENVS ?= $(HOME)/.virtualenvs
44
PYTHON2 = $(VENVS)/builder2.7/bin/python2.7
5-
PYTHON3 = $(VENVS)/builder3.5/bin/python3.5
6-
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
5+
PYTHON2BIN = $(VENVS)/builder2.7/bin
6+
PYTHON3BIN = $(VENVS)/builder3.6/bin
7+
PYTHON3 = $(VENVS)/builder3.5/bin/python3.6
8+
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
79
PYPY = $(VENVS)/builderpypy/bin/python
810

911
.PHONY: all test clean help register build
@@ -24,9 +26,10 @@ clean:
2426
rm -rf dist;
2527

2628
test:
27-
(set -e; for python in $(PYTHONS); do\
28-
PYTHONPATH=$(CWD) "$$python" setup.py test; \
29-
done)
29+
$(PYTHON3BIN)/tox;
30+
# (set -e; for python in $(PYTHONS); do\
31+
# PYTHONPATH=$(CWD) "$$python" setup.py test; \
32+
# done)
3033

3134

3235
build:
@@ -37,6 +40,9 @@ build:
3740
"$$python" setup.py bdist_egg; \
3841
done
3942

43+
rstcheck:
44+
$(PYTHON2BIN)/rstcheck README.rst;
45+
4046

4147
register:
4248
$(PYTHON2) setup.py register;
@@ -66,7 +72,7 @@ help:
6672
develop:
6773
sudo add-apt-repository ppa:fkrull/deadsnakes;
6874
sudo apt-get update;
69-
sudo apt-get install python2.6 python2.7 python3.5 python3.3 python3.4 pypy python-pip unrar -y;
75+
sudo apt-get install python2.6 python2.6-dev python2.7 python2.7-dev python3.3 python3.3-dev python3.4 python3.4-dev python3.5 python3.5-dev python3.6 python3.6-dev pypy pypy-dev python-pip unrar -y;
7076
sudo pip install virtualenv --upgrade;
7177
rm -rf $(VENVS);
7278
mkdir -p $(VENVS);
@@ -75,4 +81,7 @@ develop:
7581
virtualenv -p python3.3 $(VENVS)/builder3.3;
7682
virtualenv -p python3.4 $(VENVS)/builder3.4;
7783
virtualenv -p python3.5 $(VENVS)/builder3.5;
84+
virtualenv -p python3.6 $(VENVS)/builder3.6;
7885
virtualenv -p pypy $(VENVS)/builderpypy;
86+
$(PYTHON2BIN)/pip install rstcheck --upgrade;
87+
$(PYTHON3BIN)/pip install tox;

README.rst

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ readthedocs.org_.
4141

4242
Please note this is currently in development. Any item in development
4343
prior to a major version (1.x, 2.x) may change. Once at a major version,
44-
no breaking changes will occur within it.
44+
no breaking changes are planned to occur within that version.
4545

4646
What's in the box
4747
-----------------
@@ -53,19 +53,19 @@ General Helpers and File Management
5353
5454
import reusables
5555
56-
reusables.find_all_files(".", ext=reusables.exts.pictures)
56+
reusables.find_files_list(".", ext=reusables.exts.pictures)
5757
# ['/home/user/background.jpg', '/home/user/private.png']
5858
59-
reusables.archive_all("reusables", name="reuse", archive_type="zip")
59+
reusables.archive("reusables", name="reuse", archive_type="zip")
6060
# 'C:\\Users\\Me\\Reusables\\reuse.zip'
6161
62-
reusables.extract_all("test/test_structure.zip", "my_archive")
62+
reusables.extract("test/test_structure.zip", "my_archive")
6363
# All files in the zip will be extracted into directory "my_archive"
6464
6565
reusables.config_dict('my_config.cfg')
6666
# {'Section 1': {'key 1': 'value 1', 'key2': 'Value2'}, 'Section 2': {}}
6767
68-
reusables.count_all_files(".")
68+
reusables.count_files(".")
6969
# 405
7070
7171
reusables.file_hash("test_structure.zip", hash_type="sha256")
@@ -77,30 +77,33 @@ General Helpers and File Management
7777
reusables.run("echo 'hello there!'", shell=True)
7878
# CompletedProcess(args="echo 'hello there!'", returncode=0, stdout='hello there!\n')
7979
80+
reusables.cut("abcdefghi")
81+
# ['ab', 'cd', 'ef', 'gh', 'i']
8082
81-
One of the most reusables pieces of code is the find_all_files. It is always
83+
84+
One of the most reusables pieces of code is the find_files. It is always
8285
appearing on stackoverflow and forums of how to implement os.walk or glob;
8386
here's both.
8487

8588
.. code:: python
8689
87-
reusables.find_all_files(".", name="*reuse*", depth=2)
90+
reusables.find_files_list(".", name="*reuse*", depth=2)
8891
# ['.\\test\\test_reuse.py', '.\\test\\test_reuse_datetime.py',
8992
# '.\\test\\test_reuse_logging.py', '.\\test\\test_reuse_namespace.py']
9093
9194
# match_case works for both ext and name
9295
# depth of 1 means this working directory only, no further
9396
94-
reusables.find_all_files(ext=".PY", depth=1, match_case=True)
97+
reusables.find_files_list(ext=".PY", depth=1, match_case=True)
9598
# []
9699
97-
reusables.find_all_files(ext=".py", depth=1, match_case=True)
100+
reusables.find_files_list(ext=".py", depth=1, match_case=True)
98101
# ['.\\setup.py']
99102
100-
reusables.find_all_files(name="setup", ext=".py", match_case=True)
103+
reusables.find_files_list(name="setup", ext=".py", match_case=True)
101104
# ['.\\setup.py']
102105
103-
reusables.find_all_files(name="Setup", ext=".py", match_case=True)
106+
reusables.find_files_list(name="Setup", ext=".py", match_case=True)
104107
# []
105108
106109
@@ -400,7 +403,7 @@ License
400403

401404
The MIT License (MIT)
402405

403-
Copyright (c) 2014-2016 Chris Griffith
406+
Copyright (c) 2014-2017 Chris Griffith
404407

405408
Permission is hereby granted, free of charge, to any person obtaining a copy of
406409
this software and associated documentation files (the "Software"), to deal in
@@ -455,4 +458,6 @@ improve existing code is warmly welcomed!
455458
multiprocess_helpers
456459
cli
457460
wrappers
461+
numbers
458462
changelog
463+

doc/source/numbers.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Numbers
2+
=======
3+
4+
.. automodule:: reusables.numbers
5+
:members:
6+
:undoc-members:

requirements-test.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
nose >= 1.3
1+
pytest
22
coverage >= 3.6
33
rarfile
4+
scandir
5+
tox
6+
pytest-cov

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
rarfile
2+
scandir

reusables/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
#!/usr/bin/env python
2+
# -*- coding: UTF-8 -*-
3+
#
4+
# Part of the Reusables package.
5+
#
6+
# Copyright (c) 2014-2017 - Chris Griffith - MIT License
17
from __future__ import absolute_import
28
from .reusables import *
39
from .namespace import *
@@ -8,6 +14,7 @@
814
from .multiprocess_helpers import *
915
from .web import *
1016
from .shared_variables import *
17+
from .numbers import *
1118

1219
__author__ = "Chris Griffith"
13-
__version__ = "0.7.0"
20+
__version__ = "0.8.0"

reusables/browser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
2+
# -*- coding: UTF-8 -*-
33
#
44
# Part of the Reusables package.
55
#
6-
# Copyright (c) 2014-2016 - Chris Griffith - MIT License
6+
# Copyright (c) 2014-2017 - Chris Griffith - MIT License
77
"""
88
Classes for managing Firefox and Chrome Cookies
99
"""

reusables/cli.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# Part of the Reusables package.
55
#
6-
# Copyright (c) 2014-2016 - Chris Griffith - MIT License
6+
# Copyright (c) 2014-2017 - Chris Griffith - MIT License
77
"""
88
Functions to only be used on Interactive instances to ease life.
99
@@ -16,7 +16,7 @@
1616

1717
# Keep touch and download import so it can be imported with other CLI commands
1818
from .shared_variables import *
19-
from .reusables import run, win_based, find_all_files, touch
19+
from .reusables import run, win_based, find_files_list, touch
2020
from .web import download
2121
from .log import add_stream_handler
2222

@@ -104,7 +104,7 @@ def ls(params="", directory=".", printed=True):
104104
def find(name=None, ext=None, directory=".", match_case=False,
105105
disable_glob=False, depth=None):
106106
""" Designed for the interactive interpreter by making default order
107-
of find_all_files faster.
107+
of find_files faster.
108108
109109
:param name: Part of the file name
110110
:param ext: Extensions of the file you are looking for
@@ -114,9 +114,9 @@ def find(name=None, ext=None, directory=".", match_case=False,
114114
:param depth: How many directories down to search
115115
:return: list of all files in the specified directory
116116
"""
117-
return find_all_files(directory=directory, ext=ext, name=name,
118-
match_case=match_case, disable_glob=disable_glob,
119-
depth=depth)
117+
return find_files_list(directory=directory, ext=ext, name=name,
118+
match_case=match_case, disable_glob=disable_glob,
119+
depth=depth)
120120

121121

122122
def head(file_path, lines=10, encoding="utf-8", printed=True,
@@ -149,13 +149,16 @@ def head(file_path, lines=10, encoding="utf-8", printed=True,
149149

150150
def cat(file_path, encoding="utf-8", errors='strict'):
151151
"""
152-
^-^
153-
(-.-)
154-
|.|
155-
/ \\
156-
| | _/
157-
| || | |
158-
\_||_/_/
152+
153+
.. code:
154+
155+
^-^
156+
(-.-)
157+
|.|
158+
/ \\
159+
| | _/
160+
| || | |
161+
\_||_/_/
159162
160163
:param file_path: Path to file to read
161164
:param encoding: defaults to utf-8 to decode as, will fail on binary

reusables/dt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# Part of the Reusables package.
55
#
6-
# Copyright (c) 2014-2016 - Chris Griffith - MIT License
6+
# Copyright (c) 2014-2017 - Chris Griffith - MIT License
77
"""
88
A hopefully easier to use formatting system for datetime.
99
"""

0 commit comments

Comments
 (0)