From 8b427c9d793c1fe6db154fceb87cf7e6eb5d7649 Mon Sep 17 00:00:00 2001
From: Nick Sweeting <git@sweeting.me>
Date: Tue, 18 Aug 2020 15:00:00 -0400
Subject: [PATCH] get VERSION from package.json instead of VERSION to avoid
 duplication

---
 MANIFEST.in                     |  3 ++-
 archivebox.egg-info/SOURCES.txt |  3 ++-
 archivebox/VERSION              |  1 -
 archivebox/config/__init__.py   |  8 ++++----
 bin/release.sh                  | 26 +++++++++++++-------------
 package-lock.json               |  4 ++--
 package.json                    |  8 ++++----
 setup.py                        |  6 ++++--
 8 files changed, 31 insertions(+), 28 deletions(-)
 delete mode 100644 archivebox/VERSION

diff --git a/MANIFEST.in b/MANIFEST.in
index a73ef711..e94f3b11 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -1,4 +1,5 @@
 include LICENSE
 include README.md
-include archivebox/VERSION
+include package.json
+include package-lock.json
 recursive-include archivebox/themes *
diff --git a/archivebox.egg-info/SOURCES.txt b/archivebox.egg-info/SOURCES.txt
index ee6a2fc5..9541d8fc 100644
--- a/archivebox.egg-info/SOURCES.txt
+++ b/archivebox.egg-info/SOURCES.txt
@@ -1,8 +1,9 @@
 LICENSE
 MANIFEST.in
 README.md
+package-lock.json
+package.json
 setup.py
-archivebox/VERSION
 archivebox/__init__.py
 archivebox/__main__.py
 archivebox/logging_util.py
diff --git a/archivebox/VERSION b/archivebox/VERSION
deleted file mode 100644
index 7040b811..00000000
--- a/archivebox/VERSION
+++ /dev/null
@@ -1 +0,0 @@
-0.4.17
diff --git a/archivebox/config/__init__.py b/archivebox/config/__init__.py
index 066be01f..2eb60e09 100644
--- a/archivebox/config/__init__.py
+++ b/archivebox/config/__init__.py
@@ -4,10 +4,11 @@ import os
 import io
 import re
 import sys
-import django
+import json
 import getpass
 import shutil
 import platform
+import django
 
 from hashlib import md5
 from pathlib import Path
@@ -185,7 +186,6 @@ STATICFILE_EXTENSIONS = {
     # html, htm, shtml, xhtml, xml, aspx, php, cgi
 }
 
-VERSION_FILENAME = 'VERSION'
 PYTHON_DIR_NAME = 'archivebox'
 TEMPLATES_DIR_NAME = 'themes'
 
@@ -231,10 +231,10 @@ DERIVED_CONFIG_DEFAULTS: ConfigDefaultDict = {
     'CONFIG_FILE':              {'default': lambda c: os.path.abspath(os.path.expanduser(c['CONFIG_FILE'])) if c['CONFIG_FILE'] else os.path.join(c['OUTPUT_DIR'], CONFIG_FILENAME)},
     'COOKIES_FILE':             {'default': lambda c: c['COOKIES_FILE'] and os.path.abspath(os.path.expanduser(c['COOKIES_FILE']))},
     'CHROME_USER_DATA_DIR':     {'default': lambda c: find_chrome_data_dir() if c['CHROME_USER_DATA_DIR'] is None else (os.path.abspath(os.path.expanduser(c['CHROME_USER_DATA_DIR'])) or None)},
-    'URL_BLACKLIST_PTN':        {'default': lambda c: c['URL_BLACKLIST'] and re.compile(c['URL_BLACKLIST'], re.IGNORECASE | re.UNICODE | re.MULTILINE)},
+    'URL_BLACKLIST_PTN':        {'default': lambda c: c['URL_BLACKLIST'] and re.compile(c['URL_BLACKLIST'] or '', re.IGNORECASE | re.UNICODE | re.MULTILINE)},
 
     'ARCHIVEBOX_BINARY':        {'default': lambda c: sys.argv[0]},
-    'VERSION':                  {'default': lambda c: open(os.path.join(c['PYTHON_DIR'], VERSION_FILENAME), 'r').read().strip()},
+    'VERSION':                  {'default': lambda c: json.loads((Path(c['REPO_DIR']) / 'package.json').read_text().strip())['version']},
     'GIT_SHA':                  {'default': lambda c: c['VERSION'].split('+')[-1] or 'unknown'},
 
     'PYTHON_BINARY':            {'default': lambda c: sys.executable},
diff --git a/bin/release.sh b/bin/release.sh
index 7f5a7db4..bd7f19a7 100755
--- a/bin/release.sh
+++ b/bin/release.sh
@@ -10,29 +10,28 @@ set -o nounset
 set -o pipefail
 IFS=$'\n'
 
-DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && cd .. && pwd )"
-VERSION_FILE="$DIR/archivebox/VERSION"
+REPO_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && cd .. && pwd )"
 
 function bump_semver {
     echo "$1" | awk -F. '{$NF = $NF + 1;} 1' | sed 's/ /./g'
 }
 
-source "$DIR/.venv/bin/activate"
-cd "$DIR"
+source "$REPO_DIR/.venv/bin/activate"
+cd "$REPO_DIR"
 
-OLD_VERSION="$(cat "$VERSION_FILE")"
+OLD_VERSION="$(jq -r '.version' < "$REPO_DIR/package.json")"
 NEW_VERSION="$(bump_semver "$OLD_VERSION")"
 
 echo "[*] Fetching latest docs version"
-cd "$DIR/docs"
+cd "$REPO_DIR/docs"
 git pull
-cd "$DIR"
+cd "$REPO_DIR"
 
 echo "[+] Building docs"
 sphinx-apidoc -o docs archivebox
-cd "$DIR/docs"
+cd "$REPO_DIR/docs"
 make html
-cd "$DIR"
+cd "$REPO_DIR"
 
 if [ -z "$(git status --porcelain)" ] && [[ "$(git branch --show-current)" == "master" ]]; then 
     git pull
@@ -43,19 +42,20 @@ else
 fi
 
 echo "[*] Bumping VERSION from $OLD_VERSION to $NEW_VERSION"
-echo "$NEW_VERSION" > "$VERSION_FILE"
-git add "$DIR/docs"
+contents="$(jq ".version = \"$NEW_VERSION\"" "$REPO_DIR/package.json")" && \
+echo "${contents}" > package.json
+git add "$REPO_DIR/docs"
 git add "$VERSION_FILE"
 
 echo "[*] Cleaning up build dirs"
-cd "$DIR"
+cd "$REPO_DIR"
 rm -Rf build dist
 
 echo "[+] Building sdist and bdist_wheel"
 python3 setup.py sdist bdist_wheel
 
 echo "[^] Pushing source to github"
-git add "$DIR/archivebox.egg-info"
+git add "$REPO_DIR/archivebox.egg-info"
 git commit -m "$NEW_VERSION release"
 git tag -a "v$NEW_VERSION" -m "v$NEW_VERSION"
 git push origin master
diff --git a/package-lock.json b/package-lock.json
index 221be8d9..dfc101a1 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -902,7 +902,7 @@
 			"integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA=="
 		},
 		"readability-extractor": {
-			"version": "git+https://github.com/pirate/readability-extractor.git#afa6a5bb8473f629ee3f1e0dcbf093b73d4eff40",
+			"version": "git+https://github.com/pirate/readability-extractor.git#0098f142b0a015c8c90766d3b74d9eb6fb7b7e6a",
 			"from": "git+https://github.com/pirate/readability-extractor.git",
 			"requires": {
 				"@mozilla/readability": "^0.3.0",
@@ -1054,7 +1054,7 @@
 			"integrity": "sha1-SysbJ+uAip+NzEgaWOXlb1mfP2E="
 		},
 		"single-file": {
-			"version": "git+https://github.com/gildas-lormeau/SingleFile.git#27c1ba673979f593b3c2c6cd353634bf869743f9",
+			"version": "git+https://github.com/gildas-lormeau/SingleFile.git#e2e15381a6cbb9c3a6ca0ea8ff7307174e98ad12",
 			"from": "git+https://github.com/gildas-lormeau/SingleFile.git",
 			"requires": {
 				"file-url": "^3.0.0",
diff --git a/package.json b/package.json
index 6d44822e..9b031470 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
 	"name": "archivebox",
-	"version": "0.4.14",
+	"version": "0.4.17",
 	"description": "ArchiveBox: The self-hosted internet archive",
 	"author": "Nick Sweeting <archivebox-npm@sweeting.me>",
 	"license": "MIT",
@@ -8,9 +8,9 @@
 		"archivebox": "./bin/archive"
 	},
 	"bin": {
-        "archivebox-node": "./bin/archive",
-		"single-file": "single-file",
-        "readability-extractor": "single-file"
+		"archivebox-node": "./bin/archive",
+		"single-file": "./node_modules/.bin/single-file",
+		"readability-extractor": "./node_modules/.bin/single-file"
 	},
 	"dependencies": {
 		"readability-extractor": "git+https://github.com/pirate/readability-extractor.git",
diff --git a/setup.py b/setup.py
index e4794f00..2871df75 100755
--- a/setup.py
+++ b/setup.py
@@ -1,4 +1,6 @@
+import json
 import setuptools
+
 from pathlib import Path
 
 PKG_NAME = "archivebox"
@@ -6,13 +8,13 @@ REPO_URL = "https://github.com/pirate/ArchiveBox"
 BASE_DIR = Path(__file__).parent.resolve()
 SOURCE_DIR = BASE_DIR / PKG_NAME
 README = (BASE_DIR / "README.md").read_text()
-VERSION = (SOURCE_DIR / "VERSION").read_text().strip()
+VERSION = json.loads((BASE_DIR / "package.json").read_text().strip())['version']
 
 # To see when setup.py gets called (uncomment for debugging)
 # import sys
 # print(SOURCE_DIR, f"     (v{VERSION})")
 # print('>', sys.executable, *sys.argv)
-# raise SystemExit(0)
+
 
 setuptools.setup(
     name=PKG_NAME,