Metadata-Version: 2.1
Name: fun-with-ast
Version: 0.1.70
Summary: 
Author: Shai Rubin
Author-email: shai@ownbackup.com
Requires-Python: >=3.10,<4.0
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Description-Content-Type: text/markdown

# Fun with AST
Provides developers with a programmatic tool to change our own code.
This repository contains a library to analyze and manipulate python code using [Abstract Systax Tress](https://docs.python.org/3/library/ast.html) manipulation. 

## Using the library
See the [test-fun-with-ast](https://github.com/shairubin/test-fun-with-ast) project for examples of using the fun-with-ast library.


## Why Fun-with-AST
1. Here is a [talk](https://docs.google.com/presentation/d/e/2PACX-1vQTQQNaUPs7UNO_skE5vxBxaYbu6box99g_DnYYOuXuIKUqxI-_XEMxQ3p0_CBNlE6V9F3NzpOaXzUJ/pub?start=true&loop=false&delayms=30000)
I gave in Pycon 2023. It explains the capabilities of fun-with-ast.
2. It is a great learning personal development experience. 
3. Enables smart and complex manipulations 


## Examples: AST Parse vs. AST Unparse vs. fun-with-ast Source Code Preserver
The examples below show an original program that first was unparsed with 
python ast module, 
and then was unparsed using the fun-with-ast library. The actual code that generates 
these example can be found in the [test-fun-with-ast](https://github.com/shairubin/test-fun-with-ast) 
library. 

1. [Parse-Unparse Fibonacci Calculator](./docs/parse_vs_unparse_vs_fwa.pdf)
## Potential usages:
- Fun #1: Keep source to source transformations
- Fun #2: switch `else` / `if` bodies  
- Fun #3: mutation testing switch `<` into `<=`
- Fun #4: Switch `For` to `While` 
- Fun #5: for loop into tail recursion. 
- Fun #7: Add node AND comment.

## How to Contribute
1. Follow the steps in  [Contribute to projects](https://docs.github.com/en/get-started/quickstart/contributing-to-projects).
2. You can chose an existing open issue or open a new one.
3. Start working .... 
4. Before submitting a pull request make sure tests are [passing](#how-to-run-tests).

## How to Run Tests
1. In `fun-with-ast` we use pytest.
2. Use your IDE to run all tests in `tests` directory. 
3. OR, use command line:
   1. `cd <your path to fun-with-ast fork>/fun_with_ast/tests`
   2. `pytest --version`, should be at least `7.2.2`
   3.  run `pytest`
   4.  No tests should fail - some tests would be skipped / xfail. 

