def get_setup_py_name(self): if os.path.exists('setup.py'): # First run egg_info, as that may get rid of some warnings # that otherwise end up in the extracted name, like # UserWarnings. utils.system(utils.setup_py('egg_info')) return utils.system(utils.setup_py('--name')).strip()
def _diff_and_commit(self, commit_msg): diff_cmd = self.vcs.cmd_diff() diff = utils.system(diff_cmd) logger.info("The '%s':\n\n%s\n" % (diff_cmd, diff)) if utils.ask("OK to commit this"): msg = self.data[commit_msg] % self.data commit_cmd = self.vcs.cmd_commit(msg) commit = utils.system(commit_cmd) logger.info(commit)
def is_clean_checkout(self): """Is this a clean checkout? """ head = system("git symbolic-ref --quiet HEAD") # This returns something like 'refs/heads/maurits-warn-on-tag' # or nothing. Nothing would be bad as that indicates a # detached head: likely a tag checkout if not head: # Greetings from Nearly Headless Nick. return False if system("git status --short --untracked-files=no"): # Uncommitted changes in files that are tracked. return False return True
def get_setup_py_version(self): if os.path.exists('setup.py'): # First run egg_info, as that may get rid of some warnings # that otherwise end up in the extracted version, like # UserWarnings. utils.system(utils.setup_py('egg_info')) version = utils.system(utils.setup_py('--version')) if version.startswith('Traceback'): # Likely cause is for example forgetting to 'import # os' when using 'os' in setup.py. logger.critical('The setup.py of this package has an error:') print(version) logger.critical('No version found.') sys.exit(1) return utils.strip_version(version)
def available_tags(self): tag_info = system('hg tags') tags = [line[:line.find(' ')] for line in tag_info.split('\n')] tags = [tag for tag in tags if tag] tags.remove('tip') # Not functional for us logger.debug("Available tags: %r", tags) return tags
def checkout_from_tag(self, version): package = self.name prefix = '%s-%s-' % (package, version) tagdir = self.prepare_checkout_dir(prefix) os.chdir(tagdir) cmd = self.cmd_checkout_from_tag(version, tagdir) print(utils.system(cmd))
def checkout_from_tag(self, version): package = self.name prefix = '%s-%s-' % (package, version) # Not all hg versions can do a checkout in an existing or even # just in the current directory. tagdir = tempfile.mktemp(prefix=prefix) cmd = self.cmd_checkout_from_tag(version, tagdir) print(system(cmd)) os.chdir(tagdir)
def is_clean_checkout(self): """Is this a clean checkout? """ # The --quiet option ignores untracked (unknown and ignored) # files, which seems reasonable. if system('hg status --quiet'): # Local changes. return False return True
def prepare_checkout_dir(self, prefix): # Watch out: some git versions can't clone into an existing # directory, even when it is empty. temp = tempfile.mkdtemp(prefix=prefix) cwd = os.getcwd() os.chdir(temp) cmd = "git clone %s %s" % (self.workingdir, "gitclone") logger.debug(system(cmd)) os.chdir(cwd) return os.path.join(temp, "gitclone")
def _push(self): """Offer to push changes, if needed.""" push_cmds = self.vcs.push_commands() if not push_cmds: return if utils.ask("OK to push commits to the server?"): for push_cmd in push_cmds: output = utils.system(push_cmd) logger.info(output)
def _make_tag(self): version = self.data['new_version'] cmds = self.vcs.cmd_create_tag(version) if not isinstance(cmds, list): cmds = [cmds] if len(cmds) == 1: print("Tag needed to proceed, you can use the following command:") for cmd in cmds: print(cmd) if utils.ask("Run this command"): print(utils.system(cmd)) else: # all commands are needed in order to proceed normally print("Please create a tag for %s yourself and rerun." % (version,)) sys.exit() if not self.vcs.tag_exists(version): print("\nFailed to create tag %s!" % (version,)) sys.exit()
def cmd_diff_last_commit_against_tag(self, version): current_revision = system('hg identify') current_revision = current_revision.split(' ')[0] # + at the end of the revision denotes uncommitted changes current_revision = current_revision.rstrip('+') return "hg diff -r %s -r %s" % (version, current_revision)
def _upload_distributions(self, package, sdist_options, pypiconfig): # See if creating an sdist actually works. Also, this makes # the sdist available for plugins. logger.info("Making an egg of a fresh tag checkout.") print(utils.system(utils.setup_py('sdist ' + sdist_options))) if not pypiconfig.is_pypi_configured(): logger.warn("You must have a properly configured %s file in " "your home dir to upload an egg.", pypi.DIST_CONFIG_FILE) return # First ask if we want to upload to pypi, which should always # work, also without collective.dist. use_pypi = package_in_pypi(package) if use_pypi: logger.info("This package is registered on PyPI.") else: logger.warn("This package is NOT registered on PyPI.") if pypiconfig.is_old_pypi_config(): pypi_command = 'register sdist %s upload' % sdist_options shell_command = utils.setup_py(pypi_command) if use_pypi: default = True exact = False else: # We are not yet on pypi. To avoid an 'Oops..., # sorry!' when registering and uploading an internal # package we default to False here. default = False exact = True if utils.ask("Register and upload to PyPI", default=default, exact=exact): logger.info("Running: %s", shell_command) result = utils.system(shell_command) utils.show_first_and_last_lines(result) # If collective.dist is installed (or we are using # python2.6 or higher), the user may have defined # other servers to upload to. for server in pypiconfig.distutils_servers(): if pypi.new_distutils_available(): commands = ('register', '-r', server, 'sdist', sdist_options, 'upload', '-r', server) else: ## This would be logical, given the lines above: #commands = ('mregister', '-r', server, 'sdist', # sdist_options, 'mupload', '-r', server) ## But according to the collective.dist documentation ## it should be this (with just one '-r'): commands = ('mregister', 'sdist', sdist_options, 'mupload', '-r', server) shell_command = utils.setup_py(' '.join(commands)) default = True exact = False if server == 'pypi' and not use_pypi: # We are not yet on pypi. To avoid an 'Oops..., # sorry!' when registering and uploading an internal # package we default to False here. default = False exact = True if utils.ask("Register and upload to %s" % server, default=default, exact=exact): logger.info("Running: %s", shell_command) result = utils.system(shell_command) utils.show_first_and_last_lines(result)
def _merge_to_master(self): cmds = self.vcs.merge_to_master() for cmd in cmds: print(utils.system(cmd))
def list_files(self): """List files in version control.""" return system("git ls-tree -r HEAD --name-only").splitlines()
def list_files(self): """List files in version control.""" return system('hg manifest').splitlines()
def available_tags(self): tag_info = system("git tag") tags = [line for line in tag_info.split("\n") if line] logger.debug("Available tags: %r", tags) return tags
def merge_to_master(self): branch = system("git rev-parse --abbrev-ref HEAD") # print system('git rebase {} master'.format(data['version'])) return ["git checkout master", "git merge {}".format(branch), "git checkout {}".format(branch)]
def cmd_log_since_tag(self, version): current_revision = system('hg identify') current_revision = current_revision.split(' ')[0] # + at the end of the revision denotes uncommitted changes current_revision = current_revision.rstrip('+') return "hg log -r %s -r %s" % (version, current_revision)