mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Ensure schema generation is more stable (#7562)
* Enable passing of enviroment variables * keep server url static see #6882 (3) * keep plugin api out of schema see #6882 (1) * Add kwarg to override db settings * keep currencies stable for schema generation see #6882 (2) * use str instead of bool * add version bump
This commit is contained in:
parent
71680f6fc3
commit
74d3e28e8e
@ -1,11 +1,14 @@
|
|||||||
"""InvenTree API version information."""
|
"""InvenTree API version information."""
|
||||||
|
|
||||||
# InvenTree API version
|
# InvenTree API version
|
||||||
INVENTREE_API_VERSION = 211
|
INVENTREE_API_VERSION = 212
|
||||||
|
|
||||||
"""Increment this API version number whenever there is a significant change to the API that any clients need to know about."""
|
"""Increment this API version number whenever there is a significant change to the API that any clients need to know about."""
|
||||||
|
|
||||||
INVENTREE_API_TEXT = """
|
INVENTREE_API_TEXT = """
|
||||||
|
v212 - 2024-07-06 : https://github.com/inventree/InvenTree/pull/7562
|
||||||
|
- Makes API generation more robust (no functional changes)
|
||||||
|
|
||||||
v211 - 2024-06-26 : https://github.com/inventree/InvenTree/pull/6911
|
v211 - 2024-06-26 : https://github.com/inventree/InvenTree/pull/6911
|
||||||
- Adds API endpoints for managing data import and export
|
- Adds API endpoints for managing data import and export
|
||||||
|
|
||||||
|
@ -59,7 +59,9 @@ def currency_codes() -> list:
|
|||||||
"""Returns the current currency codes."""
|
"""Returns the current currency codes."""
|
||||||
from common.settings import get_global_setting
|
from common.settings import get_global_setting
|
||||||
|
|
||||||
codes = get_global_setting('CURRENCY_CODES', create=False).strip()
|
codes = get_global_setting(
|
||||||
|
'CURRENCY_CODES', create=False, enviroment_key='INVENTREE_CURRENCY_CODES'
|
||||||
|
).strip()
|
||||||
|
|
||||||
if not codes:
|
if not codes:
|
||||||
codes = currency_codes_default_list()
|
codes = currency_codes_default_list()
|
||||||
|
@ -1,10 +1,17 @@
|
|||||||
"""User-configurable settings for the common app."""
|
"""User-configurable settings for the common app."""
|
||||||
|
|
||||||
|
from os import environ
|
||||||
|
|
||||||
def get_global_setting(key, backup_value=None, **kwargs):
|
|
||||||
|
def get_global_setting(key, backup_value=None, enviroment_key=None, **kwargs):
|
||||||
"""Return the value of a global setting using the provided key."""
|
"""Return the value of a global setting using the provided key."""
|
||||||
from common.models import InvenTreeSetting
|
from common.models import InvenTreeSetting
|
||||||
|
|
||||||
|
if enviroment_key:
|
||||||
|
value = environ.get(enviroment_key)
|
||||||
|
if value:
|
||||||
|
return value
|
||||||
|
|
||||||
if backup_value is not None:
|
if backup_value is not None:
|
||||||
kwargs['backup_value'] = backup_value
|
kwargs['backup_value'] = backup_value
|
||||||
|
|
||||||
|
24
tasks.py
24
tasks.py
@ -136,17 +136,20 @@ def managePyPath():
|
|||||||
return managePyDir().joinpath('manage.py')
|
return managePyDir().joinpath('manage.py')
|
||||||
|
|
||||||
|
|
||||||
def manage(c, cmd, pty: bool = False):
|
def manage(c, cmd, pty: bool = False, env=None):
|
||||||
"""Runs a given command against django's "manage.py" script.
|
"""Runs a given command against django's "manage.py" script.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
c: Command line context.
|
c: Command line context.
|
||||||
cmd: Django command to run.
|
cmd: Django command to run.
|
||||||
pty (bool, optional): Run an interactive session. Defaults to False.
|
pty (bool, optional): Run an interactive session. Defaults to False.
|
||||||
|
env (dict, optional): Environment variables to pass to the command. Defaults to None.
|
||||||
"""
|
"""
|
||||||
|
env = env or {}
|
||||||
c.run(
|
c.run(
|
||||||
'cd "{path}" && python3 manage.py {cmd}'.format(path=managePyDir(), cmd=cmd),
|
'cd "{path}" && python3 manage.py {cmd}'.format(path=managePyDir(), cmd=cmd),
|
||||||
pty=pty,
|
pty=pty,
|
||||||
|
env=env,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -1020,9 +1023,12 @@ def setup_test(c, ignore_update=False, dev=False, path='inventree-demo-dataset')
|
|||||||
help={
|
help={
|
||||||
'filename': "Output filename (default = 'schema.yml')",
|
'filename': "Output filename (default = 'schema.yml')",
|
||||||
'overwrite': 'Overwrite existing files without asking first (default = off/False)',
|
'overwrite': 'Overwrite existing files without asking first (default = off/False)',
|
||||||
|
'no_default': 'Do not use default settings for schema (default = off/False)',
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
def schema(c, filename='schema.yml', overwrite=False, ignore_warnings=False):
|
def schema(
|
||||||
|
c, filename='schema.yml', overwrite=False, ignore_warnings=False, no_default=False
|
||||||
|
):
|
||||||
"""Export current API schema."""
|
"""Export current API schema."""
|
||||||
check_file_existance(filename, overwrite)
|
check_file_existance(filename, overwrite)
|
||||||
|
|
||||||
@ -1035,7 +1041,19 @@ def schema(c, filename='schema.yml', overwrite=False, ignore_warnings=False):
|
|||||||
if not ignore_warnings:
|
if not ignore_warnings:
|
||||||
cmd += ' --fail-on-warn'
|
cmd += ' --fail-on-warn'
|
||||||
|
|
||||||
manage(c, cmd, pty=True)
|
envs = {}
|
||||||
|
if not no_default:
|
||||||
|
envs['INVENTREE_SITE_URL'] = (
|
||||||
|
'http://localhost:8000' # Default site URL - to ensure server field is stable
|
||||||
|
)
|
||||||
|
envs['INVENTREE_PLUGINS_ENABLED'] = (
|
||||||
|
'False' # Disable plugins to ensure they are kep out of schema
|
||||||
|
)
|
||||||
|
envs['INVENTREE_CURRENCY_CODES'] = (
|
||||||
|
'AUD,CNY,EUR,USD' # Default currency codes to ensure they are stable
|
||||||
|
)
|
||||||
|
|
||||||
|
manage(c, cmd, pty=True, env=envs)
|
||||||
|
|
||||||
assert os.path.exists(filename)
|
assert os.path.exists(filename)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user