facelessuser / bracex Goto Github PK
View Code? Open in Web Editor NEWBash style brace expansion for Python
Home Page: https://facelessuser.github.io/bracex/
License: MIT License
Bash style brace expansion for Python
Home Page: https://facelessuser.github.io/bracex/
License: MIT License
Currently, when expanding, the limit isn't identified until most of the expansion is done, so we can actually hang regardless, we just don't return everything and fail.
We can shortcut this when expanding numbers {1..100}
and characters {a..d}
as we can calculate expansion without actually doing it.
The whole point of an iterator, in the sense we are using it, is to provide the next without having to calculate everything. Unfortunately, we currently unpack everything on the first so that we can tell how many empty entries we have at the tail (we trim trailing empty entries I believe).
The tests depend on a text file:
Line 22 in 8edd0c5
I think a simple include in the pyproject.toml would be sufficient: https://python-poetry.org/docs/pyproject/#include-and-exclude
I've been seeking a command x
, like seq
but doing brace expansion. It could be used like
x "{a..z}/{a..z}/{a..z}/{a..z}/{a..z}/{a..z}" | xargs -d $'\n' mkdir -p
I've not found a satisfactory x
, so I'd like to offer a PR allowing python -m bracex
to serve as x
. Would you be interested?
I imagine the major elements would be
__main__.py
wrapping bracex.iexpand()
argparse
I totally understand if the answer is no, so please don't feel pressured. I know every new feature creates support costs. As plan B I could release a separate package that wraps bracex, keeping a loose coupling.
Thanks for your consideration, Alex
It should be really easy to add static types to at least the public API, and would help remove some type ignores in cibuildwheel. I'd be happy to contribute the static types for the public API if you'd like me to, but I'd need to know if you want a .pyi file, or inline types. If you want to add full static type checking internally too, inline types are preferable. If not, then it could be done either way. (I think the public API is basically two functions).
๐ import bracex
๐ bracex.expand('{cautious_memory.{cogs.{permissions,wiki,watch_lists}.{db,commands},api,meta},jishaku,bot_bin.{misc,debug,sql,stats}}')
['cautious_memory.{cogs.permissions.db}', 'cautious_memory.{cogs.permissions.commands}', 'cautious_memory.{cogs.wiki.db}', 'cautious_memory.{cogs.wiki.commands}', 'cautious_memory.{cogs.watch_lists.db}', 'cautious_memory.{cogs.watch_lists.commands}', 'cautious_memory.{cogs.api}', 'cautious_memory.{cogs.meta}', 'jishaku', 'bot_bin.misc', 'bot_bin.debug', 'bot_bin.sql', 'bot_bin.stats']
๐ bracex.__version__
'1.3'
That, but without the {} in the return value
The lint task fails, with the following complaint
lint installed: flake8==3.9.2,flake8-builtins==1.5.3,flake8-docstrings==1.6.0,flake8-mutable==1.2.0,flake8-polyfill==1.0.2,mccabe==0.6.1,pep8-naming==0.12.1,pycodestyle==2.7.0,pydocstyle==6.1.1,pyflakes==2.3.1,snowballstemmer==2.1.0
llint run-test-pre: PYTHONHASHSEED='2341193631'
lint run-test: commands[0] | /home/alex/src/bracex/.tox/lint/bin/flake8 .
./bracex/__init__.py:37:8: N818 exception name 'ExpansionLimitException' should be named with an Error suffix
ERROR: InvocationError for command /home/alex/src/bracex/.tox/lint/bin/flake8 . (exited with code 1)
It could be remedied by renaming the exception, or overriding this lint check. The latter is probably preferable, in the interest of API stability,
Currently, someone could feed in a pattern of {1..100000000}
, and that would not go well. If you are using bracket expansion, and exposing it to external users, this may be very undesirable. By default, we will limit expansion to 1000 strings, but you will be able to alter this higher, lower, or even disable it via an option.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.