Introduction
RedBaron is a python library and tool powerful enough to be used into IPython
solely that intent to make the process of writing code that modify source
code as easy and as simple as possible. That include writing custom
refactoring, generic refactoring, tools, IDE or directly modifying you source
code into IPython with a higher and more powerful abstraction than the
advanced texts modification tools that you find in advanced text editors and
IDE.
RedBaron guaranteed you that it will only modify your code where you ask him
to. To achieve this, it is based on Baron
a lossless AST for
Python that guarantees the operation ast_to_code(code_to_ast(source_code)) == source_code
.
(Baron's AST is called an FST, a Full Syntax Tree).
RedBaron API and feel is heavily inspired by BeautifulSoup. It tries to be
simple and intuitive and that once you've get the basics principles, you are
good without reading the doc for 80% of your operations.
For now, RedBaron can be considered in alpha, the core is quite stable but it
is not battle tested yet and is still a bit rough. Feedback and contribution
are very welcome.
The public documented API on the other side is guaranteed to be
retro-compatible and won't break until 2.0 (if breaking is needed at that
point).
There might be the only exception that if you directly call specific nodes
constructors with FST that this API change, but this is not documented and
simply horribly unpracticable, so I'm expecting no one to do that.
Support
RedBaron is support python python 2 and up to python 3.7 grammar.
Roadmap
Current roadmap is as boring as needed:
- bug fixes
- new small features (walker pattern, maybe code generation) and performance improvement.
Installation
pip install redbaron[pygments]
Or if you don't want to have syntax highlight in your shell or don't need it:
pip install redbaron
Running tests
pip install pytest
py.test tests
You can reach us on irc.freenode.net#baron or irc.freenode.net##python-code-quality.
Financial support
Baron and RedBaron are a very advanced piece of engineering that requires a lot
of time of concentration to work on. Until the end of 2018, the development
has been a full volunteer work mostly done by Bram,
but now, to reach the next level and bring those projects to the stability and
quality you expect, we need your support.
You can join our contributors and sponsors on our transparent
OpenCollective, every contribution will
count and will be mainly used to work on the projects stability and quality but
also on continuing, on the side, the R&D side of those projects.
Backers
Thank you to all our backers! 🙏 [Become a backer]
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]
Contributors
This project exists thanks to all the people who contribute.
Code of Conduct
As a member of PyCQA, RedBaron follows its Code of Conduct.
Links
RedBaron is fully documented, be sure to check the tutorial and documentation.
Changelog
0.9.2 (2019-03-17)
0.9.1 (2019-02-01)
- fix .names() and variations that didn't handle the case where there was "()" on FromImport nodes
0.9 (2019-02-01)
-
full python 3.7 syntax support
-
BREAKING CHANGE: annotations are now member of {Def,List,Dict}Argument to flatten the data structure, TypedNameNode doesn't exist anymore
-
add support for return annotation by bram
-
add support for variable annotation https://github.com/PyCQA/redbaron/pull/177 by scottbelden and additional work by bram
-
add support for raise from by bram
0.8 (2018-10-29)
0.7 (2018-08-21)
Python 3 support (based on work in Baron):
- support ellipsis
- support matrix operator
- support f-strings
- support numeric literals
- support nonlocal statement
- support keyword only markers
- support yield from statement
- support async/await statements
0.6.3 (2017-01-02)
- fix help() after append
- fix _synchronise() for base_nodes to avoid recursion in repr function if code run not in the shell
- add at method
0.6.2 (2016-10-03)
- fix some old call to log() weren't lazy, that could cause a crash in some situations by an infinite recursive call and also reduce performances
- fix in _iter_in_rendering_order method to avoid bug in edge cases (issue #107)
0.6.1 (2016-03-28)
- fix setup.py, package weren't pushed on pypi since splitting of redbaron.py
into multiple files.
0.6 (2016-03-28)
This release is guaranteed to have a retro-compatible public documented API
from now on until maybe 2.0.
There might be the only exception that if you directly call specific nodes
constructors with FST that this API change, but this is not documented and
simply horribly unpracticable, so I'm expecting no one to do that.
From now on the focus will be on moving to a stable 1.0 meaning: bugs fixes and
API additions for missing needed features and no more big modifications, this
will be for other releases, the workload is already big enough.
- BIG improvement on the proxy list merging algorithm, it is not perfect yet (comments aren't handled yet) but it's really a big move forward
- possible retrocompatibility breaking change: from now on the node.find("name") to node.name shortcut ONLY works with possible nodes identifiers. For example node.i_dont_exist_as_an_identifier will raise AttributeError
- new helper method .to_python that wrap ast.literal_eval on compatible nodes https://redbaron.readthedocs.io/en/latest/other.html#to-python
- breaking: IntNode no longer return an int on .value but a .string instead, use .to_python to have an evaluated version
- fix node.decrease_indentation (that was simply not working)
- fix code_block_node.value was broken on node with no parent
- add string representation for Path object
- now redbaron Path() class can be compared directly to baron paths
without using to_baron_path() helper.
- fix by novocaine: 'function' was used as a function type detector instead of 'def'
- add getitem() method with same api on NodeList and ProxyList
- fix: inconsistencies when inserting lines around code blocks
- inserting a blank lines inserts effectively a \n in a LineProxyList
- new helper methods: .next_recursive and .previous_recursive https://redbaron.readthedocs.io/en/latest/other.html
- fix: doc is tested in CI now, it shouldn't break anymore
- more rendering test for python3, it shouldn't break anymore
- pygments is now an optional dependency, "pip install redbaron" won't install it, "pip install redbaron[pygments"] will
- new node.next_intuitive and node.previous_intuitive methods for situations where .next/previous doesn't behave the way the user expect it https://redbaron.readthedocs.io/en/latest/other.html#next-intuitive-previous-intuitive
0.5.1 (2015-03-11)
- fix whitespace duplication when using .insert()
- DecoratorProxyList of the last method of a function wasn't handling correctly the indentation of its last endl token
0.5 (2015-01-31)
0.4 (2014-12-11)
- compatibility with baron upstream (removal of def_argument_node and
uniformisation of def_arguments structure)
- fix: long wasn't supported in redbaron (due to a bug in baron)
0.3 (2014-11-12)
- proxy lists, major improvement in the management of list of things
- .append_value is no more since it is useless now due to proxy lists
- .index has been renamed to .index_on_parent to be more coherent
0.2 (2014-09-23)
0.1 (2014-06-13)