2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-30 18:50:53 +00:00

Switch to pathlib (#3392)

* switch to pathlib

* more pathlib

* useconvert env to path

* fix typo

* use resolve instead of absolute

* fix gitppod

* also allow parents

* replace more os operations

* fix string replacement feature

* make sure root dirs exsist

* fix replace function

* refactor duplicate code

* reduce code

* make sure dirs exist

* fix typo

* also create parent dirs

* fix match statement

* fix statments expecting string

* return getMigrationFileNames to old behaviour

* fully resolve config file

* make sure comparison works

* use pathlib in tasks

* fix file count test

* reduce code duplication in test + add test for part

* fix test

* re-add os

* Make pathlib usage simpler
This commit is contained in:
Matthias Mair
2022-07-27 02:42:34 +02:00
committed by GitHub
parent 551f66ff90
commit 794e375009
20 changed files with 242 additions and 403 deletions

View File

@ -7,9 +7,9 @@
import importlib
import logging
import os
import pathlib
import subprocess
from importlib import metadata, reload
from pathlib import Path
from typing import OrderedDict
from django.apps import apps
@ -207,7 +207,7 @@ class PluginsRegistry:
if custom_dirs is not None:
# Allow multiple plugin directories to be specified
for pd_text in custom_dirs.split(','):
pd = pathlib.Path(pd_text.strip()).absolute()
pd = Path(pd_text.strip()).absolute()
# Attempt to create the directory if it does not already exist
if not pd.exists():
@ -248,7 +248,7 @@ class PluginsRegistry:
logger.info(f"Loading plugins from directory '{plugin}'")
parent_path = None
parent_obj = pathlib.Path(plugin)
parent_obj = Path(plugin)
# If a "path" is provided, some special handling is required
if parent_obj.name is not plugin and len(parent_obj.parts) > 1:
@ -283,7 +283,7 @@ class PluginsRegistry:
return True
try:
output = str(subprocess.check_output(['pip', 'install', '-U', '-r', settings.PLUGIN_FILE], cwd=os.path.dirname(settings.BASE_DIR)), 'utf-8')
output = str(subprocess.check_output(['pip', 'install', '-U', '-r', settings.PLUGIN_FILE], cwd=settings.BASE_DIR.parent), 'utf-8')
except subprocess.CalledProcessError as error: # pragma: no cover
logger.error(f'Ran into error while trying to install plugins!\n{str(error)}')
return False
@ -565,7 +565,7 @@ class PluginsRegistry:
"""
try:
# for local path plugins
plugin_path = '.'.join(pathlib.Path(plugin.path).relative_to(settings.BASE_DIR).parts)
plugin_path = '.'.join(Path(plugin.path).relative_to(settings.BASE_DIR).parts)
except ValueError: # pragma: no cover
# plugin is shipped as package
plugin_path = plugin.NAME