Skip to main content

Abstraction on top of baron, a FST for python to make writing refactoring code a realistic task

Project description

Introduction

Build Status Latest Version Supported Python versions Development Status Wheel Status Download format License

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 an 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 a 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.

Disclamer: RedBaron (and baron) is working with python3 but it NOT fully parsing it yet.

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

Changelog

0.6 (unreleased)

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 compatibile nodes https://redbaron.readthedocs.org/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.org/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 dependancy, “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 http://redbaron.readthedocs.org/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)

  • First release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

redbaron-0.6.tar.gz (5.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

redbaron-0.6-py2.py3-none-any.whl (9.3 kB view details)

Uploaded Python 2Python 3

redbaron-0.6-py2.7.egg (4.9 kB view details)

Uploaded Egg

File details

Details for the file redbaron-0.6.tar.gz.

File metadata

  • Download URL: redbaron-0.6.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for redbaron-0.6.tar.gz
Algorithm Hash digest
SHA256 533ce5ac09ec0d41b4e2f691252d6d4e71ab66afdba68f6fa73f8d75169ecc2f
MD5 8e58eb9dac4cc2d6bcbd9fa45eff6974
BLAKE2b-256 22bf27fb3a0b7aab26dafe4078cc5a43bf8085697f0a21faab349be51c9f3860

See more details on using hashes here.

File details

Details for the file redbaron-0.6-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for redbaron-0.6-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e8ce67f265253859cc14ec34128d9ad8eb441acd4a357db32ec2e90ce50e84c7
MD5 8ce0d3800d2af7cf0fef5d0bb7a88154
BLAKE2b-256 e2ed277a1fa1ef4cf607c997f36e1b29b5b0554579b42a99753ed78b5ee129e9

See more details on using hashes here.

File details

Details for the file redbaron-0.6-py2.7.egg.

File metadata

  • Download URL: redbaron-0.6-py2.7.egg
  • Upload date:
  • Size: 4.9 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for redbaron-0.6-py2.7.egg
Algorithm Hash digest
SHA256 3290a8f70a251026d91100cf866e463c6c29aeb262bcbe8569699b33df8557a2
MD5 27bbf73fcdb54de242f8b6a149717d68
BLAKE2b-256 8a3360e541380cf0385f75c7f9a690c1c8c806aaedcf4ae3bfa425a634117628

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page