all repos — py-vite @ 9c46dc64426db1534fe0ada7fb04d7a06745114a

the original vite, written in python

refactor: rework importing of config.py
config.py is now only imported (attempted anyway), if user executes
`build` or `serve`
Anirudh icyph0x@pm.me
Wed, 25 Apr 2018 16:52:43 +0530
commit

9c46dc64426db1534fe0ada7fb04d7a06745114a

parent

69f102bf0b70909517973ac9d0e322ec1e2de5b3

2 files changed, 16 insertions(+), 30 deletions(-)

jump to
M vite/cli.pyvite/cli.py

@@ -27,8 +27,10 @@ vite.create_project(args.path)

else: parser.print_help() elif args.cmd == 'build': + vite.import_config() vite.builder() elif args.cmd == 'serve': + vite.import_config() vite.server() else: parser.print_help()
M vite/vite.pyvite/vite.py

@@ -17,20 +17,27 @@ from huepy import *

from distutils.dir_util import copy_tree from vite import vite -try: - sys.path.append(os.getcwd()) - import config -except FileNotFoundError: - print(bad('Error: config.py not found')) # constants PAGES_PATH = 'pages/' BUILD_PATH = 'build/' TEMPL_PATH = 'templates/' -TEMPL_FILE = TEMPL_PATH + config.template +TEMPL_FILE = '' PORT = 1911 +def import_config(): + try: + sys.path.append(os.getcwd()) + globals()['config'] = __import__('config') + global TEMPL_FILE + TEMPL_FILE = os.path.join(TEMPL_PATH, config.template) + except ImportError: + print(bad('Error: config.py not found.')) + print(que('Are you sure you\'re in a project directory?')) + sys.exit(1) + + def create_project(path): try: abs_path = pathlib.Path(path).resolve()

@@ -40,8 +47,6 @@ os.mkdir(os.path.join(path, 'pages'))

os.mkdir(os.path.join(path, 'templates')) os.mkdir(os.path.join(path, 'static')) create_config(path) - os.symlink(os.path.join(cur_path, 'make.py'), - os.path.join(abs_path, 'make.py')) create_template(path) print(good('Created project directory at %s.' % (abs_path))) except FileExistsError:

@@ -141,25 +146,4 @@ copy_tree('static', os.path.join(path, BUILD_PATH, 'static'))

print(good('Done in %0.5fs.' % (time.process_time() - start))) except jinja2.exceptions.TemplateNotFound: print(bad('Error: specified template not found: %s' % TEMPL_FILE)) - - -#if __name__ == "__main__": -# usage = lightblue('vite.py') + ' new [PATH]' -# desc = green('A simple and minimal static site generator.') -# parser = argparse.ArgumentParser(description=desc, usage=usage) -# parser.add_argument('new', nargs='*', help='Create new Vite project.') -# -# if len(sys.argv) == 1: -# parser.print_help() -# sys.exit(1) -# -# try: -# args = parser.parse_args() -# project_path = args.new[1] -# except IndexError: -# parser.print_help() -# sys.exit(1) -# -# if args.new: -# create_project(project_path) - +