-
Notifications
You must be signed in to change notification settings - Fork 58
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
M kovalsky/dynamicdocumentation #121
Open
m-kovalsky
wants to merge
18
commits into
microsoft:main
Choose a base branch
from
m-kovalsky:m-kovalsky/dynamicdocumentation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
1313b82
dynamically generate readme with function list categorized
m-kovalsky ce36b69
added function_examples.md
m-kovalsky 05d62ed
added logic for parameters
m-kovalsky 34ce30a
updated with parameters, returns
m-kovalsky 5dba914
updates per comments
m-kovalsky 108cfa0
added index.md within docs
m-kovalsky 28df357
added pages.yaml
m-kovalsky 766ba7f
added workflow dispatch
m-kovalsky 8a23eb6
added pip installs
m-kovalsky 797cf0a
added azure-core
m-kovalsky 8e8ced9
azure storage blob
m-kovalsky ae9618a
mkdir
m-kovalsky 3294d7c
build_outputs_folder
m-kovalsky 932b5cd
run
m-kovalsky 161d79f
again
m-kovalsky 601be23
added _config.yml
m-kovalsky 6fa7aad
update
m-kovalsky 3d20485
v3
m-kovalsky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import inspect | ||
import os | ||
import typing | ||
import sempy_labs | ||
import sempy_labs.migration | ||
import sempy_labs.report | ||
import sempy_labs.directlake | ||
from sempy_labs.tom import TOMWrapper | ||
import sempy_labs.lakehouse | ||
|
||
dirs = { | ||
sempy_labs: 'labs', | ||
sempy_labs.directlake: 'directlake', | ||
sempy_labs.lakehouse: 'lake', | ||
sempy_labs.migration: 'migration', | ||
sempy_labs.report: 'rep', | ||
TOMWrapper: 'tom', | ||
} | ||
|
||
link_prefix = "https://semantic-link-labs.readthedocs.io/en/stable/" | ||
tab = ' ' | ||
skip_functions = ['connect_semantic_model', '__init__', 'close'] | ||
|
||
markdown_example = '## Function Examples\n' | ||
# Function Examples | ||
for d, d_alias in dirs.items(): | ||
d_name = d.__name__ | ||
for attr_name in dir(d): | ||
attr = getattr(d, attr_name) | ||
if inspect.isfunction(attr): | ||
if attr_name not in skip_functions: | ||
link = f"{link_prefix}{d_name}.html#{d_name}.{attr_name}" | ||
if d_alias == 'tom': | ||
link = f"{link_prefix}sempy_labs.{d_alias}.html#sempy_labs.{d_alias}.{d_name}.{attr_name}" | ||
sig = inspect.signature(attr) | ||
markdown_example += f"\n### [{attr_name}]({link})\n```python" | ||
markdown_example += "\nimport sempy_labs as labs" | ||
if d_alias == 'tom': | ||
markdown_example += "\nfrom sempy_labs.tom import connect_semantic_model" | ||
tf = 'True' | ||
markdown_example += f"\nwith connect_semantic_model(dataset='', workspace='', readonly={tf}) as tom:" | ||
elif d_alias != 'labs': | ||
markdown_example += f"\nimport {d_name} as {d_alias}" | ||
func_print = f"{d_alias}.{attr_name}(" | ||
if d_alias == 'tom': | ||
markdown_example += f"\n{tab}{func_print}" | ||
else: | ||
markdown_example += f"\n{func_print}" | ||
params = [param for param_name, param in sig.parameters.items() if param_name not in ['kwargs', 'self']] | ||
param_count = len(params) | ||
for param_name, param in sig.parameters.items(): | ||
is_optional = False | ||
if param_name not in ['kwargs', 'self']: | ||
param_value = '' | ||
if param.default != inspect.Parameter.empty: | ||
param_value = param.default | ||
is_optional = True | ||
elif param_name == 'dataset': | ||
m-kovalsky marked this conversation as resolved.
Show resolved
Hide resolved
|
||
param_value = "AdvWorks" | ||
elif param_name in ['email_address', 'user_name']: | ||
param_value = '[email protected]' | ||
elif param_name == 'languages': | ||
param_value = ['it-IT', 'zh-CN'] | ||
elif param_name == 'dax_query': | ||
param_value = 'EVALUATE SUMMARIZECOLUMNS("MyMeasure", 1)' | ||
elif param_name == 'column': | ||
param_value = 'tom.model.Tables["Geography"].Columns["GeographyKey"]' | ||
elif param_name in ['object']: | ||
if attr_name in ['row_count', 'total_size', 'used_in_relationships', 'used_in_rls', 'set_translation']: | ||
param_value = 'tom.model.Tables["Sales"]' | ||
elif attr_name in ['records_per_segment']: | ||
param_value = 'tom.model.Tables["Sales"].Partitions["Sales"]' | ||
elif attr_name in ['used_size']: | ||
param_value = 'tom.model.Tables["Geography"].Hierarchies["Geo Hierarchy"]' | ||
elif attr_name in ['fully_qualified_measures']: | ||
param_value = 'tom.model.Tables["Sales"].Measures["Sales Amount"]' | ||
elif param_name == 'dependencies': | ||
param_value = 'labs.get_model_calc_dependencies(dataset=tom._dataset, workspace=tom._workspace)' | ||
|
||
if param_value not in [None, True, False] and not isinstance(param_value, list) and param_name not in ['object', 'column', 'dependencies']: | ||
param_value = f"'{param_value}'" | ||
p = f"{tab}{param_name}={param_value}," | ||
if is_optional: | ||
p += " # This parameter is optional" | ||
if d_alias == 'tom': | ||
markdown_example += f"\n{tab}{p}" | ||
else: | ||
markdown_example += f"\n{p}" | ||
closing = ")\n```\n" | ||
if param_count == 0: | ||
markdown_example += closing | ||
else: | ||
markdown_example += f"\n{closing}" | ||
|
||
output_path = os.path.join('/root/semantic-link-labs', 'function_examples.md') | ||
with open(output_path, 'w') as f: | ||
f.write(markdown_example) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you reduce the nesting a bit by maybe building up a list first?
from what I can see you should be able to a do single list comprehension with loops + ifs?