Skip to content

Add Git push to 3) Publish button menu #38

Description

@PFython

easyPyPI helps new Pythonistas by automatically creating and initialising a Github Repository. The author doesn't use git commands usually and just pasted in the recommended incantations from Github itself:

def publish_to_github(self):
    """ Uploads initial package to Github using Git"""
    if not self.get_username("Github"):
        return False
    commands = f"""
    git init
    git add *.*
    git commit -m "Committing version {self.version}"
    git branch -M main
    git remote add origin https://github.com/{self.Github_username}/{self.name}.git
    git push -u origin main
    """
    choice = sg.popup_yes_no(
        f"Do you want to upload (Push) your package to Github?\n\n ⚠   CAUTION - "
        f"Only recommended when creating your repository for the first time!  "
        f"This automation requires Git and will run the following commands:\n\n{commands}",
        **SG_KWARGS,
    )
    if choice != "Yes":
        return False
    os.chdir(self.setup_filepath.parent)
    for command in commands.splitlines()[1:]:  # Ignore first blank line
        if not os.system(f"cmd /c {command}"):
            # A return value of 1 indicates an error, 0 indicates success
            print(f"\n ⓘ  Your package is now online at:\n  {self.url}':\n")

Although easyPyPI isn't intended to replace the git or Github client or the numerous plugins and extensions to IDEs that help with version control, it might be a nice convenience function to add the ability to Push the latest Repository to Github immediately after publishing on PyPI.

If anyone can help with the correct git incantations and a little logic to check things are set up correctly ready for the Push, please do contribute and send a Pull Request! Many thanks :)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions