code: def build(args):
      if os.path.exists(args.build_dir):
          sys.stderr.write(
              "Please remove the build directory %s before proceeding, or specify a different path with --build-dir.\n"
              % args.build_dir
          )
          sys.exit(-1)
      if os.path.exists(args.pkg_dir):
          sys.stderr.write(
              "Please remove the package directory %s before proceeding, or specify a different path with --pkg-dir.\n"
              % args.pkg_dir
          )
          sys.exit(-1)
  
      # Clone source repository and tag the release branch
      shell(
          """
          # Clone and merge release branch into previous master
          mkdir -p {build_dir}
          cd {build_dir}
          rm -rf pyqtgraph
          git clone --depth 1 --branch master --single-branch {source_repo} pyqtgraph
          cd pyqtgraph
          git checkout -b release-{version}
          git pull {source_repo} release-{version}
          git checkout master
          git merge --no-ff --no-commit release-{version}
          
          # Write new version number into the source
          sed -i "s/__version__ = .*/__version__ = '{version}'/" pyqtgraph/__init__.py
          sed -i "s/version = .*/version = '{version}'/" doc/source/conf.py
          sed -i "s/release = .*/release = '{version}'/" doc/source/conf.py
          
          # make sure changelog mentions unreleased changes
          grep "pyqtgraph-{version}.*unreleased.*" CHANGELOG    
          sed -i "s/pyqtgraph-{version}.*unreleased.*/pyqtgraph-{version}/" CHANGELOG
  
          # Commit and tag new release
          git commit -a -m "PyQtGraph release {version}"
          git tag pyqtgraph-{version}
  
          # Build HTML documentation
          cd doc
              make clean
              make html
          cd ..
          find ./ -name "*.pyc" -delete
  
          # package source distribution
          python setup.py sdist
  
          mkdir -p {pkg_dir}
          cp dist/*.tar.gz {pkg_dir}
  
          # source package build complete.
      """.format(
              **args.__dict__
          )
      )
  
      if args.skip_pip_test:
          args.pip_test = "skipped"
      else:
          shell(
              """
              # test pip install source distribution
              rm -rf release-{version}-virtenv
              virtualenv --system-site-packages release-{version}-virtenv
              . release-{version}-virtenv/bin/activate
              echo "PATH: $PATH"
              echo "ENV: $VIRTUAL_ENV" 
              pip install --no-index --no-deps dist/pyqtgraph-{version}.tar.gz
              deactivate
              
              # pip install test passed
          """.format(
                  **args.__dict__
              )
          )
          args.pip_test = "passed"
  
      if "linux" in sys.platform and not args.no_deb:
          shell(
              """
              # build deb packages
              cd {build_dir}/pyqtgraph
              python setup.py --command-packages=stdeb.command sdist_dsc
              cd deb_dist/pyqtgraph-{version}
              sed -i "s/^Depends:.*/Depends: python (>= 2.6), python-qt4 | python-pyside, python-numpy/" debian/control    
              dpkg-buildpackage
              cd ../../
              mv deb_dist {pkg_dir}/pyqtgraph-{version}-deb
              
              # deb package build complete.
          """.format(
                  **args.__dict__
              )
          )
          args.deb_status = "built"
      else:
          args.deb_status = "skipped"
  
      if not args.no_exe:
          shell(
              """
              # Build windows executables
              cd {build_dir}/pyqtgraph
              python setup.py build bdist_wininst --plat-name=win32
              python setup.py build bdist_wininst --plat-name=win-amd64
              cp dist/*.exe {pkg_dir}
          """.format(
                  **args.__dict__
              )
          )
          args.exe_status = "built"
      else:
          args.exe_status = "skipped"
  
      print(
          unindent(
              """
  
      ======== Build complete. =========
  
        * Source package:     built
        * Pip install test:   {pip_test}
        * Debian packages:    {deb_status}
        * Windows installers: {exe_status}
        * Package files in    {pkg_dir}
  
      Next steps to publish:
      
        * Test all packages
        * Run script again with --publish
  
      """
          ).format(**args.__dict__)
      )
  
imports: import os, sys, argparse, random
  from shell import shell, ssh
label_desc: Use image node_id 1 for calling a global function with example usage: build(args) without return types