示例#1
0
文件: git.py 项目: adamgreenhall/seed
 def get_suitability(self):
     try:
         run_command("git status")
     except ShellCommandError:
         return 0
     
     return 1
示例#2
0
    def get_suitability(self):
        try:
            run_command("git status")
        except ShellCommandError:
            return 0

        return 1
示例#3
0
 def get_user_repo(self):
     # Get all remote urls
     output = run_command("git config --get-regexp 'remote\..*\.url'")
     urls = {}
     for line in output.split("\n"):
         matches = re.match(r'remote\.(.*)\.url\s+(.*github\.com.*)', line)
         if matches:
             remote_name, url = matches.groups()
             urls[remote_name] = url
     
     if "origin" in urls:
         url = urls["origin"]
     elif len(urls) == 1:
         url = urls.values()[0]
     else:
         raise VcsCommandError("Could not determine a suitable GitHub remote url. "
                               "This is because you have more than one GitHub remote url "
                               "and none of them are called 'origin'.")
     
     # Parse out into user & repo
     return re.search(r"([a-z0-9-_]+)/([a-z0-9-_]+)", url).groups()
示例#4
0
    def run(self, options, args):
        vcs = get_suitable_vcs()
        previous_version = self.read_version()
        
        if not previous_version:
            raise CommandError("Could not determine version. Make sure your root __init__.py file contains '__version__ = \"1.2.3\"'")
        
        if options.initial:
            # We don't increment the version number for the initial commit
            next_version = previous_version
        else:
            next_version = self.get_next_version(options, previous_version)
        
        print "This release will be version %s" % next_version
        
        # Running checks
        print "Running package sanity checks on setup.py"
        output = run_command("python setup.py check")
        warnings = [l.split("check: ")[1] for l in output.split("\n") if "check: " in l]
        if warnings:
            print "Checks on setup.py failed. Messages were:\n%s" % "\n".join(warnings)
            sys.exit(1)
        
        # Checking pypi login details are in place
        print "Checking we have our PyPi login details in place"
        if not os.path.exists(os.path.expanduser("~/.pypirc")):
            print "Could not find your ~/.pypirc file. See http://seed.readthedocs.org/en/latest/#pypi-registration for help."
            sys.exit(1)
        else:
            print "You have a ~/.pypirc file. Assuming the details in there are correct"

        # Update the version number
        
        if options.dry_run:
            print "Version would be set to %s" % next_version
        else:
            print "Version written"
            self.write_version(next_version)
        
        # Update the changelog
        
        if options.dry_run:
            if options.initial:
                print "Would have written the initial version to the changelog"
            else:
                changes = vcs.get_changes(previous_version)
                print "Would have written %d changes to changelog" % len(changes)
        else:
            print "Updating changelog"
            if options.initial:
                self.write_changelog([], "%s (first version)" % next_version)
            else:
                changes = vcs.get_changes(previous_version)
                self.write_changelog(changes, next_version)
        
        # Commit the changes we have made
        
        commit_files = [self.project_dir / "CHANGES.txt", self.package_dir / "__init__.py"]
        if options.dry_run:
            print "Would have committed changes to: %s" % ", ".join(commit_files)
        else:
            print "Committing changes"
            vcs.commit("Version bump to %s and updating CHANGES.txt" % next_version, commit_files)
        
        # Now do the tag
        if options.dry_run:
            print "Would have created a tag for version %s" % next_version
        else:
            print "Tagging new version"
            vcs.tag(next_version)
        
        if options.push and hasattr(vcs, "push"):
            if options.dry_run:
                print "Would have pushed changes"
            else:
                print "Pushing changes"
                vcs.push()        
        
        # Now register/upload the package
        if options.dry_run:
            print "Would have updated PyPi"
        else:
            print "Uploading to PyPi"
            print "(This may take a while, grab a cuppa. You've done a great job!)"
            if options.initial or options.register:
                run_command("python setup.py register sdist upload")
            else:
                run_command("python setup.py sdist upload")
        
        print "All done!"
        if not options.dry_run and not options.push:
            print "We have made changes, but not pushed. Git users should probably do: "
            print "    git push && git push --tags"
示例#5
0
文件: git.py 项目: adamgreenhall/seed
 def push(self):
     run_command("git push")
     run_command("git push --tags")
示例#6
0
文件: git.py 项目: adamgreenhall/seed
 def tag(self, version):
     name = self.make_tag_name(version)
     run_command("git tag %s" % quote(name))
示例#7
0
文件: git.py 项目: adamgreenhall/seed
 def commit(self, message, files):
     quoted_files = " ".join(map(quote, files))
     run_command("git add %s" % quoted_files)
     run_command("git commit -m %s %s" % (quote(message), quoted_files))
示例#8
0
文件: git.py 项目: adamgreenhall/seed
 def get_changes(self, since_version):
     log_range = "%s..HEAD" % self.make_tag_name(since_version)
     commits = run_command("git log --pretty=short %s" % quote(log_range))
     
     return self.parse_log_messages(commits)
示例#9
0
文件: git.py 项目: adamcharnock/seed
 def add(self, file_path):
     run_command("git add %s" % quote(file_path))
示例#10
0
    def run(self, options, args):
        vcs = get_suitable_vcs()
        previous_version = self.read_version()

        if not previous_version:
            raise CommandError(
                "Could not determine version. Make sure your root __init__.py file contains '__version__ = \"1.2.3\"'"
            )

        if options.initial:
            # We don't increment the version number for the initial commit
            next_version = previous_version
        else:
            next_version = self.get_next_version(options, previous_version)

        print("This release will be version %s" % next_version)

        # Running checks
        print("Running package sanity checks on setup.py")
        output = run_command("python setup.py check")
        warnings = [
            l.split("check: ")[1] for l in output.split("\n") if "check: " in l
        ]
        if warnings:
            print("Checks on setup.py failed. Messages were:\n%s" %
                  "\n".join(warnings))
            sys.exit(1)

        # Checking pypi login details are in place (if we need them)
        if not options.no_release:
            print("Checking we have our PyPi login details in place")
            if not os.path.exists(os.path.expanduser("~/.pypirc")):
                print(
                    "Could not find your ~/.pypirc file. See http://seed.readthedocs.org/en/latest/#pypi-registration for help."
                )
                sys.exit(1)
            else:
                print(
                    "You have a ~/.pypirc file. Assuming the details in there are correct"
                )

        # Update the version number

        if options.dry_run:
            print("Version would be set to %s" % next_version)
        else:
            print("Version written")
            self.write_version(vcs, next_version)

        # Update the changelog

        if options.dry_run:
            if options.initial:
                print(
                    "Would have written the initial version to the changelog")
            else:
                changes = vcs.get_changes(previous_version)
                print("Would have written %d changes to changelog" %
                      len(changes))
        else:
            print("Updating changelog")
            if options.initial:
                self.write_changelog([], "%s (first version)" % next_version)
            else:
                changes = vcs.get_changes(previous_version)
                self.write_changelog(changes, next_version)

        # Commit the changes we have made

        commit_files = [
            self.project_dir / "CHANGES.txt",
            self.project_dir / "VERSION",
            self.project_dir / "MANIFEST.in",
            self.project_dir / "setup.py",
            self.package_dir / "__init__.py",
        ]
        if options.dry_run:
            print("Would have committed changes to: %s" %
                  ", ".join(commit_files))
        else:
            print("Committing changes")
            vcs.commit(
                "Version bump to %s and updating CHANGES.txt" % next_version,
                commit_files)

        # Now do the tag
        if options.dry_run:
            print("Would have created a tag for version %s" % next_version)
        else:
            print("Tagging new version")
            vcs.tag(next_version)

        if options.push and hasattr(vcs, "push"):
            if options.dry_run:
                print("Would have pushed changes")
            else:
                print("Pushing changes")
                vcs.push()

        # Now register/upload the package
        if options.no_wheel:
            setup_args = "sdist"
        else:
            setup_args = "sdist bdist_wheel"
        if options.no_release:
            if options.dry_run:
                print("Would build dist but not release to PyPi")
            else:
                print("Build dist, not releasing to PyPi")
                run_command("python setup.py %s" % setup_args)
        else:
            if options.dry_run:
                print("Would have updated PyPi")
            else:
                print("Uploading to PyPi")
                print(
                    "(This may take a while, grab a cuppa. You've done a great job!)"
                )
                if options.initial or options.register:
                    run_command("python setup.py register %s upload" %
                                setup_args)
                else:
                    run_command("python setup.py %s upload" % setup_args)

        print("All done!")
        if not options.dry_run:
            if not options.push:
                print(
                    "We have made changes, but not pushed. Git users should probably do: "
                )
                print("    git push && git push --tags")
            if options.no_release:
                print(
                    "Package was not released (as requested). You can find your package here:"
                )
                print("    %s" % (self.project_dir / 'dist' / '%s-%s.tar.gz' %
                                  (self.project_name, next_version)))
示例#11
0
 def add(self, file_path):
     run_command("git add %s" % quote(file_path))
示例#12
0
 def push(self):
     run_command("git push")
     run_command("git push --tags")
示例#13
0
 def tag(self, version):
     name = self.make_tag_name(version)
     run_command("git tag %s" % quote(name))
示例#14
0
 def commit(self, message, files):
     quoted_files = " ".join(map(quote, files))
     run_command("git add %s" % quoted_files)
     run_command("git commit -m %s %s" % (quote(message), quoted_files))
示例#15
0
    def get_changes(self, since_version):
        log_range = "%s..HEAD" % self.make_tag_name(since_version)
        commits = run_command("git log --pretty=short %s" % quote(log_range))

        return self.parse_log_messages(commits)