Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 01f94f8
Showing
10 changed files
with
780 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
Pseudo-hacky sugar around generators. If you use this your code can get unreadable or very simple. Over the last years I never beautified the code, but used it quite sometimes. | ||
|
||
|
||
Basically it looks like this: | ||
|
||
[1, 2, 3] | add(2) | list == [3, 4, 5] | ||
|
||
where | ||
|
||
@worker | ||
def add(items, n): | ||
for i in items: | ||
yield i + n | ||
|
||
If you write nested for loops or nested functions a(b(c([1,2,3]))) this might help you. | ||
|
||
|
||
Sometimes you can achieve something like this: | ||
|
||
|
||
filter_audio_files = fs.filter_by_ext(['.mp3']) | ||
|
||
@producer | ||
def folders_with_audio_files(path): | ||
for root, folders, filenames in os.walk(path): | ||
if any(filenames | filter_audio_files): | ||
yield root | ||
|
||
|
||
@worker | ||
def that_need_fix(paths): | ||
for path in paths: | ||
files = listdir(path) | filter_audio_files | join_path(path) | list | ||
dos_names = files | get_83DOS_name | list | ||
|
||
if files.sort() != dos_names.sort(): | ||
yield path | ||
that_need_fix = that_need_fix() | ||
|
||
|
||
# and the outermost command looks like this | ||
|
||
folders_with_audio_files(root) | that_need_fix # ... | ||
|
||
|
||
# note that convetional python doesn't have to be more complex | ||
# it's just about code reuse | ||
for root, folders, filenames in os.walk(root): | ||
files = [file for file in listdir(path) if os.path.splitext(file)[1] in ['.mp3',]] | ||
if any(files): | ||
files = map(lambda file:os.path.join(root, file), files) | ||
|
||
dos_names = [get_dos_name(file) for file in files] | ||
|
||
if files.sort() != dos_names.sort(): | ||
yield path | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
__version__ = "0.0.1" | ||
import os | ||
from setuptools import setup, find_packages | ||
|
||
def _read_contents(fn): | ||
here = os.path.dirname( os.path.realpath(__file__) ) | ||
filename = os.path.join(here, fn) | ||
with open(filename) as file: | ||
return file.read() | ||
|
||
setup( | ||
name='useless.pipes', | ||
version=__version__, | ||
description='Generator sugar.', | ||
long_description=_read_contents('README'), | ||
author="herr kaste", | ||
author_email="herr.kaste@gmail.com", | ||
packages=find_packages(exclude=['tests']), | ||
install_requires=[], | ||
tests_require=['pytest'], | ||
classifiers= [ | ||
'Development Status :: 3 - Alpha', | ||
'Intended Audience :: Developers', | ||
'License :: OSI Approved :: BSD License', | ||
'Operating System :: OS Independent', | ||
'Programming Language :: Python', | ||
'Topic :: Internet :: WWW/HTTP', | ||
'Topic :: Software Development :: Libraries', | ||
], | ||
) |
Empty file.
Oops, something went wrong.