diff --git a/.gitignore b/.gitignore index 14af76a..8a96d4f 100644 --- a/.gitignore +++ b/.gitignore @@ -109,3 +109,6 @@ Icon Network Trash Folder Temporary Items .apdisk + +# VirtualEnv +.venv diff --git a/Makefile b/Makefile index 80e01cf..e82cb18 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,45 @@ PIP_HOME = $(shell python3 -c "import site; import os; print(os.path.join(site.USER_BASE, 'bin'))" \ || python -c "import site; import os; print(os.path.join(site.USER_BASE, 'bin'))") +VENV := .venv +BIN := $(VENV)/bin +PYTHON := $(BIN)/python +MANAGE := $(PYTHON) ./manage.py +# MANAGE := HKNWEB_MODE='dev' $(PYTHON) ./manage.py + IP ?= 0.0.0.0 PORT ?= 3000 .PHONY: run run: - pipenv run python3 ./manage.py runserver $(IP):$(PORT) + $(MANAGE) runserver $(IP):$(PORT) .PHONY: superuser superuser: - pipenv run python3 ./manage.py createsuperuser + $(MANAGE) createsuperuser .PHONY: migrations migrations: - pipenv run python3 ./manage.py makemigrations + $(MANAGE) makemigrations .PHONY: migrate migrate: - pipenv run python3 ./manage.py migrate \ No newline at end of file + $(MANAGE) migrate + +.PHONY: venv +venv: + python3 -m venv $(VENV) + @echo "When developing, activate the virtualenv with 'source .venv/bin/activate' so Python can access the installed dependencies." + +.PHONY: install-prod +install-prod: + # For issues with binary packages, consider https://pythonwheels.com/ + $(PYTHON) -m pip install --upgrade pip setuptools + # TODO: pinned/unpinned dependency version. + # See https://hkn-mu.atlassian.net/browse/COMPSERV-110 + $(PYTHON) -m pip install -r requirements.txt + +.PHONY: install +install: + make install-prod + $(PYTHON) -m pip install -r requirements-dev.txt diff --git a/README.md b/README.md index cbdff77..84f2a62 100644 --- a/README.md +++ b/README.md @@ -35,22 +35,22 @@ From here, run $ cd tbpweb ``` -Make sure pipenv is installed in your virtual machine. To do this, run +Developing on `tbpweb` requires a virtual environment so that every developer has the exact same development environment i.e. any errors that a developer has is not due to difference in configuration. We will be using Python's built-on [`venv`](https://docs.python.org/3/library/venv.html) to make our virtual environment. This command creates our virtual environment. ```sh -$ pip3 install pipenv +$ make venv ``` -Next, make sure there is a Pipfile in your current directory and run +Next, we need to have our current terminal/shell use the virtual environment we just created. We do this through: ```sh -$ pipenv shell +$ source .venv/bin/activate ``` -To install django, run +To install all dependencies (including django), run ```sh -$ pipenv install django +$ make install ``` There may be warnings that installation of some packages failed, but as long as you can run the command below successfully you are good to go. diff --git a/Vagrantfile b/Vagrantfile index eeca568..6ab8705 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -85,9 +85,10 @@ Vagrant.configure("2") do |config| python3 \ python3-dev \ python3-pip \ + python3-venv \ tmux \ vim SHELL - # Setup pipenv and virtualenv - config.vm.provision "shell", privileged: false, inline: "cd ~/tbpweb; make setup" + # Setup virtualenv + config.vm.provision "shell", privileged: false, inline: "cd ~/tbpweb; make venv" end diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..dbb1284 --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,5 @@ +pre-commit==1.14.4 +pytest==4.3.0 +pytest-django==3.4.7 +tox==3.7.0 +livereload==2.6.0 diff --git a/tbpweb/settings.py b/tbpweb/settings.py index fdc9eb8..8709d2c 100644 --- a/tbpweb/settings.py +++ b/tbpweb/settings.py @@ -23,14 +23,15 @@ SECRET_KEY = '^j!vujd$z7w1_)zx%11fa@-x5!7)#9me9b_eevrg3z6@fk%1qq' # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = False -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = ['localhost'] # Application definition INSTALLED_APPS = [ + 'base', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', diff --git a/tbpweb/urls.py b/tbpweb/urls.py index db53703..cb62698 100644 --- a/tbpweb/urls.py +++ b/tbpweb/urls.py @@ -15,7 +15,11 @@ """ from django.contrib import admin from django.urls import path +from django.urls import include + +from base import views urlpatterns = [ path('admin/', admin.site.urls), + path('', views.homePage), ]