def get_suitability(self): try: run_command("git status") except ShellCommandError: return 0 return 1
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()
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"
def push(self): run_command("git push") run_command("git push --tags")
def tag(self, version): name = self.make_tag_name(version) run_command("git tag %s" % quote(name))
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))
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)
def add(self, file_path): run_command("git add %s" % quote(file_path))
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)))