mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-13 06:34:25 -04:00
improve version detection
This commit is contained in:
parent
b913e6f426
commit
66cd711df9
3 changed files with 27 additions and 13 deletions
|
@ -102,7 +102,7 @@ class BaseHook(BaseModel):
|
||||||
def register(self, settings):
|
def register(self, settings):
|
||||||
"""Called when django.apps.AppConfig.ready() is called"""
|
"""Called when django.apps.AppConfig.ready() is called"""
|
||||||
|
|
||||||
print("REGISTERED HOOK:", self.hook_module)
|
# print("REGISTERED HOOK:", self.hook_module)
|
||||||
self._is_registered = True
|
self._is_registered = True
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -132,8 +132,8 @@ class BasePlugin(BaseModel):
|
||||||
self._is_registered = True
|
self._is_registered = True
|
||||||
bump_startup_progress_bar()
|
bump_startup_progress_bar()
|
||||||
|
|
||||||
print('◣----------------- REGISTERED PLUGIN:', self.plugin_module, '-----------------◢')
|
# print('◣----------------- REGISTERED PLUGIN:', self.plugin_module, '-----------------◢')
|
||||||
print()
|
# print()
|
||||||
|
|
||||||
@abx.hookimpl
|
@abx.hookimpl
|
||||||
def ready(self, settings=None):
|
def ready(self, settings=None):
|
||||||
|
|
|
@ -20,20 +20,34 @@ ARCHIVE_DIR: Path = DATA_DIR / 'archive' # archivebox snaps
|
||||||
|
|
||||||
|
|
||||||
def _detect_installed_version(PACKAGE_DIR: Path):
|
def _detect_installed_version(PACKAGE_DIR: Path):
|
||||||
"""Autodetect the installed archivebox version by using pip package metadata or pyproject.toml file"""
|
"""Autodetect the installed archivebox version by using pip package metadata, pyproject.toml file, or package.json file"""
|
||||||
try:
|
try:
|
||||||
|
# if in production install, use pip-installed package metadata
|
||||||
return importlib.metadata.version(__package__ or 'archivebox')
|
return importlib.metadata.version(__package__ or 'archivebox')
|
||||||
except importlib.metadata.PackageNotFoundError:
|
except importlib.metadata.PackageNotFoundError:
|
||||||
try:
|
pass
|
||||||
pyproject_config = (PACKAGE_DIR / 'pyproject.toml').read_text()
|
|
||||||
for line in pyproject_config:
|
|
||||||
if line.startswith('version = '):
|
|
||||||
return line.split(' = ', 1)[-1].strip('"')
|
|
||||||
except FileNotFoundError:
|
|
||||||
# building docs, pyproject.toml is not available
|
|
||||||
return 'dev'
|
|
||||||
|
|
||||||
raise Exception('Failed to detect installed archivebox version!')
|
try:
|
||||||
|
# if in dev Git repo dir, use pyproject.toml file
|
||||||
|
pyproject_config = (PACKAGE_DIR.parent / 'pyproject.toml').read_text().split('\n')
|
||||||
|
for line in pyproject_config:
|
||||||
|
if line.startswith('version = '):
|
||||||
|
return line.split(' = ', 1)[-1].strip('"')
|
||||||
|
except FileNotFoundError:
|
||||||
|
# building docs, pyproject.toml is not available
|
||||||
|
pass
|
||||||
|
|
||||||
|
try:
|
||||||
|
# if in dev but not in Git repo dir, fallback to using package.json file
|
||||||
|
package_json = (PACKAGE_DIR / 'package.json').read_text().split('\n')
|
||||||
|
for line in package_json:
|
||||||
|
if '"version": "' in line:
|
||||||
|
return line.replace('"', '').split(':')[-1].strip(',')
|
||||||
|
except FileNotFoundError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# raise Exception('Failed to detect installed archivebox version!')
|
||||||
|
return 'dev'
|
||||||
|
|
||||||
VERSION: str = _detect_installed_version(PACKAGE_DIR)
|
VERSION: str = _detect_installed_version(PACKAGE_DIR)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue