From cbee55d24fe3eebef6cc30db12d2f0eb2afadf10 Mon Sep 17 00:00:00 2001 From: ashariyar Date: Tue, 11 Oct 2022 05:09:30 -0400 Subject: [PATCH] README, PROJECT_DIR --- pdfalyzer/config.py | 5 +++-- pdfalyzer/util/filesystem_awareness.py | 13 ------------- tests/conftest.py | 13 ++++++++++--- 3 files changed, 13 insertions(+), 18 deletions(-) delete mode 100644 pdfalyzer/util/filesystem_awareness.py diff --git a/pdfalyzer/config.py b/pdfalyzer/config.py index 321eae5..89dec17 100644 --- a/pdfalyzer/config.py +++ b/pdfalyzer/config.py @@ -1,10 +1,11 @@ import importlib.resources import logging -from os import environ, path +from os import environ, pardir, path from yaralyzer.config import YaralyzerConfig, is_env_var_set_and_not_false, is_invoked_by_pytest PDFALYZE = 'pdfalyze' +PROJECT_ROOT = path.join(str(importlib.resources.files('pdfalyzer')), pardir) PYTEST_FLAG = 'INVOKED_BY_PYTEST' # Configuring PDFALYZER_LOG_DIR has side effects; see .pdfalyzer.example in repo for specifics. @@ -22,7 +23,7 @@ class PdfalyzerConfig: JAVSCRIPT_KEYWORD_ALERT_THRESHOLD = 2 QUOTE_TYPE = None - DEFAULT_PDF_PARSER_EXECUTABLE = path.join(str(importlib.resources.files('pdfalyzer')), 'tools', 'pdf-parser.py') + DEFAULT_PDF_PARSER_EXECUTABLE = path.join(PROJECT_ROOT, 'tools', 'pdf-parser.py') # Path to Didier Stevens's pdf-parser.py if is_env_var_set_and_not_false(PDF_PARSER_EXECUTABLE_ENV_VAR): diff --git a/pdfalyzer/util/filesystem_awareness.py b/pdfalyzer/util/filesystem_awareness.py deleted file mode 100644 index a33bf68..0000000 --- a/pdfalyzer/util/filesystem_awareness.py +++ /dev/null @@ -1,13 +0,0 @@ -""" -A resource all the project code can use to understand the file system and this project's -place in it -""" -from os import path -import pathlib - - -PROJECT_DIR = path.realpath(path.join(pathlib.Path(__file__).parent.resolve(), '..', '..')) - -DOCUMENTATION_DIR = path.join(PROJECT_DIR, 'doc') -SVG_DIR = path.join(DOCUMENTATION_DIR, 'svgs') -RENDERED_IMAGES_DIR = path.join(SVG_DIR, 'rendered_images') diff --git a/tests/conftest.py b/tests/conftest.py index 1e7e741..84f13c6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,12 +1,19 @@ -from os import environ, path, remove +from os import environ, path, pardir, remove +import importlib.resources +import pathlib environ['INVOKED_BY_PYTEST'] = 'True' import pytest -from yaralyzer.config import MAX_DECODE_LENGTH_ENV_VAR, YaralyzerConfig from yaralyzer.helpers.file_helper import files_in_dir from pdfalyzer.pdfalyzer import Pdfalyzer -from pdfalyzer.util.filesystem_awareness import DOCUMENTATION_DIR + + +PROJECT_DIR = path.join(str(importlib.resources.files('pdfalyzer')), pardir) +DOCUMENTATION_DIR = path.join(PROJECT_DIR, 'doc') +SVG_DIR = path.join(DOCUMENTATION_DIR, 'svgs') +RENDERED_IMAGES_DIR = path.join(SVG_DIR, 'rendered_images') + # Full paths to PDF test fixtures