Skip to content

Commit b09461c

Browse files
committed
-
1 parent c1529f3 commit b09461c

File tree

5 files changed

+36
-11
lines changed

5 files changed

+36
-11
lines changed

setup.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,16 @@ def get_packages():
145145
]
146146

147147

148+
install_requires = ['setuptools']
149+
if sys.version_info[:2] <= (3, 3):
150+
install_requires.append('pathlib>=0.97')
151+
152+
148153
setuptools.setup(
149154
name='python_toolbox',
150155
version='0.6.3',
151-
requires=['setuptools'],
152156
test_suite='nose.collector',
153-
install_requires=['setuptools', 'pathlib>=0.97'],
157+
install_requires=install_requires,
154158
tests_require=['nose>=1.0.0',
155159
'docutils>=0.8'],
156160
description='A collection of Python tools for various tasks',

source_py3/python_toolbox/import_tools.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def import_all(package, exclude='__init__', silent_fail=False):
3535

3636
names = {}
3737
for path in paths:
38-
name = str(path.parts[-1][:-len(path.suffix)])
38+
name = str(path.name[:-len(path.suffix)] if path.suffix else path.name)
3939
if name == exclude:
4040
continue
4141
full_name = package.__name__ + '.' + name
@@ -164,7 +164,8 @@ def import_by_path(path, name=None, keep_in_sys_modules=True):
164164
module = _import_by_path_from_zip(path)
165165

166166
else: # '.zip' not in path
167-
short_name = str(path.parts[-1][:-len(path.suffix)])
167+
short_name = str(path.name[:-len(path.suffix)] if path.suffix
168+
else path.name)
168169

169170
if name is None: name = short_name
170171
my_file = None

source_py3/python_toolbox/misc_tools/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
is_magic_variable_name, get_actual_type, is_number, identity_function,
1010
do_nothing, OwnNameDiscoveringDescriptor, find_clear_place_on_circle,
1111
general_sum, general_product, is_legal_email_address, is_type, NonInstatiable,
12-
repeat_getattr
12+
repeat_getattr, add_extension_if_plain
1313
)
1414
from . import name_mangling
1515
from .proxy_property import ProxyProperty

source_py3/python_toolbox/misc_tools/misc_tools.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,16 +223,15 @@ def find_clear_place_on_circle(circle_points, circle_size=1):
223223

224224

225225
def add_extension_if_plain(path, extension):
226-
'''Add `extenstion` to a file path if it doesn't have an extenstion.'''
226+
'''Add `extension` to a file path if it doesn't have an extension.'''
227227

228228
path = pathlib.Path(path)
229229

230-
if extension:
230+
if extension and not path.suffix:
231231
assert extension.startswith('.')
232-
if path.suffix:
233-
return pathlib.Path(str(path)[:-len(path.suffix) + extension])
234-
else:
235-
return path
232+
return pathlib.Path(str(path) + extension)
233+
234+
return path
236235

237236

238237
def general_sum(things, start=None):
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2009-2014 Ram Rachum.
2+
# This program is distributed under the MIT license.
3+
4+
'''Testing module for `find_clear_place_on_circle`.'''
5+
6+
import pathlib
7+
8+
import nose.tools
9+
10+
from python_toolbox import temp_file_tools
11+
12+
from python_toolbox.misc_tools import add_extension_if_plain
13+
14+
15+
def test():
16+
assert str(add_extension_if_plain(r'''c:\hello.zip''', '.ogg')) == \
17+
r'''c:\hello.zip'''
18+
assert str(add_extension_if_plain(r'''c:\hello''', '.ogg')) == \
19+
r'''c:\hello.ogg'''
20+
assert str(add_extension_if_plain(r'''c:\hello''', '.mkv')) == \
21+
r'''c:\hello.mkv'''

0 commit comments

Comments
 (0)