Beispiel #1
0
 def check_master(self):
     # cur_branch = system('git rev-parse --abbrev-ref HEAD').strip()
     cur_branch = open(".git/HEAD").read().strip().split("/")[-1]
     if cur_branch == "master":
         q = "Your current branch is master\n" "Are you sure you want to continue?"
         if not ask(q, default=False):
             sys.exit(1)
Beispiel #2
0
    def _release(self):
        """Upload the release, when desired"""

        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['new_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()

        sdist_options = self._sdist_options()

        if 'setup.py' in os.listdir(self.data['tagdir']):
            self._upload_distributions(package, sdist_options, pypiconfig)

        # Make sure we are in the expected directory again.
        os.chdir(self.vcs.workingdir)
Beispiel #3
0
 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)
Beispiel #4
0
    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)
Beispiel #5
0
 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()
Beispiel #6
0
def main():

    #
    # Ask about the project
    #

    here = os.path.dirname(os.path.realpath(__file__))

    project = ask_version('\nProject name')

    print('\nChoose a license, options are:')
    for index, license in enumerate(LICENSES):
        print('{}) {}'.format(index, license[0]))

    license = ask_version('Pick a version', '0')
    while 0 > int(license) or int(license) >= len(LICENSES):
        license = ask_version('Wrong version, try again', '0')

    license = LICENSES[int(license)]
    license_file = os.path.join(here, 'licenses', license[0])

    #
    # Create folder and copy license
    #

    project_dir = os.path.join(os.path.abspath(os.getcwd()), project)
    if not ask('\nCreate this project directory:\n{}'.format(project_dir)):
        print('Exit')
        sys.exit()

    try:
        os.mkdir(project)
    except FileExistsError:
        print('Directory "{}" already exits!!!'.format(project_dir))
        sys.exit(1)
    copy(license_file, os.path.join(project, 'LICENSE'))

    #
    # Render the templates
    #
    variables = {'project': project,
                 'license': license[1]}

    templates_dir = os.path.join(here, 'templates')
    env = Environment(loader=FileSystemLoader(templates_dir),
                      keep_trailing_newline=True)

    for path, subdirs, files in os.walk(templates_dir):
        if '__pycache__' in subdirs:
            subdirs.remove('__pycache__')

        for name in files:
            if should_skip_file(name):
                continue

            in_path = os.path.relpath(os.path.join(path, name), templates_dir)
            logging.info('Render {}'.format(in_path))
            out_path = os.path.join(project_dir, replace(in_path, variables))

            out_dir = os.path.dirname(out_path)
            if not os.path.exists(out_dir):
                os.makedirs(out_dir)

            render(env, in_path, out_path, variables)

    #
    # Init a git repo
    #

    logging.info('Create git repository')
    run('git init', cwd=project)
    run('git add .', cwd=project)
    run('git commit -a -m "Initial commit"', cwd=project)
    run('git checkout -b develop', cwd=project)

    # Create github repo
    if ask('Create a GitHub repo'):
        user = '******'
        pw = run('pass github | head -n 1', stdout=Capture()).stdout.text.strip()
        requests.post('https://api.github.com/user/repos',
                      auth=(user, pw),
                      data=json.dumps({'name': project,
                                       'homepage': 'http://{}.github.io/{}'.format(user, project)}))

        run('git remote add origin [email protected]:{}/{}.git'.format(user, project), cwd=project)
        run('git push --all --set-upstream origin', cwd=project)
Beispiel #7
0
    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)