From a6fe73e3faf3dcb8728b6d582e1f0305fa962084 Mon Sep 17 00:00:00 2001 From: Ryan Dale Date: Fri, 19 Apr 2024 17:00:48 -0400 Subject: [PATCH] python version agnostic method to get package files --- trackhub/trackhub_from_excel | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/trackhub/trackhub_from_excel b/trackhub/trackhub_from_excel index 0527cbe..72814f8 100755 --- a/trackhub/trackhub_from_excel +++ b/trackhub/trackhub_from_excel @@ -1,5 +1,7 @@ #!/usr/bin/env python +import sys +import os import importlib.resources import trackhub from collections import defaultdict @@ -585,10 +587,13 @@ def create_example(filename): This uses the example file that is shipped with the trackhub package, and adds two new sheets to include absolute paths to the example data. """ - # Find the package's data directory - data = importlib.resources.files("trackhub") / "test" / "data" - - wb = load_workbook(data / "example.xlsx", data_only=True) + # In Python >=3.9, importlib.resources.files would work, but the method + # used here is agnostic to Python versions. + example_file = os.path.join( + os.path.dirname(sys.modules['trackhub'].__file), + "example.xlsx" + ) + wb = load_workbook(example_file, data_only=True) bigbeds = wb.create_sheet("bigbeds") bigbeds.append(