Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/TBP-IT/tbpweb
Browse files Browse the repository at this point in the history
  • Loading branch information
chevin-ken committed Jan 19, 2021
2 parents 72ecafe + ee1b093 commit 92e7118
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,6 @@ Icon
Network Trash Folder
Temporary Items
.apdisk

# VirtualEnv
.venv
32 changes: 28 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
$(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
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
5 changes: 3 additions & 2 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions tbpweb/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 4 additions & 0 deletions tbpweb/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
]

0 comments on commit 92e7118

Please sign in to comment.