Building a local environment comes with some costs. Of course, I really understand the opinion that you should have some trouble here. However, I think it's a waste to lose my feelings.
Therefore, I created a template for Flask / Django / Jupyter Notebook that allows you to complete ** Python development environment construction with 3 commands **. (Excluding cd
)
--Being MacOS
--The git
and make
commands are valid (should be valid by default)
conda
is installed, batting with pip may occur and it may fail in the middle.You will run the app on the Docker container. Even if you're not familiar with it, you can say that you're developing with a Docker container **.
--The directory is provided from the host PC to the container by bind mount. This makes it possible to read the contents of the file edited on the host PC side on the container side. --For access from the host PC, port forwarding is adopted. The connection port on the container side has been changed depending on the project, but all the ports on the host side to forward have been unified to 8000.
Describes how to download with git clone
.
Terminal
git clone [email protected]:mintak21/local-py-dev-template.git
Specify the extraction destination directory and extract the project.
Use the make
command properly according to the created project.
Terminal
cd local-py-dev-template
#When creating a jupyter project
make create_jupyter_pj
#When creating a flask project
make create_flask_pj
#When creating a django project
make create_django_pj
--Specifiable arguments
Argument name | Overview | Default value |
---|---|---|
TARGET_DIR | Extraction directory(Create if it does not exist) | ~/workspace/project |
DJANGO_PJ_NAME | Can be specified for django. Django template project name | mysite |
Command example with arguments
Terminal
#One level higher flask_Extract the flask project to the dir directory
make create_flask_pj TARGET_DIR=../flask_dir
# ~/Expand the django project in the workspace directory and name the django project blog
make create_django_pj TARGET_DIR=~/workspace DJANGO_PJ_NAME=blog
Move to the directory extracted in 2, create a Docker image and container, and start it.
Terminal
cd ${TARGET_DIR}
make run
Since both containers are port forwarding on port 8000 of the host PC, you can connect if you can access the following, and if the contents described are displayed, the setting is completed.
Access: http: // localhost: 8000 /
project | Expected results |
---|---|
Jupyter | On the Jupyter home screen,HelloPython.ipynb The file is visible |
Flask | Hello Flask! Is displayed |
Django | Rocket is out |
Since it is running in Foreground, stopping the process on the terminal will stop the container.
Ctrl + C
in the terminal
At this point, we have started and connected, so we will proceed with development from now on.
There are also development editors such as Vim
and pytorch
, but here we are using Visual-Studio-Code
to proceed with development.
Installation is completed with one command.
Terminal
make setup_vscode # local-py-dev-Run in template directory
Not only installing Visual-Studio-Code
, but also setting static analysis and pytest
, and introducing necessary & useful extensions at the same time.
Visual-Studio-Code
with brew cask
pip
)
--Static analysis: flake8
--import alignment: isort
--Formatter: autopep8
--type check: mypy
--Test: pytestcode --install-extension
)
--Microsoft-Python: Python extension tool (required)
--Bracket Pair Colorizer: Corresponding brackets are easier to see in color
--Whitespace +: Visualize tabs and whitespace
--Docker: Docker can be handled with vscode
--vscode-icons: Make icons easier to see
--autoDocString: DocString creation assistanceOthers
The local side should also use a virtual environment such as pipenv
, but since many of the pythonic
seniors I knew were using pure Python, I introduced a virtual environment following this. Is not ...
Reference Github repository