Skip to main content

Turn hard-coded variables into dynamic ones without refactoring.

Project description

softshell

Turn hard-coded variables into dynamic ones without refactoring.

This module allows you to run a script where you replace hard-coded variable assignments with a list of values. For example, suppose we have some script (add.py) that looks like this:

PARAM=2

def add(x, y=2):
    return x + y

print("Adding {} to 2".format(PARAM))
print(add(PARAM))

Without changing anything in add.py, you just create some configuration (config.yml) file like the following:

---
path: add.py
configurations:
    - line_number: 1
      variable: PARAM
      value: [1, 2, 3]

And then run this:

$ softshell -f config.yml python add.py

[{'configurations': [{'line_number': 1,
                      'value': [1, 2, 3],
                      'variable': 'PARAM'}],
  'path': 'add.py'}]
Going through edit 1/3
Configuration is: [('add.py', [(1, 'PARAM', 1)])]
Logs can be found here: /var/folders/km/41mjphdd6553jdjjf32y9jkh0000gn/T/tmp7sr_umua
Going through edit 2/3
Configuration is: [('add.py', [(1, 'PARAM', 2)])]
Logs can be found here: /var/folders/km/41mjphdd6553jdjjf32y9jkh0000gn/T/tmpn5y4b48c
Going through edit 3/3
Configuration is: [('add.py', [(1, 'PARAM', 3)])]
Logs can be found here: /var/folders/km/41mjphdd6553jdjjf32y9jkh0000gn/T/tmpo4vlz7e3

You will see three separate log files, each showing the result where we set PARAM to 1, 2, 3, respectively:

$ cat /var/folders/km/41mjphdd6553jdjjf32y9jkh0000gn/T/tmp7sr_umua
Configuration is: [('add.py', [(1, 'PARAM', 1)])]
Adding 1 to 2
3
$ cat /var/folders/km/41mjphdd6553jdjjf32y9jkh0000gn/T/tmpn5y4b48c
Configuration is: [('add.py', [(1, 'PARAM', 2)])]
Adding 2 to 2
4
$ cat /var/folders/km/41mjphdd6553jdjjf32y9jkh0000gn/T/tmpo4vlz7e3
Configuration is: [('add.py', [(1, 'PARAM', 3)])]
Adding 3 to 2
5

More examples can be found in the examples directory

Installation

$ pip install softshell

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

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

Source Distribution

softshell-0.1.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

softshell-0.1-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file softshell-0.1.tar.gz.

File metadata

  • Download URL: softshell-0.1.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.2

File hashes

Hashes for softshell-0.1.tar.gz
Algorithm Hash digest
SHA256 5c49fac530c7ff290d1f9b255b7e4b9409c84faeb9dfe7debc43f74af08e94f8
MD5 78b0fa7d39f54abcf9b42c935f508c97
BLAKE2b-256 d19a01a2a02f8065a83e2a6fea4abc295032bebbec022dde7208d3cb88155d4c

See more details on using hashes here.

File details

Details for the file softshell-0.1-py3-none-any.whl.

File metadata

  • Download URL: softshell-0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.2

File hashes

Hashes for softshell-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 30e73829b5b02081137a8b51c152d66668c7e5a5f57b49829abbafd58589b137
MD5 86953b929f6148696d12b0b694b13683
BLAKE2b-256 0e26b785d1bccb90d79e73e163a2807c5b60058ee10eb175bece679974b5eac7

See more details on using hashes here.

Supported by

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