[PYTHON] Try using cookiecutter

Overview

https://github.com/audreyr/cookiecutter

A tool for creating a template for a Python project Prepare a project template using Django and Bootstrap, and use it like generating a project from the command line Some templates are published on GitHub etc.

Installation

Install with pip

pip install cookiecutter

Generate a project by specifying a template

cookiecutter https://github.com/audreyr/cookiecutter-pypackage.git

As for the specification of the template, it seems that the method is described in the explanation, so follow it. When creating a project, you will be asked for information such as the project name and email address, so if you answer, it will be reflected in the project. At this time, it seems that the repository is cloned in ~ / .cookiecutters. Maybe cache.

How to find a template

--Search with cookiecutter on GitHub --This is also Django https://www.djangopackages.com/grids/g/cookiecutter/

Try to move

https://github.com/pydanny/cookiecutter-django Type that seems to be all in Since DB is PostgreSQL, change to MySQL and use The documentation is pretty well written

Project generation

cd ~/dev
cookiecutter https://github.com/pydanny/cookiecutter-django.git

This time I will create a project in "home directory / dev" It doesn't matter if you ask the question properly. This time I will leave it as myassp Just be careful about the project name

Install the required libraries for your project

Since the DB used is PostgreSQL, some settings are rewritten. ~/dev/myapps/requirements/base.txt Edit this file.

psycopg2==2.5.3 This line MySQL-python == 1.2.5 Change to

cd ~/dev/myapps 
pip install -r requirements/local.txt

A text file that summarizes the necessary libraries is prepared, so use it to install In this template, the library can be divided according to the test environment, production environment, etc.

To requirements test.txt production.txt local.txt base.txt There is

base.txt is a common library for the whole, and the rest is divided into test / production / local

At this time, if I did it as it was, an error occurred in the PostgreSQL related library. Maybe it's because you didn't install it

Application settings

Change DB config/settings.py DATABASES = values.DatabaseURLValue('postgres://localhost/myapps') Change this to one that uses MySQL

to start

syncdb

python manage.py syncdb

Do normal syncdb However, there seems to be a model managed by south, and this alone does not complete

python manage.py migrate

This seems to pass the initial settings

Start the server

python manage.py runserver

to access

http://127.0.0.1:8000/

Make your own template

I didn't actually make it, but it's easy to fork someone's template and make it. If it's simple to play with, it's not so difficult, so it seems to be good for people who often make projects

Summary

――It looks good when you decide and operate a standard template etc. at a company etc. ――The created template can be a reference for implementation, but when it comes to using it, it can be awkward to understand first. ――You may need to make it only occasionally (because it requires labor and regular maintenance)

Recommended Posts

Try using cookiecutter
Try using Tkinter
Try using docker-py
Try using PDFMiner
Try using geopandas
Try using Selenium
Try using scipy
Try using pandas.DataFrame
Try using django-swiftbrowser
Try using matplotlib
Try using tf.metrics
Try using PyODE
Try using virtualenv (virtualenvwrapper)
[Azure] Try using Azure Functions
Try using virtualenv now
Try using W & B
Try using Django templates.html
[Kaggle] Try using LGBM
Try using Python's feedparser.
Try using Python's Tkinter
Try using Tweepy [Python2.7]
Try using Pytorch's collate_fn
Try using PythonTex with Texpad.
[Python] Try using Tkinter's canvas
Try using Jupyter's Docker image
Try using scikit-learn (1) --K-means clustering
Try function optimization using Hyperopt
Try using matplotlib with PyCharm
Try using Azure Logic Apps
Try using Kubernetes Client -Python-
[Kaggle] Try using xg boost
Try using the Twitter API
Try using OpenCV on Windows
Try using Jupyter Notebook dynamically
Try using AWS SageMaker Studio
Try tweeting automatically using Selenium.
Try using SQLAlchemy + MySQL (Part 1)
Try using the Twitter API
Try using SQLAlchemy + MySQL (Part 2)
Try using Django's template feature
Try using the PeeringDB 2.0 API
Try using Pelican's draft feature
Try using pytest-Overview and Samples-
Try using folium with anaconda
Try using Janus gateway's Admin API
[Statistics] [R] Try using quantile regression.
Try using Spyder included in Anaconda
Try using design patterns (exporter edition)
Try using Pillow on iPython (Part 1)
Try using Pillow on iPython (Part 2)
Try using Pleasant's API (python / FastAPI)
Try using LevelDB in Python (plyvel)
Try using pynag to configure Nagios
Try using PyCharm's remote debugging feature
Try using ArUco on Raspberry Pi
Try using cheap LiDAR (Camsense X1)
[Sakura rental server] Try using flask.
Try using Pillow on iPython (Part 3)
Reinforcement learning 8 Try using Chainer UI
Try to get statistics using e-Stat
Try using Python argparse's action API