![LUSID_by_Finbourne](https://content.finbourne.com/LUSID_repo.png)
# Lusid Feature Python Decorator Scanner
## Description
This repository contains source code which provides a python decorator called 'lusid_feature', which can then be used
within a python project to scan through all 'lusid_feature' decorator values in a desired project package. The runner
will then produce an output text file of desired name and path with all lusid_feature codes.
The generated text file is then passed into a Lusid feature reporter python script, which maps the feature codes to
full feature names and their implementation status, ultimately creating a visual features report across all Lusid SDKs.
## Usage
### Installing
Run:
```
pip install lusidfeature
```
### Importing
This repository has two main functions that need to be imported for the scanner to work
1. lusid_feature in lusid_feature.py - The decorator used with functions and methods
2. extract_features_to_file(argv) in reporter - The function that extracts all decorator values and writes them to a file
### Implementing `lusid_feature` decorator
When successfully imported, lusid_feature decorator can be used to decorate functions and methods in the following manner:
```
from lusidfeature import lusid_feature
@lusid_feature("F1")
def some_function():
pass # function/method implementation
```
Rules around using lusid_feature decorator:
- The decorator must always be called with brackets, and have a string value passed. It can optionally contain multiple values.
Correct Usage: ```@lusid_feature("F1") or @lusid_feature("F1", "F2")```
Incorrect Usage:```@lusid_feature```
- The decorator must not have an empty string passed. The following will throw an error:
```@lusid_feature("")```
- The decorator must not have duplicate feature values across the package files that are being scanned.
The following will throw an error if both functions/methods with the same feature codes are found in the same package:
```
@lusid_feature("F1")
def some_function():
pass # function/method implementation
@lusid_feature("F1")
def some_other_function():
pass # function/method implementation
```
### Running the decorator scanner
To extract the feature values and write them to a file, the following function must be imported and run from a main function in a main.py file:
```
from lusidfeature.reporter import extract_features_to_file
def main(argv):
extract_features_to_file(argv)
if __name__ == "__main__":
main(sys.argv)
```
The reason we must use 'if __name__ == "__main__"' with an entry main function is because the decorator scanner
must be run directly, together with strictly required "root project directory", "project package name"
and "output file path" parameters.
### Input parameters (sys.argv)
The command line requires two parameters
- --outpath or -o <br>
This is the full qualified filename of where to create the output file
Examples:
_Windows_:
```
-o <your-absolute-path>\<your-filename>.txt
-o C:\\home\src\output\features.txt
```
_Unix (Mac/Linux)_:
```
-o <your-absolute-path>/<your-filename>.txt
-o home/src/output/features.txt
```
- --package or -p <br>
This is the package that the decorator scanner should look for decorators in
Examples:
```
-p lusid.submodule
-p lusid.submodule.anothersubmodule
-p tests.tutorials
```
- --root or -r <br>
The path of root directory from which the decorator scanner should start traversing packages and modules.
The path must point to a directory within the project folder, and not to a directory outside the project.
(Recommended to be the root SDK folder or src folder rather than the base project path.)
Examples:
_Windows_:
```
-r C:\\home\lusid-sdk-python\sdk
```
_Unix (Mac/Linux)_:
```
-r home/lusid-sdk-python/sdk
```
To run, set your PYTHONPATH for the required folders and run the following example in a similar way:
```
python main.py -p "tests.tutorials" -o "/usr/app/features.txt"
```
## Output file
The decorator scanner should write a file to the specified path with the example content:
features.txt
```
F1
F32
F2
F3
F10
F11
F8
etc...
```
### Stacking decorators
Decorator stacking for lusid_feature is not supported at the moment. The following will NOT yield expected results.
Incorrect usage:
```
@lusid_feature("F1")
@lusid_feature("F2")
def some_function():
pass # function/method implementation
```
Raw data
{
"_id": null,
"home_page": "https://github.com/finbourne/lusid-features-python.git",
"name": "lusidfeature",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "OpenAPI,FINBOURNE,LUSID,LUSID API",
"author": "FINBOURNE Technology",
"author_email": "engineering@finbourne.com",
"download_url": "https://files.pythonhosted.org/packages/56/64/71d0da8a4d0030bbd6ba22ca12bfa2f158f88066be81896640a756faffaf/lusidfeature-0.2.4.tar.gz",
"platform": "",
"description": "![LUSID_by_Finbourne](https://content.finbourne.com/LUSID_repo.png)\n\n# Lusid Feature Python Decorator Scanner\n\n## Description\n\nThis repository contains source code which provides a python decorator called 'lusid_feature', which can then be used\nwithin a python project to scan through all 'lusid_feature' decorator values in a desired project package. The runner\nwill then produce an output text file of desired name and path with all lusid_feature codes.\n\nThe generated text file is then passed into a Lusid feature reporter python script, which maps the feature codes to \nfull feature names and their implementation status, ultimately creating a visual features report across all Lusid SDKs.\n\n## Usage\n\n### Installing\n\nRun:\n```\npip install lusidfeature\n```\n\n### Importing\n\nThis repository has two main functions that need to be imported for the scanner to work\n\n1. lusid_feature in lusid_feature.py - The decorator used with functions and methods\n2. extract_features_to_file(argv) in reporter - The function that extracts all decorator values and writes them to a file\n\n### Implementing `lusid_feature` decorator\n\nWhen successfully imported, lusid_feature decorator can be used to decorate functions and methods in the following manner: \n\n```\nfrom lusidfeature import lusid_feature\n\n@lusid_feature(\"F1\")\ndef some_function():\n pass # function/method implementation\n```\n\nRules around using lusid_feature decorator:\n- The decorator must always be called with brackets, and have a string value passed. It can optionally contain multiple values.\nCorrect Usage: ```@lusid_feature(\"F1\") or @lusid_feature(\"F1\", \"F2\")``` \nIncorrect Usage:```@lusid_feature```\n- The decorator must not have an empty string passed. The following will throw an error: \n```@lusid_feature(\"\")```\n- The decorator must not have duplicate feature values across the package files that are being scanned. \nThe following will throw an error if both functions/methods with the same feature codes are found in the same package:\n```\n@lusid_feature(\"F1\")\ndef some_function():\n pass # function/method implementation\n\n@lusid_feature(\"F1\")\ndef some_other_function():\n pass # function/method implementation\n```\n\n\n### Running the decorator scanner\n\nTo extract the feature values and write them to a file, the following function must be imported and run from a main function in a main.py file:\n\n```\nfrom lusidfeature.reporter import extract_features_to_file\n\ndef main(argv):\n extract_features_to_file(argv)\n\n\nif __name__ == \"__main__\":\n main(sys.argv)\n\n```\n\nThe reason we must use 'if __name__ == \"__main__\"' with an entry main function is because the decorator scanner \nmust be run directly, together with strictly required \"root project directory\", \"project package name\" \nand \"output file path\" parameters.\n\n\n### Input parameters (sys.argv)\n\nThe command line requires two parameters\n\n- --outpath or -o <br>\nThis is the full qualified filename of where to create the output file\n\nExamples:\n\n_Windows_:\n```\n-o <your-absolute-path>\\<your-filename>.txt\n\n-o C:\\\\home\\src\\output\\features.txt\n```\n\n_Unix (Mac/Linux)_:\n```\n-o <your-absolute-path>/<your-filename>.txt\n\n-o home/src/output/features.txt\n```\n- --package or -p <br>\nThis is the package that the decorator scanner should look for decorators in\nExamples:\n```\n-p lusid.submodule\n-p lusid.submodule.anothersubmodule\n-p tests.tutorials\n```\n\n- --root or -r <br>\nThe path of root directory from which the decorator scanner should start traversing packages and modules. \nThe path must point to a directory within the project folder, and not to a directory outside the project. \n(Recommended to be the root SDK folder or src folder rather than the base project path.)\n\nExamples:\n\n_Windows_:\n```\n-r C:\\\\home\\lusid-sdk-python\\sdk\n```\n\n_Unix (Mac/Linux)_:\n```\n-r home/lusid-sdk-python/sdk\n```\n\nTo run, set your PYTHONPATH for the required folders and run the following example in a similar way:\n\n```\npython main.py -p \"tests.tutorials\" -o \"/usr/app/features.txt\"\n```\n\n## Output file\n\nThe decorator scanner should write a file to the specified path with the example content:\n\nfeatures.txt\n\n```\nF1\nF32\nF2\nF3\nF10\nF11\nF8\netc...\n```\n\n### Stacking decorators\n\nDecorator stacking for lusid_feature is not supported at the moment. The following will NOT yield expected results.\n\nIncorrect usage:\n\n```\n@lusid_feature(\"F1\")\n@lusid_feature(\"F2\")\ndef some_function():\n pass # function/method implementation\n```\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "This package will allow to run the main file and retrieve a list of decorated feature methods in a cls",
"version": "0.2.4",
"split_keywords": [
"openapi",
"finbourne",
"lusid",
"lusid api"
],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "f09ee86c678583e5a8a4e0031256b6de",
"sha256": "74c0be6be2e87a7999ddfa56ca365debf7247a0c9060f350b99f8f8871de9445"
},
"downloads": -1,
"filename": "lusidfeature-0.2.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f09ee86c678583e5a8a4e0031256b6de",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 7422,
"upload_time": "2021-06-16T12:59:00",
"upload_time_iso_8601": "2021-06-16T12:59:00.982737Z",
"url": "https://files.pythonhosted.org/packages/0f/74/ac335734338c9b23a652fae6a0a66297da5e59b5b43370d1abf40d730f1b/lusidfeature-0.2.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "b364b2241dc3d4009fcef5048ec3df09",
"sha256": "51efd3e4a58cb3d0c16c8989b36a6db72300342546d53b1afe247926aff5ade0"
},
"downloads": -1,
"filename": "lusidfeature-0.2.4.tar.gz",
"has_sig": false,
"md5_digest": "b364b2241dc3d4009fcef5048ec3df09",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 6833,
"upload_time": "2021-06-16T12:59:02",
"upload_time_iso_8601": "2021-06-16T12:59:02.476016Z",
"url": "https://files.pythonhosted.org/packages/56/64/71d0da8a4d0030bbd6ba22ca12bfa2f158f88066be81896640a756faffaf/lusidfeature-0.2.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2021-06-16 12:59:02",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "finbourne",
"github_project": "lusid-features-python.git",
"lcname": "lusidfeature"
}