From d7cd792b57d93aeb804cb69ead74db452d6fff8a Mon Sep 17 00:00:00 2001 From: Nikhil Rao Date: Wed, 4 Jan 2023 15:05:07 -0800 Subject: [PATCH] Add default gitignore on pc init (#206) --- pynecone/constants.py | 4 ++++ pynecone/pc.py | 3 +++ pynecone/utils.py | 15 +++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/pynecone/constants.py b/pynecone/constants.py index 931e83ee8..55d1f63f5 100644 --- a/pynecone/constants.py +++ b/pynecone/constants.py @@ -121,6 +121,10 @@ DEFAULT_DESCRIPTION = "A Pynecone app." DEFAULT_IMAGE = "favicon.ico" +# The gitignore file. +GITIGNORE_FILE = ".gitignore" +# Files to gitignore. +DEFAULT_GITIGNORE = {".web", DB_NAME} # The name of the pynecone config module. CONFIG_MODULE = "pcconfig" # The python config file. diff --git a/pynecone/pc.py b/pynecone/pc.py index dd5f193ac..a2d689815 100644 --- a/pynecone/pc.py +++ b/pynecone/pc.py @@ -39,6 +39,9 @@ def init(): utils.create_config(app_name) utils.initialize_app_directory(app_name) + # Initialize the .gitignore. + utils.initialize_gitignore() + # Finish initializing the app. utils.console.log(f"[bold green]Finished Initializing: {app_name}") diff --git a/pynecone/utils.py b/pynecone/utils.py index 8b1437eeb..47e722b1b 100644 --- a/pynecone/utils.py +++ b/pynecone/utils.py @@ -377,6 +377,21 @@ def create_config(app_name: str): f.write(templates.PCCONFIG.format(app_name=app_name)) +def initialize_gitignore(): + """Initialize the template .gitignore file.""" + # The files to add to the .gitignore file. + files = constants.DEFAULT_GITIGNORE + + # Subtract current ignored files. + if os.path.exists(constants.GITIGNORE_FILE): + with open(constants.GITIGNORE_FILE, "r") as f: + files -= set(f.read().splitlines()) + + # Add the new files to the .gitignore file. + with open(constants.GITIGNORE_FILE, "a") as f: + f.write(join(files)) + + def initialize_app_directory(app_name: str): """Initialize the app directory on pc init.