Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal to add a few functions #186

Open
moltenform opened this issue Nov 2, 2018 · 4 comments
Open

Proposal to add a few functions #186

moltenform opened this issue Nov 2, 2018 · 4 comments

Comments

@moltenform
Copy link

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:

  • Supports py 2 and py 3 from the same codebase
  • Performs common tasks that would be complex/verbose using the stdlib
  • Does not depend on other 3rd party libs
  • Thoroughly tested

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
Copy link
Owner

mahmoud commented Dec 25, 2018

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:

  • I've had to write my own Enum once or twice bc Enum34 didn't really fit the bill.
  • I think format_filesize is probably the same as strutils.bytes2human.
  • I'm curious how to_printable and safe_print work.
  • Curious what readall and writeall do.
  • boltons has an iter_find_files with patterns and stuff, but I think there's a demand for more.
  • I could definitely see get_hash being useful, half the time I have to look up hashlib :)

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
Copy link
Contributor

mblahay commented Aug 14, 2020

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

@moltenform
Copy link
Author

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
Copy link
Contributor

mblahay commented Aug 28, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants