Giter Club home page Giter Club logo

amorph's Introduction

Amorph

Package for Python source code transformation.

>>> from amorph import patch_with_closest
>>> source = '''
... def f(a, b):
...    return a + b
... '''
>>> samples = [
... '''
... def f(a, b):
...    return a * b
... ''',
... '''
... def f(a, b):
...    return sum([a for i in range(b)])
... '''
... ]
>>> for patch in patch_with_closest(source, samples):
...     print(patch)
Replace char #26 with '*'

Use cases

Patch with given sample

from amorph import patch_with_sample

patches = patch_with_sample(source, sample)

Specify patch method

Currently diff, tokens and ast methods available. To use ast patching you should run the API server first.

from amorph import patch_with_closest, patch_with_sample, Method

patches = patch_with_sample(source, sample, method=Method.DIFF)
patches = patch_with_closest(source, samples, method=Method.DIFF)

Find closest code

from amorph.utils import find_closest

closest_sample = find_closest(source, sample)

Custom metric

from amorph import patch_with_closest
from amorph.utils import find_closest

def dummy_metric(source, sample):
    return source.count('def') - sample.count('def')

closest_sample = find_closest(source, samples, metric=dummy_metric)
patches = patch_with_closest(source, samples, metric=dummy_metric)

Nested objects

from amorph import patch_with_closest, patch_with_sample
from amorph.utils import find_closest
from operator import itemgetter

source = {'code': 'print(input())'}
samples = [{'code': 'print("Hello World!")'}, {'code': 'print("Bye Bye!")'}]
get_code = itemgetter('code')

closest = find_closest(source, samples, key=get_code)
patches = patch_with_sample(source, closest, key=get_code)
patches = patch_with_closest(source, samples, key=get_code)

amorph's People

Contributors

kostya93 avatar laplab avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

amorph's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.