Skip to content

Latest commit

History

33 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Amorph

Package for Python source code transformation.

>>>fromamorphimportpatch_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)])... '''
... ]
>>>forpatchinpatch_with_closest(source, samples):
... print(patch)
Replacechar#26 with '*'

Use cases

Patch with given sample

fromamorphimportpatch_with_samplepatches=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.

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

Find closest code

fromamorph.utilsimportfind_closestclosest_sample=find_closest(source, sample)

Custom metric

fromamorphimportpatch_with_closestfromamorph.utilsimportfind_closestdefdummy_metric(source, sample):
returnsource.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

fromamorphimportpatch_with_closest, patch_with_samplefromamorph.utilsimportfind_closestfromoperatorimportitemgettersource= {'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)

About

Finds set of patches to transform one code into another

Topics

Resources

Stars

0 stars

Watchers

5 watching

Forks

Releases

Packages

Contributors

Languages