flamapy-rest 2.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,116 @@
1
+ import os
2
+ import inspect
3
+ import json
4
+
5
+ from flask import Blueprint, request, jsonify
6
+ from flamapy.interfaces.python.flamapy_feature_model import FLAMAFeatureModel
7
+ from flamapy.metamodels.configuration_metamodel.models import Configuration
8
+
9
+
10
+ operations_bp = Blueprint('operations_bp', __name__, url_prefix='/api/v1/operations')
11
+
12
+ MODEL_FOLDER = './resources/models/'
13
+
14
+ class CustomJSONEncoder(json.JSONEncoder):
15
+ def default(self, obj):
16
+ if isinstance(obj, Configuration):
17
+ return obj.__dict__
18
+ return super().default(obj)
19
+
20
+ def _api_call(operation_name: str):
21
+ # Get files
22
+ uploaded_model = request.files['model']
23
+
24
+ # Check if file is provided
25
+ if uploaded_model.filename != '':
26
+ # Save file
27
+ uploaded_model.save(os.path.join(MODEL_FOLDER, uploaded_model.filename))
28
+
29
+ fm = FLAMAFeatureModel(os.path.join(MODEL_FOLDER, uploaded_model.filename))
30
+ operation = getattr(fm, operation_name)
31
+
32
+ # Extract the method signature
33
+ sig = inspect.signature(operation)
34
+ params = sig.parameters
35
+
36
+ args = []
37
+ for param in params.values():
38
+ if param.name == 'feature_name':
39
+ args.append(request.form['feature'])
40
+ elif param.name == 'configuration_path':
41
+ configuration = request.files['configuration']
42
+ configuration.save(os.path.join(MODEL_FOLDER, configuration.filename))
43
+ args.append(os.path.join(MODEL_FOLDER, configuration.filename))
44
+
45
+ result = operation(*args)
46
+
47
+ # Remove file
48
+ os.remove(os.path.join(MODEL_FOLDER, uploaded_model.filename))
49
+
50
+ if 'configuration' in request.files:
51
+ os.remove(os.path.join(MODEL_FOLDER, request.files['configuration'].filename))
52
+
53
+ # Return result
54
+ if result is None:
55
+ return jsonify(error='Not valid result'), 404
56
+ else:
57
+ return jsonify(json.loads(json.dumps(result, cls=CustomJSONEncoder)))
58
+
59
+
60
+ def extract_docstring_with_swagger_info(method):
61
+ docstring = method.__doc__ or ""
62
+ parameters = """
63
+ parameters:
64
+ - name: model
65
+ in: formData
66
+ type: file
67
+ required: true
68
+ """
69
+
70
+ # Extract the method signature
71
+ sig = inspect.signature(method)
72
+ for param in sig.parameters.values():
73
+ if param.name == 'feature_name':
74
+ parameters += """
75
+ - name: feature
76
+ in: formData
77
+ type: string
78
+ required: true
79
+ """
80
+ elif param.name == 'configuration_path':
81
+ parameters += """
82
+ - name: configuration
83
+ in: formData
84
+ type: file
85
+ required: true
86
+ """
87
+
88
+ swagger_info = """
89
+ ---
90
+ tags:
91
+ - {operation_name}
92
+ {parameters}
93
+ responses:
94
+ 200:
95
+ description: Result of the operation
96
+ examples:
97
+ result: Example result
98
+ """.format(operation_name=method.__name__, parameters=parameters)
99
+ # Replace new lines with HTML line breaks
100
+ docstring = docstring.replace('\n', '')
101
+ return docstring + swagger_info
102
+
103
+ def create_route(operation_name: str, docstring: str):
104
+ def route_function():
105
+ return _api_call(operation_name)
106
+
107
+ route_function.__name__ = operation_name
108
+ route_function.__doc__ = docstring
109
+ return route_function
110
+
111
+ # Introspect FLAMAFeatureModel class to find all callable methods and create routes dynamically
112
+ for name, method in inspect.getmembers(FLAMAFeatureModel, predicate=inspect.isfunction):
113
+ if name.startswith('_'):
114
+ continue
115
+ docstring = extract_docstring_with_swagger_info(method)
116
+ operations_bp.route(f'/{name}', methods=['POST'])(create_route(name, docstring))
@@ -0,0 +1,127 @@
1
+ Metadata-Version: 2.1
2
+ Name: flamapy-rest
3
+ Version: 2.0.0
4
+ Summary: Flamapy feature model is a distribution of the flama framework containing all plugins required to analyze feature models. It also offers a richier API and a complete command line interface and documentation.
5
+ Home-page: https://github.com/flamapy/flamapy-feature-model
6
+ Author: Flamapy
7
+ Author-email: flamapy@us.es
8
+ License: UNKNOWN
9
+ Platform: UNKNOWN
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
12
+ Classifier: Operating System :: OS Independent
13
+ Requires-Python: >=3.9
14
+ Description-Content-Type: text/markdown
15
+ Requires-Dist: wheel
16
+ Requires-Dist: Flask
17
+ Requires-Dist: gunicorn
18
+ Requires-Dist: flamapy ==2.0.0
19
+ Requires-Dist: flask-swagger-ui
20
+ Requires-Dist: flask-restplus
21
+ Requires-Dist: pytest
22
+ Requires-Dist: flask-cors
23
+ Requires-Dist: flasgger
24
+ Provides-Extra: dev
25
+ Requires-Dist: pytest ; extra == 'dev'
26
+ Requires-Dist: pytest-mock ; extra == 'dev'
27
+ Requires-Dist: prospector ; extra == 'dev'
28
+ Requires-Dist: mypy ; extra == 'dev'
29
+ Requires-Dist: coverage ; extra == 'dev'
30
+
31
+ <div align="center">
32
+
33
+ <a href="">[![Pytest Testing Suite](https://github.com/flamapy/flamapy-rest/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/flamapy/flamapy-rest/actions/workflows/tests.yml)</a>
34
+ <a href="">[![Commits Syntax Checker](https://github.com/flamapy/flamapy-rest/actions/workflows/commits.yml/badge.svg?branch=main)](https://github.com/flamapy/flamapy-rest/actions/workflows/commits.yml)</a>
35
+ <a href="">![PyPI](https://img.shields.io/pypi/v/flamapy-rest?label=pypi%20package)
36
+ <a href="">![PyPI - Downloads](https://img.shields.io/pypi/dm/flamapy-rest)
37
+ </div>
38
+
39
+ #
40
+
41
+ <div id="top"></div>
42
+ <br />
43
+ <div align="center">
44
+
45
+ <h3 align="center">FLAMAPY rest API</h3>
46
+
47
+ <p align="center">
48
+ A new and easy way to use FLAMA
49
+ <br />
50
+ <a href="https://github.com/flamapy/flamapy-fm-dist/issues">Report Bug</a>
51
+ ·
52
+ <a href="https://github.com/flamapy/flamapy-fm-dist/issues">Request Feature</a>
53
+ </p>
54
+ </div>
55
+ <!-- ABOUT THE PROJECT -->
56
+
57
+ ## About The Project
58
+
59
+ FLAMAPY Feature model distribution provides an easier way of using FLAMA when analysing feature models. It packs the most used plugins for analyis of feature models adding a layer of convenience to use the framework or integrate it.
60
+
61
+ Feature Model Analysis has a crucial role in software product line engineering, enabling us to understand, design, and validate the complex relationships among features in a software product line. These feature models can often be complex and challenging to analyze due to their variability, making it difficult to identify conflicts, dead features, and potential optimizations. This is where this distribution comes in.
62
+
63
+ Please note: This is a living document and we will continue to update and improve it as we release new versions of the plugins and receive feedback from our users. If there's anything you don't understand or if you have any suggestions for improvement, don't hesitate to contact us. We're here to help!
64
+
65
+ Three main interfaces are provided:
66
+ * A REST API: The REST API allows for easy integration with other tools and applications. It is also a more user friendly interface for those who are not familiar with the command line.
67
+
68
+ Whant it to runint, simply run
69
+ ```bash
70
+ pip install flamapy-rest
71
+ gunicorn --bind 0.0.0.0:8000 app:app
72
+ ```
73
+
74
+ Alternatively, you can use docker in this way:
75
+ ```bash
76
+ chmod +x start-server.sh
77
+ ./start-server.sh
78
+ ```
79
+ Or go to [the render deployed version]() it isn't fast, but its free.
80
+
81
+ <p align="right">(<a href="#top">back to top</a>)</p>
82
+
83
+ ### Built With
84
+
85
+ * [Docker](https://www.docker.com/)
86
+ * [Flask](https://flask.palletsprojects.com/en/2.2.x/)
87
+ * [FLAMAPY](https://github.com/flamapy)
88
+ * [Flasgger](https://github.com/flasgger/flasgger)
89
+
90
+ <p align="right">(<a href="#top">back to top</a>)</p>
91
+
92
+ # Using the distribution REST API
93
+ The easies way is to execute the following command: docker run -p 8000:8000 flamapy/flamapy-fm-dist and open localhost:8000
94
+ <!-- GETTING STARTED -->
95
+ ## Getting Started
96
+
97
+ To get a local copy up and running follow these simple example steps.
98
+
99
+ First, you will need to install [Docker](https://docs.docker.com/desktop/).
100
+
101
+ ### Instalation
102
+
103
+ 1. Clone the repository
104
+
105
+ 2. If you are running Windows, run
106
+ ```sh
107
+ $ cd flamapy-dm-dist
108
+ $ ./start-server.cmd
109
+ ```
110
+
111
+ 3. If you are running Linux or MacOS, run
112
+ ```sh
113
+ $ cd flamapy-dm-dist
114
+ $ ./start-server.sh
115
+ ```
116
+
117
+ This script will build, install and deploy the API in http://localhost:8000, you can access all the endpoints through an application like [Postman](https://www.postman.com/)
118
+
119
+ <p align="right">(<a href="#top">back to top</a>)</p>
120
+
121
+ ### API Documentation
122
+
123
+ All the documentation is registered with Swagger UI and OAS 3.0. It is accesible through /api/v1/docs. This documentation is generated dinamically by relyin gon flasgger. DO not forget to document your code in the route files!
124
+
125
+ <p align="right">(<a href="#top">back to top</a>)</p>
126
+
127
+
@@ -0,0 +1,5 @@
1
+ flamapy/interfaces/rest/operations_routes.py,sha256=m08-UYRkqDy1BNldBJvF7oLQcPQ28uaQZKiCDkdg_VE,3729
2
+ flamapy_rest-2.0.0.dist-info/METADATA,sha256=jpFJ4qzqtgl9Wm_BwlBfNv7yPwuLtCqRcN4J7r1K4FE,5024
3
+ flamapy_rest-2.0.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
4
+ flamapy_rest-2.0.0.dist-info/top_level.txt,sha256=2YBI9dg4GVk28AJuyNu6dldi5Riwt5SP0zpNe2lSU5M,8
5
+ flamapy_rest-2.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.43.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ flamapy