How to use the setupmeta.run_program function in setupmeta

To help you get started, we’ve selected a few setupmeta examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zsimic / setupmeta / tests / test_versioning.py View on Github external
def test_brand_new_project():
    with setupmeta.temp_resource():
        conftest.run_git("init")
        with open("setup.py", "w") as fh:
            fh.write(SAMPLE_EMPTY_PROJECT)

        # Test that we avoid warning about no tags etc on brand new empty git repos
        output = setupmeta.run_program(sys.executable, "setup.py", "--version", capture="all")
        output = conftest.cleaned_output(output)
        assert output == "0.0.0"
github zsimic / setupmeta / tests / scenarios.py View on Github external
os.makedirs(self.origin)
        self.run_git("init", "--bare", self.origin, cwd=self.temp)
        self.run_git("clone", self.origin, self.target, cwd=self.temp)
        copytree(self.folder, self.target)

        for command in self.preparation:
            if command.startswith("mv"):
                # Unfortunately there is no 'mv' on Windows
                _, source, dest = command.split()
                source = os.path.join(self.target, source)
                dest = os.path.join(self.target, dest)
                shutil.copytree(source, dest)
                shutil.rmtree(source)

            else:
                setupmeta.run_program(*command.split(), cwd=self.target)

        self.run_git("add", ".")
        self.run_git("commit", "-m", "Initial commit")
        self.run_git("push", "origin", "master")
        self.run_git("tag", "-a", "v1.2.3", "-m", "Initial tag at v1.2.3")
        self.run_git("push", "--tags", "origin", "master")
github zsimic / setupmeta / tests / test_content.py View on Github external
def test_run_program():
    setupmeta.DEBUG = True
    with conftest.capture_output() as out:
        assert setupmeta.run_program("ls", capture=True, dryrun=True) is None
        assert setupmeta.run_program("ls", capture=False, dryrun=True) == 0
        assert setupmeta.run_program("ls", "foo/does/not/exist", capture=None) != 0
        assert setupmeta.run_program("pip", "--version", capture=True)
        assert setupmeta.run_program("pip", "foo bar", capture=True) == ""
        assert "unknown command" in setupmeta.run_program("pip", "foo bar", capture="all")
        assert setupmeta.run_program("/foo/does/not/exist", capture=True, dryrun=True) is None
        assert setupmeta.run_program("/foo/does/not/exist", capture=False) != 0

        with pytest.raises(SystemExit):
            setupmeta.run_program("/foo/does/not/exist", fatal=True)

        with pytest.raises(SystemExit):
            assert setupmeta.run_program("ls", "foo/does/not/exist", fatal=True)

        assert "exitcode" in out

    setupmeta.DEBUG = False
github zsimic / setupmeta / tests / test_content.py View on Github external
def test_run_program():
    setupmeta.DEBUG = True
    with conftest.capture_output() as out:
        assert setupmeta.run_program("ls", capture=True, dryrun=True) is None
        assert setupmeta.run_program("ls", capture=False, dryrun=True) == 0
        assert setupmeta.run_program("ls", "foo/does/not/exist", capture=None) != 0
        assert setupmeta.run_program("pip", "--version", capture=True)
        assert setupmeta.run_program("pip", "foo bar", capture=True) == ""
        assert "unknown command" in setupmeta.run_program("pip", "foo bar", capture="all")
        assert setupmeta.run_program("/foo/does/not/exist", capture=True, dryrun=True) is None
        assert setupmeta.run_program("/foo/does/not/exist", capture=False) != 0

        with pytest.raises(SystemExit):
            setupmeta.run_program("/foo/does/not/exist", fatal=True)

        with pytest.raises(SystemExit):
            assert setupmeta.run_program("ls", "foo/does/not/exist", fatal=True)

        assert "exitcode" in out

    setupmeta.DEBUG = False
github zsimic / setupmeta / tests / test_content.py View on Github external
setupmeta.DEBUG = True
    with conftest.capture_output() as out:
        assert setupmeta.run_program("ls", capture=True, dryrun=True) is None
        assert setupmeta.run_program("ls", capture=False, dryrun=True) == 0
        assert setupmeta.run_program("ls", "foo/does/not/exist", capture=None) != 0
        assert setupmeta.run_program("pip", "--version", capture=True)
        assert setupmeta.run_program("pip", "foo bar", capture=True) == ""
        assert "unknown command" in setupmeta.run_program("pip", "foo bar", capture="all")
        assert setupmeta.run_program("/foo/does/not/exist", capture=True, dryrun=True) is None
        assert setupmeta.run_program("/foo/does/not/exist", capture=False) != 0

        with pytest.raises(SystemExit):
            setupmeta.run_program("/foo/does/not/exist", fatal=True)

        with pytest.raises(SystemExit):
            assert setupmeta.run_program("ls", "foo/does/not/exist", fatal=True)

        assert "exitcode" in out

    setupmeta.DEBUG = False
github zsimic / setupmeta / setupmeta / scm.py View on Github external
def get_output(self, *args, **kwargs):
        """
        Run SCM's CLI program with 'args' and optional additional 'kwargs' (passed through to subprocess.Popen)
        Command is ran with cwd being 'self.root'

        :param args: CLI arguments (example: describe --tags)
        :param kwargs: Additional named arguments
        :return str|int: Output if kwargs['capture'] is True, exit code otherwise
        """
        capture = kwargs.pop("capture", True)
        cwd = kwargs.pop("cwd", self.root)
        return setupmeta.run_program(self.program, *args, capture=capture, cwd=cwd, **kwargs)
github zsimic / setupmeta / setupmeta / commands.py View on Github external
print("%s dependencies in %s" % (len(reqs), self.requirements))
        if reqs:
            with setupmeta.temp_resource():
                easy_install = os.path.join(os.path.dirname(sys.executable), "easy_install")
                common_args = ["-zax", "-d", "."]
                index_url = get_pip_config("global.index-url")
                if index_url:  # pragma: no cover, only applicable if one has configured index url
                    common_args.append("-i")
                    common_args.append(index_url)

                env = dict(os.environ)
                env["PYTHONPATH"] = "."
                for req in reqs:
                    args = common_args[:]
                    args.append(req)
                    setupmeta.run_program(easy_install, *args, env=env)

                eggs = [f for f in os.listdir(".") if f.endswith(".egg")]
                print("Fetched %s eggs" % len(eggs))
                for name in eggs:
                    dest = os.path.join(egg_target, name)
                    if os.path.exists(dest):  # pragma: no cover
                        print("%s/%s already exists, skipping" % (self.dist, name))
                        continue

                    source = name
                    action = "Grabbed"
                    if os.path.isdir(source):
                        # This disregards any `zip_safe=False` setting, this could be wrong
                        # However, most libraries don't specify this, even though their project is zip-safe...
                        # Spark users seem to get by with eggs just fine, so forcing a zip here
                        action = "Force-zipped"
github zsimic / setupmeta / setupmeta / versioning.py View on Github external
if not push:
            print("Not pushing bump, use --push to push")

        vdefs = self.meta.definitions.get("version")
        if vdefs:
            self.update_sources(next_version, commit, push, vdefs)

        self.scm.apply_tag(commit, push, next_version, branch)

        if not self.strategy.hook:
            return

        hook = setupmeta.project_path(self.strategy.hook)
        if setupmeta.is_executable(hook):
            setupmeta.run_program(hook, self.meta.name, branch, next_version, fatal=True, dryrun=not commit, cwd=setupmeta.project_path())