From ff638e269d439c853b5182b68ff10777f12597f1 Mon Sep 17 00:00:00 2001 From: Terry Truong Date: Sun, 5 Feb 2023 13:55:00 +1100 Subject: Use relative imports between data generation scripts Avoids the need for code that modifies sys.path, but requires running of the scripts using 'python -m' with backend/ as cwd. Also expects constants like DB_FILE to be non-relative, due to running from backend/. --- backend/hist_data/gen_events_data.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'backend/hist_data/gen_events_data.py') diff --git a/backend/hist_data/gen_events_data.py b/backend/hist_data/gen_events_data.py index 453a9ad..d433ce7 100755 --- a/backend/hist_data/gen_events_data.py +++ b/backend/hist_data/gen_events_data.py @@ -61,14 +61,9 @@ Info about objects with type 'quantity' can be found at: https://www.wikidata.or # Note: Took about 4.5 hours to run -# For unit testing, resolve imports of modules within this directory -import os -import sys -parentDir = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(parentDir) - from typing import cast import argparse +import os import math import re import io @@ -81,13 +76,14 @@ import pickle import multiprocessing import tempfile -from cal import gregorianToJdn, julianToJdn, MIN_CAL_YEAR +from .cal import gregorianToJdn, julianToJdn, MIN_CAL_YEAR # ========== Constants ========== -WIKIDATA_FILE = os.path.join('wikidata', 'latest-all.json.bz2') -OFFSETS_FILE = os.path.join('wikidata', 'offsets.dat') -DB_FILE = 'data.db' +DATA_DIR = os.path.dirname(os.path.realpath(__file__)) +WIKIDATA_FILE = os.path.join(DATA_DIR, 'wikidata', 'latest-all.json.bz2') +OFFSETS_FILE = os.path.join(DATA_DIR, 'wikidata', 'offsets.dat') +DB_FILE = os.path.join(DATA_DIR, 'data.db') N_PROCS = 6 # Number of processes to use # For getting Wikidata entity IDs -- cgit v1.2.3