mahmoud / boltons

🔩 Like builtins, but boltons. 250+ constructs, recipes, and snippets which extend (and rely on nothing but) the Python standard library. Nothing like Michael Bolton.
https://boltons.readthedocs.org
Other
6.47k stars 349 forks source link

Proposal to add a few functions #186

Open moltenform opened 5 years ago

moltenform commented 5 years ago

It's great to find a library like Boltons. I've been using my own library for 8 years that shares many of the same goals as this library:

Here are the main functions from my library that didn't seem to already be in Boltons, (renamed to be closer to Bolton's naming conventions),

ioutils.input_ask_yes_no
ioutils.input_int
ioutils.input_choice
namedutils.SimpleEnum
namedutils.SimpleContainer
fileutils.safe_filename
mathutils.get_random_string
strutils.replace_whole_word
strutils.truncate_with_ellipsis
strutils.format_filesize
listutils.RecentlyUsedList
fileutils.delete_dir_contents
fileutils.is_dir_empty
fileutils.copy(src, dest, ok_to_overwrite)
    unlike shutil, can atomically ensure that no file is overwritten
fileutils.move(src, dest, ok_to_overwrite)
    unlike shutil, can atomically ensure that no file is overwritten
ioutils.to_printable
ioutils.safe_print
    print any string and avoid UnicodeDecodeError
fileutils.readall(path, mode, encoding)
fileutils.writeall(path, s, mode, encoding)
fileutils.iterfiles(path, pattern, recurse)
fileutils.iterdirs(path, pattern, recurse)
fileutils.iterfileinfo(path, pattern, recurse)
fileutils.find_on_sys_path
fileutils.get_hash
fileutils.run
    convenience wrapper around common subprocess.Popen patterns

Please let me know if any of these would be considered for inclusion, and I can submit a pull request, including unit tests.

mahmoud commented 5 years ago

Hey Ben! Thanks for your patience, this issue caught me on honeymoon. Many if not most of these look very promising! I'm kind of curious what some of them entail, and whether I can merge some with some non-bolton utils I have laying around too (I def have an input_ask_yes_or_no somewhere around here ;) )

Some notes:

So yeah, without putting too much work into extra testing, can you do a PR per module so that we can review the contents?

Thanks again for reaching out!

mblahay commented 3 years ago

@moltenform, do you have the code available in a personal repo?

moltenform commented 3 years ago

I do have it, along with tests, at https://github.com/moltenform/labs_youthful_projects/tree/master/src/ben_python_common

The method names have changed from what I mentioned above.

Let me know if you have any questions!

mblahay commented 3 years ago

@moltenform, Do you plan on submitting pull requests to start integrating your work into boltons?