Skip to main content

image

Mamushi

image Build Status codecov License: MIT Code style: black

Mamushi is a fork of the popular Black formatter adapted to the Vyper programming language. Mamushi reformats your Vyper contracts in a readable and consistent way.

Installation

pip install mamushi

Usage

Search all *.vy files and overwrite them after formatting:

mamushi

Specify a list of *.vy files or directories and output to console after formatting:

mamushi [SRC]

Output the result to console instead of overwriting:

mamushi --in-place False

pre-commit

Add to your .pre-commit-config.yaml:

repos:
  - repo: https://github.com/benber86/mamushi
    rev: main
    hooks:
      - id: mamushi
        args: [ --line-length=100 ]

Notes

Line length

The default line length is 80. Line length can be adjusted by using the --line-length option.

AST Safety

By default, mamushi will compare the AST of your reformatted code with that of the original to ensure that the changes applied remain strictly formal. The option can be disabled with --safe False to speed things up.

Trailing commas

When handling expressions split by commas, mamushi follows Black's default behavior.

Mamushi also uses Black's magic trailing comma to give user the option to collapse a comma-separated expression into one line if possible. If a trailing comma is added, mamushi will always explode the expression. This can have important consequences for the commenting of your code. Consider the following two examples:

This code snippet:

self.b(0, # amount to send
       msg.sender, # sender
       True, # refund ?
        )

formats to the following with a trailing comma after the last argument (True):

self.b(
    0,  # amount to send
    msg.sender,  # sender
    True,  # refund ?
)

Disabling formatting

Mamushi supports # fmt: off and # fmt: on tags to disable formatting for specific regions of code:

x: uint256 = 1

# fmt: off
y:    uint256     =     2    # preserve this spacing
z:uint256=3
# fmt: on

a: uint256 = 4  # this will be formatted normally

The code between # fmt: off and # fmt: on will be preserved exactly as written, including all spacing and line breaks. These tags can be nested, and unclosed # fmt: off regions will extend to the end of the file.

You can also use # nosplit on individual lines to prevent line splitting while still applying spacing normalization:

assert not self.user[receiver][msg.sender], "Error message"  # nosplit

Note: # fmt: skip is not currently supported.

but if the trailing comma is removed, the line will be collapsed to:

self.b(0, msg.sender, True)  # amount to send  # sender  # refund ?

Future developments

  • Multiprocessing when processing multiple files
  • Configuration files
  • Improve Windows compatibility
  • Handle versioning of Vyper/lark grammar
  • Refactoring comment handling in the parser
  • Add .gitignore / exclude / include support

Download files

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

Source Distribution

mamushi-0.1.2.tar.gz (48.1 kB view details)

Uploaded Source

Built Distribution

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

mamushi-0.1.2-py3-none-any.whl (50.0 kB view details)

Uploaded Python 3

File details

Details for the file mamushi-0.1.2.tar.gz.

File metadata

  • Download URL: mamushi-0.1.2.tar.gz
  • Upload date:
  • Size: 48.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mamushi-0.1.2.tar.gz
Algorithm Hash digest
SHA256 e9303f56c566eb2bc0a039ba638eb97c03637bf5ecf3b4e9be91fb2bb1ff8d1f
MD5 a2977c43393a9532c58cc8fe2f362d74
BLAKE2b-256 21c5a5988cb549c4210b6ce682905c78da0e1a289dc1ca8cbde0c08c49645d53

See more details on using hashes here.

Provenance

The following attestation bundles were made for mamushi-0.1.2.tar.gz:

Publisher: publish-pypi.yml on benber86/mamushi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mamushi-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: mamushi-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 50.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mamushi-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ab4a2a7cb975718f69d17964f59b560f10e405821d9bf3487908bba56b178f72
MD5 0a0a2f844cd7c5f8839bbc0b832a9294
BLAKE2b-256 4072d68bb1b036201b8c21a58c11fbcc0538a4709955623cf1c0b5520e842a9e

See more details on using hashes here.

Provenance

The following attestation bundles were made for mamushi-0.1.2-py3-none-any.whl:

Publisher: publish-pypi.yml on benber86/mamushi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 files

0.1.1

2 files

0.1.0

2 files

0.0.9

2 files

0.0.8

2 files

0.0.7

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

Supported by

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