Skip to main content

A python variant of the redo build system, with which You Can (Not) Redo.

Project description

dp-redo

A python variant of the redo build system, with which You Can (Not) Redo.

Example

Let's say we have a build process where we read test.c and generate test.o:

import os, sys
source_tree = os.path.dirname(os.path.abspath(sys.argv[0]))

def test():
    source = os.path.join(source_tree, "test.c")

    # The simplest compiler 😁
    os.system("cat {} > {}".format(source, "test.o"))

if __name__ == "__main__":
    test()

test will be run every time no matter whether test.c gets an update or not, which wastes much time. Now let's add some magic:

from dp_redo import *
import os, sys

source_tree = os.path.dirname(os.path.abspath(sys.argv[0]))

@do("test.o")
def test(target_name, target_base_name, output_path):
    redo_ifchange("test.c")
    source = os.path.join(source_tree, "test.c")
    os.system("cat {} > {}".format(source, output_path))

if __name__ == "__main__":
    redo_ifchange(test)

If you run it multiple times:

PS C:\Users\lishengq\source\repos\dp-redo\build> python ..\test2.py
Redoing target: test
PS C:\Users\lishengq\source\repos\dp-redo\build> python ..\test2.py
Skipping target test: it's up to date.

Fantastic, isn't it? If you changed test.c, modified the test method itself, or deleted test.o, test will be executed again:

PS C:\Users\lishengq\source\repos\dp-redo\build> python ..\test2.py
Redoing target: test. Reason: It's python code has changed
PS C:\Users\lishengq\source\repos\dp-redo\build> python ..\test2.py
Redoing target: test. Reason: The target file doesn't exist
PS C:\Users\lishengq\source\repos\dp-redo\build> python ..\test2.py
Redoing target: test. Reason: test.c has been modified
PS C:\Users\lishengq\source\repos\dp-redo\build> 

A target method can also depend on another method, which is rather simple:

from dp_redo import *
import os, sys

source_tree = os.path.dirname(os.path.abspath(sys.argv[0]))

@do("test2.o")
def test2(target_name, target_base_name, output_path):
    os.system("echo test2 > " + output_path)

@do("test.o")
def test(target_name, target_base_name, output_path):
    redo_ifchange(test2, "test.c")
    source = os.path.join(source_tree, "test.c")
    os.system("cat {} > {}".format(source, output_path))

if __name__ == "__main__":
    redo_ifchange(test)

What makes redo more interesting is that, you can call redo_ifchange to add dependencies at any time, even after your compilation:

from dp_redo import *
import os, sys, re

source_tree = os.path.dirname(os.path.abspath(sys.argv[0]))

@do("test2.o")
def test2(target_name, target_base_name, output_path):
    print("In test2")
    os.system("echo test2 > " + output_path)

@do("test.o")
def test(target_name, target_base_name, output_path):
    redo_ifchange(test2)
    source = os.path.join(source_tree, "test.c")
    os.system("gcc -M -MF test.c.dep -o {} {}".format(output_path, source))

    # Dependent headers given by gcc
    deps = open('test.c.dep', 'r').read().split(": ")[1].strip().split("\\\n")
    redo_ifchange(*deps)

if __name__ == "__main__":
    redo_ifchange(test)

Now when any headers are changed, the build process will be run again.

Project details


Download files

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

Source Distribution

dp-redo-3.0.2.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dp_redo-3.0.2-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file dp-redo-3.0.2.tar.gz.

File metadata

  • Download URL: dp-redo-3.0.2.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.1 CPython/3.7.4

File hashes

Hashes for dp-redo-3.0.2.tar.gz
Algorithm Hash digest
SHA256 da1dc0d5196163c245e59b5e8f714d40766df2b8e5d12a6a8fe832b6592c7255
MD5 b1909dd39d127822401068f39f849a4a
BLAKE2b-256 631b616ace3564c7a074a3863d6e18b2e0764ae7cbf15905efaf1bd12175966b

See more details on using hashes here.

File details

Details for the file dp_redo-3.0.2-py3-none-any.whl.

File metadata

  • Download URL: dp_redo-3.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.1 CPython/3.7.4

File hashes

Hashes for dp_redo-3.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3ed211679688c9eecb9b78c4aa456fbff834b0003fec16dfd9083dda37b0f7f1
MD5 87ec5988a1313fe3940e81bd80c21402
BLAKE2b-256 4f95ee1906ce136e525c0cd45603fe49d0566ed5250ddab2c36d5b4effa49158

See more details on using hashes here.

Supported by

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