cambio
Change Python Source Code Files
methods
- remove_comments
- remove_imports
- declare_variable
- replace_class
- replace_variable_declaration
- remove_class_instantiation_parameter
- add_param_to_class_instantiation
- remove_class_definition
usage
Remove Comments
from cambio import remove_comments
with open("example.py") as f:
text = f.read()
text = remove_comments(text)
with open("example_without_comments.py", "w") as f:
f.write(text)
cambio example.py remove-comments
Remove Imports
from cambio import remove_imports
with open("example.py") as f:
text = f.read()
text = remove_imports(text)
with open("example_without_imports.py", "w") as f:
f.write(text)
cambio example.py remove-imports
Declare Variable
from cambio import declare_variable
from django.utils.crypt import get_random_string
with open("settings.py") as f:
text = f.read()
text = declare_variable(text, "SECRET_KEY", get_random_string())
with open("settings.py", "w") as f:
f.write(text)
cambio settings.py declare-variable "SECRET_KEY" "$(uuidgen)"
Replace Class
from cambio import replace_class
code = "my_fruit = Apple()"
new_code = replace_class(code, "Apple", "Orange")
print(new_code)
# my_smoothie = Orange()
cambio juicer.py replace-class "Apple" "Orange"
Replace Variable Declaration
from cambio import replace_variable_declaration
code = "HTTP_ORIGIN = 'http://localhost:8000'"
new_code = replace_variable_declaration('HTTP_ORIGIN', 'http://localhost:4200')
print(new_code)
# HTTP_ORIGIN = 'http://localhost:4200'
cambio settings.py replace-declaration 'HTTP_ORIGIN' 'http://localhost:4200'
Remove Class Instantiation Parameter
from cambio import remove_class_instantiation_parameter
old_code = "my_drink = Wine(age=100)"
new_code = remove_class_instantiation_parameter(old_code, 'Wine', 'age')
print(new_code)
# my_drink = Wine()
cambio settings.py
Conditionally Remove Class Instantiation Parameter
from cambio import remove_class_instantiation_parameter
old_code = "bottle_1 = Wine(age=100)\nbottle_2 = Wine(age=1)"
# removes all bottles under 10 years of age
new_code = remove_class_instantiation_parameter(old_code, 'Wine', 'age', lambda age: age < 10)
print(new_code)
# bottle_1 = Wine(age=100)\n
cambio settings.py
Add Parameter to Class Instantiation
from cambio import add_param_to_class_instantiation
old_code = "[Food(type='Cereal')\n, Fruit(type='Cheese')]"
def get_expiration(instantiation):
text = instantiation['text']
if 'Cereal' in text:
return 10
elif 'Cheese' in text:
return 1
# age cars by one year
add_param_to_class_instantiation(old_code, "Fruit", "expiration", get_expiration)
Remove Class Definition
from cambio import remove_class_definition
old_code = '''
class OldCar():
a = 1
b = 2
class NewCar():
a = 1
b = 2
'''
new_code = remove_class_definition(old_code, "OldCar")
cambio example.py remove-class-definition 'OldCar'
Testing
To test the package run
python3 -m unittest cambio.tests.test
Support
Contact the Library Author, Daniel J. Dufour, or post an issue at https://github.com/danieljdufour/cambio/issues
Metadata
Release files for cambio 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cambio-0.0.4.tar.gz | 5.6 kB | Without provenance | Details for cambio-0.0.4.tar.gz |
Release files / cambio-0.0.4.tar.gz
| Download URL | cambio-0.0.4.tar.gz |
|---|---|
| Size | 5.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
af59be88f18aaac3dffa9ffefb1ad8b0a4d9dd802f52841a62ce974a01cf73c5
|
|
BLAKE2b-256 checksum How to use checksums |
4d0c715506cd872458d8e90e22b411453a34fccd48820218a5bf2797268ecf59
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/44.1.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/2.7.17
|
Security for cambio 0.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.