Last active
September 17, 2023 14:05
-
-
Save toaster-code/0e7dc945254a2c44f33f6cbaa53d16a1 to your computer and use it in GitHub Desktop.
setup a project using python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import sys | |
| def create_project_structure(project_name): | |
| # Create project directory | |
| os.makedirs(project_name, exist_ok=True) | |
| os.chdir(project_name) | |
| # Create a virtual environment (.venv) | |
| os.system(f"python -m venv .venv") | |
| # Create a dummy .env file | |
| with open('.env', 'w') as env_file: | |
| env_file.write("# Add your environment variables here\n") | |
| # Create a README.md file | |
| readme_content = f"""# {project_name}\n\n## Description\n\nTODO: Add project description here\n\n## Getting Started\n\n1. Create and activate a virtual environment:\n ''' | |
| python -m venv .venv\n source .venv\\bin\\activate (Linux/macOS)\n .venv\\Scripts\\activate (Windows)\n '''\n2. Install project dependencies:\n ''' | |
| pip install -r requirements.txt\n '''\n3. Run the project:\n ''' | |
| python main.py\n '''\n4. Add your environment variables to the `.env` file.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.""" | |
| with open('README.md', 'w') as readme_file: | |
| readme_file.write(readme_content) | |
| if __name__ == "__main__": | |
| if len(sys.argv) != 2: | |
| print("Usage: python create_project.py <project_name>") | |
| sys.exit(1) | |
| project_name = sys.argv[1] | |
| create_project_structure(project_name) | |
| print(f"Project structure for {project_name} created successfully.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment