def __init__(self, vcs=None):
     os.environ["ZESTRELEASER"] = "We are called from within zest.releaser"
     # ^^^ Env variable so called tools can detect us. Don't depend on the
     # actual text, just on the variable's name.
     if vcs is None:
         self.vcs = choose.version_control()
     else:
         # In a fullrelease, we share the determined vcs between
         # prerelease, release and postrelease.
         self.vcs = vcs
     self.data = {
         'name': self.vcs.name,
         'nothing_changed_yet': NOTHING_CHANGED_YET,
         'reporoot': self.vcs.reporoot,
         'workingdir': self.vcs.workingdir,
     }
     self.setup_cfg = pypi.SetupConfig()
     if utils.TESTMODE:
         pypirc_old = pkg_resources.resource_filename(
             'zest.releaser.tests', 'pypirc_old.txt')
         self.pypiconfig = pypi.PypiConfig(pypirc_old)
     else:
         self.pypiconfig = pypi.PypiConfig()
     if self.pypiconfig.no_input():
         utils.AUTO_RESPONSE = True
Exemple #2
0
 def __init__(self, vcs=None):
     if vcs is None:
         self.vcs = choose.version_control()
     else:
         # In a fullrelease, we share the determined vcs between
         # prerelease, release and postrelease.
         self.vcs = vcs
     self.data = {'workingdir': self.vcs.workingdir,
                  'reporoot': self.vcs.reporoot,
                  'name': self.vcs.name}
     self.setup_cfg = pypi.SetupConfig()
     if self.setup_cfg.no_input():
         utils.AUTO_RESPONSE = True
     if utils.TESTMODE:
         pypirc_old = pkg_resources.resource_filename(
             'zest.releaser.tests', 'pypirc_old.txt')
         self.pypiconfig = pypi.PypiConfig(pypirc_old)
     else:
         self.pypiconfig = pypi.PypiConfig()
Exemple #3
0
 def __init__(self, reporoot=None):
     self.workingdir = os.getcwd()
     if reporoot is None:
         self.reporoot = self.workingdir
         self.relative_path_in_repo = ''
     else:
         self.reporoot = reporoot
         # Determine relative path from root of repo.
         self.relative_path_in_repo = os.path.relpath(
             self.workingdir, reporoot)
     self.setup_cfg = pypi.SetupConfig()
     pypi_cfg = pypi.PypiConfig()
     self.fallback_encoding = pypi_cfg.encoding()
Exemple #4
0
def check_pypi_access(data):
    pypi_user = pypi.PypiConfig().config.get('pypi', 'username')
    if not canUserReleasePackageToPypi(pypi_user, data['name']):
        if not ask("User %s does not have pypi release rights to %s. Continue?" % (pypi_user, data['name']), default=False):
            sys.exit()
Exemple #5
0
    def _release(self):
        """Upload the release, when desired"""
        if utils.TESTMODE:
            pypirc_old = pkg_resources.resource_filename(
                'zest.releaser.tests', 'pypirc_old.txt')
            pypiconfig = pypi.PypiConfig(pypirc_old)
        else:
            pypiconfig = pypi.PypiConfig()

        # Does the user normally want a real release?  We are
        # interested in getting a sane default answer here, so you can
        # override it in the exceptional case but just hit Enter in
        # the usual case.
        main_files = os.listdir(self.data['workingdir'])
        if 'setup.py' not in main_files and 'setup.cfg' not in main_files:
            # Neither setup.py nor setup.cfg, so this is no python
            # package, so at least a pypi release is not useful.
            # Expected case: this is a buildout directory.
            default_answer = False
        else:
            default_answer = pypiconfig.want_release()

        if not utils.ask("Check out the tag (for tweaks or pypi/distutils "
                         "server upload)", default=default_answer):
            return

        package = self.vcs.name
        version = self.data['version']
        logger.info("Doing a checkout...")
        self.vcs.checkout_from_tag(version)
        self.data['tagdir'] = os.path.realpath(os.getcwd())
        logger.info("Tag checkout placed in %s", self.data['tagdir'])

        # Possibly fix setup.cfg.
        if self.setup_cfg.has_bad_commands():
            logger.info("This is not advisable for a release.")
            if utils.ask("Fix %s (and commit to tag if possible)" %
                         self.setup_cfg.config_filename, default=True):
                # Fix the setup.cfg in the current working directory
                # so the current release works well.
                self.setup_cfg.fix_config()
                # Now we may want to commit this.  Note that this is
                # only really useful for subversion, as for example in
                # git you are in a detached HEAD state, which is a
                # place where a commit will be lost.
                #
                # Ah, in the case of bazaar doing a commit is actually
                # harmful, as the commit ends up on the tip, instead
                # of only being done on a tag or branch.
                #
                # So the summary is:
                #
                # - svn: NEEDED, not harmful
                # - git: not needed, not harmful
                # - hg: not needed, not harmful
                # - bzr: not needed, HARMFUL
                #
                # So for clarity and safety we should only do this for
                # subversion.
                if self.vcs.internal_filename == '.svn':
                    command = self.vcs.cmd_commit(
                        "Fixed %s on tag for release" %
                        self.setup_cfg.config_filename)
                    print system(command)
                else:
                    logger.debug("Not committing in non-svn repository as "
                                 "this is not needed or may be harmful.")

        sdist_options = self._sdist_options()
        # Run extra entry point
        self._run_hooks('after_checkout')

        if 'setup.py' in os.listdir(self.data['tagdir']):
            if not pypiconfig.config:
                logger.warn("You must have a properly configured %s file in "
                            "your home dir to upload an egg.",
                            pypi.DIST_CONFIG_FILE)
            else:
                self._upload_distributions(package, sdist_options, pypiconfig)

        # Make sure we are in the expected directory again.
        os.chdir(self.vcs.workingdir)