Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔥 no template available #1

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,21 @@

## [0.1.5] - 2021-01-07

## [Unreleased]

**Bugfix**

- No template available
- Print a message when the lenght template list is 0

**Enhancement**

- Local install template
- Add a local installation of templates
- Add an update option to upgrade local templates from local source

**Structure**

- Distinct workflow and setup cmd
- Moves file to workflow or setup directories

39 changes: 0 additions & 39 deletions git_improved/configurations.py

This file was deleted.

File renamed without changes.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
import shutil
import argparse
import subprocess
from ..templates import TEMPLATES
from ..command import Command
from ..changelog import Changelog
from ...command import Command
from ...changelog import Changelog
from ..template import setup_project


Expand Down Expand Up @@ -50,4 +49,38 @@ def parser():
return parser

def run(*, directory=".", template=None, verbose=False):
setup_project(template=template, destination=directory)

releases_directory='docs/releases'
changelog_path='docs/changelog.md'
no_github_action=False

# create releases_directory and add a .gitkeep to ensure it wont be empty
release_gitkeep_path = os.path.join(releases_directory, '.gitkeep')
try:
open(release_gitkeep_path)
print('[Warning] GitHub action already exists. Make sure it contains configuration to document changes on release.')
except FileNotFoundError:
os.makedirs(releases_directory, exist_ok=True)
with open(release_gitkeep_path, 'w') as gitkeep:
pass
print('Releases directory created in:', releases_directory)

# create changelog if it doesn't exists
try:
changelog = Changelog.parse(changelog_path)
except FileNotFoundError:
directory = os.path.dirname(os.path.abspath(changelog_path))
os.makedirs(directory, exist_ok=True)
changelog = Changelog.parse(changelog_path)


if not is_git_initialized():
subprocess.call(['git', 'init'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
subprocess.call(['git', 'branch -m master main'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print('Git repository initialized...')

commit_configuration()

# setup templates
if template is not None:
setup_project(template=template, destination=directory)
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import argparse

from ..exceptions import ValidationError
from ..command import Command
from ..template import Template, GitCredentials
from ..shell import display_table
from ...exceptions import ValidationError
from ...command import Command
from ...template import Template, GitCredentials
from ...shell import display_table


class TemplateCommand(metaclass=Command):
Expand All @@ -18,6 +18,11 @@ def parser():
install_parser.add_argument("--user", help="username used to autenticate if required")
install_parser.add_argument("--token", help="pass a token or password to authenticate if required")

local_install_parser = subparsers.add_parser("local", help="install a template from a local source")
local_install_parser.add_argument("alias", help="the name you want to use locally to reference this template")
local_install_parser.add_argument("source", help="local path where target template is located")
local_install_parser.add_argument("-u", "--upgrade", action="store_true", help="update the given template")

update_parser = subparsers.add_parser("update", help="update given templates (default to all).")
update_parser.add_argument("templates", nargs="*", help="if you pass a list of templates, only these templates will be updated...")
update_parser.add_argument("-v", "--verbose", action="store_true", help="(verbose) display additional informations...")
Expand All @@ -34,20 +39,25 @@ def validate(args):
if not args.command:
raise ValidationError('You must specify a command')

def run(*, command, alias=None, search=None, branch=None, user=None, token=None, origin=None, templates=None, verbose=False):
def run(*, command, alias=None, search=None, branch=None, user=None, token=None, origin=None, source=None, upgrade=None, templates=None, verbose=False):
git_template = Template()

if command == "install":
# ensure that user can read this repository (=> public repo or proper authentication)
GitCredentials().require_credentials(repository=origin)
git_template.install(template=alias, origin=origin, branch=branch)
elif command == "local":
git_template.local_install(template=alias, source=source, upgrade=upgrade)
elif command == "update":
templates = templates if templates else git_template.search()
for template in templates:
git_template.update(template, verbose=verbose)
elif command == "list":
templates = git_template.search(query=search)
display_table(templates)
if len(templates) == 0:
print("no templates available")
else:
display_table(templates)
elif command == "rm":
for template in templates:
git_template.remove(template)
33 changes: 28 additions & 5 deletions git_improved/template.py → git_improved/setup/template.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import os
import re
import json
import shutil
import requests
import argparse
import subprocess
import importlib.util
from getpass import getpass
from distutils.dir_util import copy_tree, remove_tree
from jinja2 import Environment, FileSystemLoader, select_autoescape
from .shell import check_output, silent_call
from .git import get_remote_origin, count_changes_from_remote
from ..shell import check_output, silent_call
from ..git import get_remote_origin, count_changes_from_remote


def load_environment(template_path):
Expand Down Expand Up @@ -229,7 +229,30 @@ def install(self, *, template, origin, user=None, token=None, branch='main'):
subprocess.call(['git', 'checkout', '-b', branch])
subprocess.call(['git', 'pull', 'origin', branch])
subprocess.call(['git', 'branch', '--set-upstream-to=origin/%s'%branch, branch])


def local_install(self, *, template:str, source:str, upgrade:bool):

template_path = os.path.join(self.templates_directory, template)

# ensure that --upgrade is used and the template directory exist
if (upgrade is True) and (os.path.isdir(template_path) is True):
self.remove(template=template)

self.manifest.add_template(template)
os.makedirs(template_path)

source_path = ""

if source.startswith(".") is True:
source_path = os.path.abspath(source)
else:
source_path = source

if os.path.isdir(source_path) is False:
raise NotADirectoryError()

copy_tree(source_path, template_path)
print('template upgraded:' if upgrade is True else 'template installed', template)

def update(self, template, verbose=False):
template_path = os.path.join(self.templates_directory, template)
Expand All @@ -253,7 +276,7 @@ def remove(self, template):
try:
template_path = os.path.join(self.templates_directory, template)
self.manifest.remove_template(template)
shutil.rmtree(template_path)
remove_tree(template_path)
except FileNotFoundError as e:
print("[Warning] %s not found!"%template_path)
print('template removed:', template)
5 changes: 0 additions & 5 deletions git_improved/templates/__init__.py

This file was deleted.

4 changes: 0 additions & 4 deletions git_improved/templates/python_package.py

This file was deleted.

Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import argparse
import subprocess
from ..menu import Menu
from ..command import Command
from ..git import get_local_branches, get_remote_branches, get_current_branch, delete_branch
from ...menu import Menu
from ...command import Command
from ...git import get_local_branches, get_remote_branches, get_current_branch, delete_branch


def select_branches():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import uuid
import argparse
import subprocess
from ..command import Command
from ..constants import BRANCHES_PREFIXES, CATEGORIES_ICONS
from ..changelog import Changelog
from ..git import (
from ...command import Command
from ...constants import BRANCHES_PREFIXES, CATEGORIES_ICONS
from ...changelog import Changelog
from ...git import (
get_current_branch, merge_squash, get_current_branch_commits,
ensure_git_initialized, ensure_working_tree_clean, ensure_branch_mergeable
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import re
import argparse
import subprocess
from ..command import Command
from ..changelog import Changelog
from ..constants import CATEGORIES_ICONS
from ..exceptions import ValidationError
from ..git import get_current_branch, ensure_main_branch
from ...command import Command
from ...changelog import Changelog
from ...constants import CATEGORIES_ICONS
from ...exceptions import ValidationError
from ...git import get_current_branch, ensure_main_branch


# custom type used to parse semver
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import argparse
import subprocess
from ..command import Command
from ...command import Command


class SaveCommand(metaclass=Command):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import re
import argparse
import subprocess
from ..git import get_releases
from ..menu import Menu
from ..command import Command
from ..changelog import Changelog
from ..exceptions import ValidationError
from ...git import get_releases
from ...menu import Menu
from ...command import Command
from ...changelog import Changelog
from ...exceptions import ValidationError


def delete_release(version):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import argparse
import subprocess
from ..command import Command
from ..constants import BRANCHES_PREFIXES
from ...command import Command
from ...constants import BRANCHES_PREFIXES


class WipCommand(metaclass=Command):
Expand Down
20 changes: 10 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import setuptools
from git_improved.constants import GITHUB_ICONS_URLS
from src.git_improved.constants import GITHUB_ICONS_URLS


def load_long_description():
Expand All @@ -16,20 +16,20 @@ def load_long_description():
name='git-improved',
description='Add commands to simplify release and publish operation from Git CLI.',
version='0.1.5',
packages=setuptools.find_packages(),
packages=setuptools.find_packages(exclude=("tests")),
entry_points={
'console_scripts': [
'git-setup=git_improved.commands.setup:SetupCommand',
'git-template=git_improved.commands.template:TemplateCommand',
#'git-setup=git_improved.commands.setup:SetupCommand',
#'git-template=git_improved.commands.template:TemplateCommand',

'git-wip=git_improved.commands.wip:WipCommand',
'git-save=git_improved.commands.save:SaveCommand',
'git-wip=git_improved.workflow.commands.wip:WipCommand',
'git-save=git_improved.workflow.commands.save:SaveCommand',

'git-cancel=git_improved.commands.cancel:CancelCommand',
'git-done=git_improved.commands.done:DoneCommand',
'git-cancel=git_improved.workflow.commands.cancel:CancelCommand',
'git-done=git_improved.workflow.commands.done:DoneCommand',

'git-release=git_improved.commands.release:ReleaseCommand',
'git-unrelease=git_improved.commands.unrelease:UnreleaseCommand'
'git-release=git_improved.workflow.commands.release:ReleaseCommand',
'git-unrelease=git_improved.workflow.commands.unrelease:UnreleaseCommand'
]
},
install_requires=[
Expand Down