From b932312bc3e134028567829a20ca92734c6364c9 Mon Sep 17 00:00:00 2001 From: lgolston <30876419+lgolston@users.noreply.github.com> Date: Wed, 18 Oct 2023 11:56:49 -0500 Subject: [PATCH] change REPO_DIR approach --- lib/cartopy/tests/test_coding_standards.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/cartopy/tests/test_coding_standards.py b/lib/cartopy/tests/test_coding_standards.py index 81e53e7f8..57f464fde 100644 --- a/lib/cartopy/tests/test_coding_standards.py +++ b/lib/cartopy/tests/test_coding_standards.py @@ -5,15 +5,12 @@ # licensing details. from fnmatch import fnmatch -import os from pathlib import Path import re import subprocess import pytest -import cartopy - # Add shebang possibility or C comment starter to the LICENSE_RE_PATTERN SHEBANG_PATTERN = r'((\#\!.*|\/\*)\n)?' @@ -29,12 +26,11 @@ LICENSE_RE_PATTERN = re.escape(LICENSE_TEMPLATE) LICENSE_RE = re.compile(SHEBANG_PATTERN + LICENSE_RE_PATTERN, re.MULTILINE) - -# Guess cartopy repo directory of cartopy - realpath is used to mitigate -# against Python finding the cartopy package via a symlink. -CARTOPY_DIR = Path(cartopy.__file__).parent.resolve() -REPO_DIR = Path(os.getenv('CARTOPY_GIT_DIR', - CARTOPY_DIR.parent.parent)) +# Get repo directory for cartopy (https://stackoverflow.com/a/53675112) +REPO_DIR = subprocess.Popen(['git', 'rev-parse', '--show-toplevel'], + stdout=subprocess.PIPE + ).communicate()[0].rstrip().decode('utf-8') +REPO_DIR = Path(REPO_DIR) class TestLicenseHeaders: