Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance extension and config docs #5790

Merged
merged 5 commits into from
Nov 6, 2023
Merged

Conversation

MarcSkovMadsen
Copy link
Collaborator

@MarcSkovMadsen MarcSkovMadsen commented Oct 31, 2023

Closes #3404

You can preview the docs here

I've used the script below to generate the options summary section.

import panel as pn
from textwrap import dedent
import textwrap

NO_ENVIRONMENT_VARIABLE=[
    '_admin', '_theme'
]

ENVIRONMENT_VARIABLE_NAME={
    "_oauth_encryption_key": "PANEL_OAUTH_ENCRYPTION",
    "_nthreads": "PANEL_NTHREADS",
}

def nice_name(key):
    if key.startswith("_"):
        return key[1:]
    return key

def environment_variable(key):
    if key in NO_ENVIRONMENT_VARIABLE:
        return ""
    if key in ENVIRONMENT_VARIABLE_NAME:
        return f" (`{ENVIRONMENT_VARIABLE_NAME[key]}`)" 
    if key.startswith("_"):
        return f" (`PANEL{key.upper()}`)"
    return ""

def nice_default_value(parameter):
    default=parameter.default
    if isinstance(default, str):
        return f"'{default}'"
    return str(default)

def nice_type(parameter):
    if parameter.__class__.__name__ in ["Selector", "ObjectSelector"]:
        return f"""Literal | Options: '{"', '".join([str(object) for object in parameter.objects])}'"""
    return parameter.__class__.__name__

def is_readonly(parameter):
    original = parameter.name.startswith("_") or parameter.constant or parameter.readonly
    new = False
    try:
         setattr(pn.config, parameter.name, getattr(pn.config, parameter.name))
    except:
        new = True
    return new

keys_and_parameters = [(key, pn.config.param[key]) for key in pn.config.param.values() if key!="name"]
keys_and_parameters = sorted(keys_and_parameters, key=lambda x: nice_name(x[0]))

def print_parameters(parameters):
    for key, parameter in parameters:    
        text = f"""\
### `{nice_name(key)}`{environment_variable(key)}

{dedent(pn.config.param[key].doc)}

Default: {nice_default_value(parameter)} | Type: {nice_type(parameter)}
"""
        text = text.replace("`\n\n", "`\n").replace("`)\n\n\n", "`)\n\n")
        print(text)

print("## Options Summary\n")

print_parameters(keys_and_parameters)

@MarcSkovMadsen MarcSkovMadsen added this to the v1.3.2 milestone Oct 31, 2023
Copy link

codecov bot commented Oct 31, 2023

Codecov Report

Merging #5790 (f3e43eb) into main (359ccbe) will increase coverage by 9.94%.
The diff coverage is 75.00%.

@@            Coverage Diff             @@
##             main    #5790      +/-   ##
==========================================
+ Coverage   72.44%   82.39%   +9.94%     
==========================================
  Files         290      290              
  Lines       42161    42164       +3     
==========================================
+ Hits        30544    34740    +4196     
+ Misses      11617     7424    -4193     
Flag Coverage Δ
ui-tests 38.31% <75.00%> (?)
unitexamples-tests 72.44% <75.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
panel/config.py 66.98% <75.00%> (-0.01%) ⬇️

... and 70 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Member

@philippjfr philippjfr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@philippjfr philippjfr merged commit 4606a96 into main Nov 6, 2023
11 of 13 checks passed
@philippjfr philippjfr deleted the enhancement/docs-extension-config branch November 6, 2023 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document pn.extension
2 participants