ArchLens 0.2__tar.gz
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.
- archlens-0.2/ArchLens.egg-info/PKG-INFO +25 -0
- archlens-0.2/ArchLens.egg-info/SOURCES.txt +33 -0
- archlens-0.2/ArchLens.egg-info/dependency_links.txt +1 -0
- archlens-0.2/ArchLens.egg-info/entry_points.txt +2 -0
- archlens-0.2/ArchLens.egg-info/requires.txt +7 -0
- archlens-0.2/ArchLens.egg-info/top_level.txt +1 -0
- archlens-0.2/PKG-INFO +25 -0
- archlens-0.2/README.md +269 -0
- archlens-0.2/setup.cfg +8 -0
- archlens-0.2/setup.py +34 -0
- archlens-0.2/src/__init__.py +4 -0
- archlens-0.2/src/cli_interface.py +176 -0
- archlens-0.2/src/config.schema.json +94 -0
- archlens-0.2/src/config.template.json +16 -0
- archlens-0.2/src/core/__init__.py +0 -0
- archlens-0.2/src/core/bt_file.py +95 -0
- archlens-0.2/src/core/bt_graph.py +115 -0
- archlens-0.2/src/core/bt_module.py +99 -0
- archlens-0.2/src/git_integration/__init__.py +0 -0
- archlens-0.2/src/git_integration/fetch_git.py +11 -0
- archlens-0.2/src/main.py +2 -0
- archlens-0.2/src/providers/__init__.py +0 -0
- archlens-0.2/src/providers/json/__init__.py +0 -0
- archlens-0.2/src/providers/json/json_render.py +46 -0
- archlens-0.2/src/providers/plantuml/__init__.py +0 -0
- archlens-0.2/src/providers/plantuml/pu_render.py +62 -0
- archlens-0.2/src/utils/__init__.py +0 -0
- archlens-0.2/src/utils/config_manager_singleton.py +14 -0
- archlens-0.2/src/utils/functions.py +38 -0
- archlens-0.2/src/utils/path_manager_singleton.py +54 -0
- archlens-0.2/src/views/__init__.py +0 -0
- archlens-0.2/src/views/utils.py +8 -0
- archlens-0.2/src/views/view_entities.py +225 -0
- archlens-0.2/src/views/view_manager.py +255 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ArchLens
|
|
3
|
+
Version: 0.2
|
|
4
|
+
Summary: Designed for visualizing package dependencies and highlighting differences between branches in GitHub pull requests. It offers customization options to tailor package views.
|
|
5
|
+
Home-page: https://github.com/archlens/ArchLens
|
|
6
|
+
Author: The ArchLens Team
|
|
7
|
+
Author-email: mlun@itu.dk
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
10
|
+
Requires-Dist: plantuml
|
|
11
|
+
Requires-Dist: typer
|
|
12
|
+
Requires-Dist: astroid
|
|
13
|
+
Requires-Dist: six
|
|
14
|
+
Requires-Dist: requests
|
|
15
|
+
Requires-Dist: jsonschema
|
|
16
|
+
Requires-Dist: gitpython
|
|
17
|
+
Dynamic: author
|
|
18
|
+
Dynamic: author-email
|
|
19
|
+
Dynamic: classifier
|
|
20
|
+
Dynamic: description
|
|
21
|
+
Dynamic: home-page
|
|
22
|
+
Dynamic: requires-dist
|
|
23
|
+
Dynamic: summary
|
|
24
|
+
|
|
25
|
+
This is the long description
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
setup.cfg
|
|
3
|
+
setup.py
|
|
4
|
+
ArchLens.egg-info/PKG-INFO
|
|
5
|
+
ArchLens.egg-info/SOURCES.txt
|
|
6
|
+
ArchLens.egg-info/dependency_links.txt
|
|
7
|
+
ArchLens.egg-info/entry_points.txt
|
|
8
|
+
ArchLens.egg-info/requires.txt
|
|
9
|
+
ArchLens.egg-info/top_level.txt
|
|
10
|
+
src/__init__.py
|
|
11
|
+
src/cli_interface.py
|
|
12
|
+
src/config.schema.json
|
|
13
|
+
src/config.template.json
|
|
14
|
+
src/main.py
|
|
15
|
+
src/core/__init__.py
|
|
16
|
+
src/core/bt_file.py
|
|
17
|
+
src/core/bt_graph.py
|
|
18
|
+
src/core/bt_module.py
|
|
19
|
+
src/git_integration/__init__.py
|
|
20
|
+
src/git_integration/fetch_git.py
|
|
21
|
+
src/providers/__init__.py
|
|
22
|
+
src/providers/json/__init__.py
|
|
23
|
+
src/providers/json/json_render.py
|
|
24
|
+
src/providers/plantuml/__init__.py
|
|
25
|
+
src/providers/plantuml/pu_render.py
|
|
26
|
+
src/utils/__init__.py
|
|
27
|
+
src/utils/config_manager_singleton.py
|
|
28
|
+
src/utils/functions.py
|
|
29
|
+
src/utils/path_manager_singleton.py
|
|
30
|
+
src/views/__init__.py
|
|
31
|
+
src/views/utils.py
|
|
32
|
+
src/views/view_entities.py
|
|
33
|
+
src/views/view_manager.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
src
|
archlens-0.2/PKG-INFO
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ArchLens
|
|
3
|
+
Version: 0.2
|
|
4
|
+
Summary: Designed for visualizing package dependencies and highlighting differences between branches in GitHub pull requests. It offers customization options to tailor package views.
|
|
5
|
+
Home-page: https://github.com/archlens/ArchLens
|
|
6
|
+
Author: The ArchLens Team
|
|
7
|
+
Author-email: mlun@itu.dk
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
10
|
+
Requires-Dist: plantuml
|
|
11
|
+
Requires-Dist: typer
|
|
12
|
+
Requires-Dist: astroid
|
|
13
|
+
Requires-Dist: six
|
|
14
|
+
Requires-Dist: requests
|
|
15
|
+
Requires-Dist: jsonschema
|
|
16
|
+
Requires-Dist: gitpython
|
|
17
|
+
Dynamic: author
|
|
18
|
+
Dynamic: author-email
|
|
19
|
+
Dynamic: classifier
|
|
20
|
+
Dynamic: description
|
|
21
|
+
Dynamic: home-page
|
|
22
|
+
Dynamic: requires-dist
|
|
23
|
+
Dynamic: summary
|
|
24
|
+
|
|
25
|
+
This is the long description
|
archlens-0.2/README.md
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
# Architectural Lens
|
|
2
|
+
### This project was originally forked from [Architectural Lens](https://github.com/Perlten/Architectural-Lens), all credit for the groundwork goes to the original authors
|
|
3
|
+
(Fork was detached after work on the original project was discontinued, development continued by the ArchLens organization)
|
|
4
|
+
|
|
5
|
+
##
|
|
6
|
+
ArchLens is a Python software tool that generates customizable visual package views, showcasing the packages in your system and their dependencies. It offers the flexibility to include or exclude specific packages to suit your requirements for comprehensible views.
|
|
7
|
+
|
|
8
|
+
Moreover, ArchLens can highlight the differences between your working branch and a specified remote branch, including added or removed dependencies and created or deleted packages, by using green and red highlighting.
|
|
9
|
+
|
|
10
|
+
Lastly, ArchLens can display the highlighted differences in the system views when a pull request is created on GitHub. It automatically generates the views specified in your config, highlights the differences, and displays them in your pull request, simplifying the review process.
|
|
11
|
+
|
|
12
|
+
To help you get started, this readme includes various options in combination with the setup of a config file.
|
|
13
|
+
|
|
14
|
+
### ArchLens runs is compatible with 3.9 <= Python version <= 3.12.0
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
To install ArchLens, simply use the pip package manager by running the following command:
|
|
19
|
+
|
|
20
|
+
`pip install archlens-preview` (You need administrative right to perform the operation)
|
|
21
|
+
|
|
22
|
+
This will download and install the necessary files and dependencies needed for ArchLens to run properly.
|
|
23
|
+
|
|
24
|
+
## Commands
|
|
25
|
+
|
|
26
|
+
All commands must be run from the project's root folder
|
|
27
|
+
|
|
28
|
+
<b>The system has 4 commands:</b>
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
-`archlens init`- Creates the config template
|
|
32
|
+
|
|
33
|
+
-`archlens render` - Renders the views specified in the config
|
|
34
|
+
|
|
35
|
+
-`archlens render-diff` - Renders the differences in the views between your working branch and a specified branch
|
|
36
|
+
|
|
37
|
+
-`archlens create-action` Creates the github action which will automatically add the difference views to pull requests.
|
|
38
|
+
|
|
39
|
+
# Using the system
|
|
40
|
+
|
|
41
|
+
In this section, we will guide you through using the ArchLens system by explaining the commands and output with the example of an API project called 'zeeguu-api' that can be found at https://github.com/zeeguu/api.
|
|
42
|
+
|
|
43
|
+
Although the project is not large, understanding the system even for this project size of roughly 40 packages can be challenging. To begin generating views, you need to be in the root of your project and run the following command:
|
|
44
|
+
|
|
45
|
+
- `archlens init`
|
|
46
|
+
|
|
47
|
+
This will create an "archlens.json" file in your root folder, where you can edit your desired views. This is the initial config:
|
|
48
|
+
|
|
49
|
+
```json
|
|
50
|
+
{
|
|
51
|
+
"$schema": "https://raw.githubusercontent.com/archlens/ArchLens/master/src/config.schema.json",
|
|
52
|
+
"name": "",
|
|
53
|
+
"rootFolder": "",
|
|
54
|
+
"github": {
|
|
55
|
+
"url": "",
|
|
56
|
+
"branch": "main"
|
|
57
|
+
},
|
|
58
|
+
"saveLocation": "./diagrams/",
|
|
59
|
+
"views": {
|
|
60
|
+
"completeView": {
|
|
61
|
+
"packages": [],
|
|
62
|
+
"ignorePackages": []
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Here are two views of the 'zeeguu-api' project that we will be using as examples:
|
|
70
|
+
|
|
71
|
+
- A complete view of the system
|
|
72
|
+
|
|
73
|
+

|
|
74
|
+
|
|
75
|
+
Hard to grasp? ArchLens agrees with you, which is why this tool exists.
|
|
76
|
+
|
|
77
|
+
- A view of the system where everything except "core" and its sub-packages has been scraped away:
|
|
78
|
+
|
|
79
|
+

|
|
80
|
+
|
|
81
|
+
Here is an edited version of the "archlens.json" file for the 'zeeguu-api' project, which represents the first two views we created earlier, along with comments explaining each field briefly:
|
|
82
|
+
|
|
83
|
+
The "views" field in the "archlens.json" file allows you to define as many views as you need for your project. Simply add a new object with a unique name for each view you want to create. For example, if you wanted to create a view that showed only the "utils" package in the "api" folder, you could add the following to the "views" field:
|
|
84
|
+
|
|
85
|
+
```json
|
|
86
|
+
{
|
|
87
|
+
"$schema": "https://raw.githubusercontent.com/archlens/ArchLens/master/src/config.schema.json",
|
|
88
|
+
"name": "zeeguu", # Name of project
|
|
89
|
+
"rootFolder": "zeeguu", # Name of source folder containing the root package (Usually a folder called src)
|
|
90
|
+
"github": {
|
|
91
|
+
"url": "https://github.com/zeeguu/api", # Link to project's Github
|
|
92
|
+
"branch": "master" # Name of main/master branch of project
|
|
93
|
+
},
|
|
94
|
+
"saveLocation": "./diagrams/", # Location to store generated diagrams
|
|
95
|
+
"views": { # Define each view
|
|
96
|
+
"completeView": { # Name of first view, you may add more
|
|
97
|
+
"packages": [], # Select packages to see in view, if left empty, see entire system view
|
|
98
|
+
"ignorePackages": [] # Specify packages not to include in diagram
|
|
99
|
+
}, "coreView":{ # Create view containing specific packages
|
|
100
|
+
"packages": [
|
|
101
|
+
"core" # In this case, we only allow packages starting with the name 'core'
|
|
102
|
+
],
|
|
103
|
+
"ignorePackages": []
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### You can render the views specified in your "archlens.json" file by running the command:
|
|
111
|
+
- `archlens render`
|
|
112
|
+
|
|
113
|
+
This will generate the diagrams for all the views defined in your configuration file and save them in the location specified in the "saveLocation" field of your configuration.
|
|
114
|
+
|
|
115
|
+
## Further Filtering of packages
|
|
116
|
+
|
|
117
|
+
If you find the core view to be too large, you can create a new view that further filters the packages. Instead of giving a path to the package "core", you can limit it further by specifying that you want to see "core" and only its sub-packages that are 1 layer down.
|
|
118
|
+
|
|
119
|
+
To achieve this, you can create an object instead of a string path for the package, with two fields: "depth" and "path". In the "depth" field, you specify the number of sub-packages you want to include, and in the "path" field, you specify the package to start with.
|
|
120
|
+
|
|
121
|
+
For example, the following configuration file defines a view for the "core" package and its immediate sub-packages:
|
|
122
|
+
|
|
123
|
+

|
|
124
|
+
|
|
125
|
+
This will create a view that shows only the "core" package and its immediate sub-packages.
|
|
126
|
+
|
|
127
|
+
Here is an example of the archlens.json file used to generate the filtered view:
|
|
128
|
+
|
|
129
|
+
```json
|
|
130
|
+
{
|
|
131
|
+
"$schema": "https://raw.githubusercontent.com/archlens/ArchLens/master/src/config.schema.json",
|
|
132
|
+
"name": "zeeguu",
|
|
133
|
+
"rootFolder": "zeeguu",
|
|
134
|
+
"github": {
|
|
135
|
+
"url": "https://github.com/zeeguu/api",
|
|
136
|
+
"branch": "master"
|
|
137
|
+
},
|
|
138
|
+
"saveLocation": "./diagrams/",
|
|
139
|
+
"views": {
|
|
140
|
+
"coreView":{
|
|
141
|
+
"packages": [
|
|
142
|
+
#We create an object instead of a path
|
|
143
|
+
{
|
|
144
|
+
"depth": 1, #We only want 1 layer of sub packages from core
|
|
145
|
+
"path": "core" #Just like before, we give the path
|
|
146
|
+
}
|
|
147
|
+
],
|
|
148
|
+
"ignorePackages": []
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
You can combine both strings and objects when defining packages in the packages array in the configuration file. For example, you can include all packages starting with "api/utils" along with packages in the "core" directory up to a depth of 1 using the following syntax:
|
|
156
|
+
|
|
157
|
+
```json
|
|
158
|
+
|
|
159
|
+
"packages": [
|
|
160
|
+
"api/utils",
|
|
161
|
+
{
|
|
162
|
+
"path": "core",
|
|
163
|
+
"depth": 1
|
|
164
|
+
}
|
|
165
|
+
]
|
|
166
|
+
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Arrows
|
|
170
|
+
Each arrow in the system diagram represents a dependency between two packages, and the number on the arrow indicates the number of dependencies going in that direction. If you prefer not to see these arrows, you can use the optional "showDependencyCount" setting, which is a boolean. When set to "false", the dependency count will be hidden in all views. Here is an example of how to set this option in your archlens.json file:
|
|
171
|
+
|
|
172
|
+
```json
|
|
173
|
+
{
|
|
174
|
+
"$schema": "https://raw.githubusercontent.com/archlens/ArchLens/master/src/config.schema.json",
|
|
175
|
+
"name": "zeeguu", # Name of project
|
|
176
|
+
"rootFolder": "zeeguu", # Name of source folder
|
|
177
|
+
"github": {
|
|
178
|
+
"url": "https://github.com/zeeguu/api", # Link to project's Github
|
|
179
|
+
"branch": "master" # Name of main/master branch of project
|
|
180
|
+
},
|
|
181
|
+
"showDependencyCount": false, <------ here we remove the arrows.
|
|
182
|
+
"saveLocation": "./diagrams/", # Location to store generated diagrams
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
In this ArchLens config file, the dependency count would be gone. This setting is applied to all of the views.
|
|
186
|
+
|
|
187
|
+
## Ignore packages
|
|
188
|
+
In addition to selecting which packages you want in your diagram, you can also select which packages you want removed from your diagram.
|
|
189
|
+
|
|
190
|
+
This can be done in two different ways:
|
|
191
|
+
|
|
192
|
+
```json
|
|
193
|
+
"ignorePackages": [
|
|
194
|
+
"*test*" #Removes any package which contains the word test
|
|
195
|
+
"api/test" #Removes the package api/test and all of its sub packages
|
|
196
|
+
]
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
To clarify, the first method using an asterisk (*) will remove any package containing the specified keyword, while the second method will remove only the specified package and all of its sub-packages. This can be useful for cleaning up clutter in the diagram or for excluding certain packages that are not relevant to the analysis.
|
|
200
|
+
|
|
201
|
+
## The difference views
|
|
202
|
+
To generate a difference view using ArchLens, you need to be on a branch other than the one specified in the configuration file. Usually, you would compare your current branch with the main/master branch, but you have the flexibility to choose any branch you desire. For the following example, I have narrowed down the view by filtering out only the "core/model" package.
|
|
203
|
+
|
|
204
|
+
```json
|
|
205
|
+
{
|
|
206
|
+
"$schema": "https://raw.githubusercontent.com/archlens/ArchLens/master/src/config.schema.json",
|
|
207
|
+
"name": "zeeguu",
|
|
208
|
+
"rootFolder": "zeeguu",
|
|
209
|
+
"github": {
|
|
210
|
+
"url": "https://github.com/zeeguu/api",
|
|
211
|
+
"branch": "master"
|
|
212
|
+
},
|
|
213
|
+
"saveLocation": "./diagrams/",
|
|
214
|
+
"views": {
|
|
215
|
+
"coreView":{
|
|
216
|
+
"packages": [
|
|
217
|
+
"core/model" #Looking at core/model, using the path instead of object, because i want to see the entire sub system
|
|
218
|
+
],
|
|
219
|
+
"ignorePackages": []
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
For the next example, the core view is further filtered to show only "core/model". Three changes were made in comparison to the main branch: the package "smart_watch" was deleted, a new package called "smart_watch_two" was added, and a dependency from "word_knowledge" to "model" was removed.
|
|
225
|
+
|
|
226
|
+
To render this new view displaying the changes, a new command must be run:
|
|
227
|
+
|
|
228
|
+
- `archlens render-diff`
|
|
229
|
+
|
|
230
|
+

|
|
231
|
+
|
|
232
|
+
If there are no diffrences, a diagram without diffrences will still be generated.
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
## Github action - Pull request
|
|
236
|
+
|
|
237
|
+
To display the difference views in your pull requests, run the command:
|
|
238
|
+
|
|
239
|
+
- `archlens create-action`
|
|
240
|
+
|
|
241
|
+
This command generates the necessary files in the .github folder, creating it if it doesn't already exist. Once this is done, you can create a pull request, and the difference view will be visible to the reviewer, as shown in the image below. If there are no diffrences, a diagram without diffrences will still be generated.
|
|
242
|
+
|
|
243
|
+

|
|
244
|
+
|
|
245
|
+
## Contributing
|
|
246
|
+
|
|
247
|
+
Further development on ArchLens is welcomed. To contribute to developing further on ArchLens, we welcome you to fork the repository and propose your additions.
|
|
248
|
+
|
|
249
|
+
Before you start developing, ensure you have a compatible Python version for running ArchLens. ArchLens have been tested for versions after, including, 3.9, up until, and excluding, version 3.12. There are known issues related to running ArchLens with a version after and including version 3.11.
|
|
250
|
+
|
|
251
|
+
After ensuring that the current Python version is compatible with ArchLens, we recommend installing the required packages from the files _requirements.txt_ and _dev-requirements.txt_. This will ensure that the necessary packages to run and test your contributions to ArchLens are in your development environment and that they uphold the minimum version requirements. The installing process has been tested using _pip_, and can be done using the following commands:
|
|
252
|
+
|
|
253
|
+
```
|
|
254
|
+
python -m pip install -r requirements.txt
|
|
255
|
+
python -m pip install -r dev-requirements.txt
|
|
256
|
+
```
|
|
257
|
+
(What you use to install pip packages might differ)
|
|
258
|
+
|
|
259
|
+
Next, to continue setting up your development environment, run the following command:
|
|
260
|
+
```
|
|
261
|
+
python setup.py develop
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
After following these steps, one can use the commando below to run the commands locally:
|
|
265
|
+
```
|
|
266
|
+
python ./src/cli_interface.py [cli_command]
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
For an overview of CLI-commands, look [here](https://github.com/archlens/ArchLens/edit/master/README.md#commands).
|
archlens-0.2/setup.cfg
ADDED
archlens-0.2/setup.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from setuptools import setup, find_packages, glob
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
setup(
|
|
5
|
+
name="ArchLens",
|
|
6
|
+
version="0.2",
|
|
7
|
+
description="Designed for visualizing package dependencies and highlighting differences between"
|
|
8
|
+
" branches in GitHub pull requests. It offers customization options to tailor package views.",
|
|
9
|
+
author="The ArchLens Team",
|
|
10
|
+
author_email="mlun@itu.dk",
|
|
11
|
+
url="https://github.com/archlens/ArchLens",
|
|
12
|
+
packages=find_packages(),
|
|
13
|
+
long_description="This is the long description",
|
|
14
|
+
data_files=glob.glob("src/config.**.json"),
|
|
15
|
+
include_package_data=True,
|
|
16
|
+
install_requires=[
|
|
17
|
+
"plantuml",
|
|
18
|
+
"typer",
|
|
19
|
+
"astroid",
|
|
20
|
+
"six",
|
|
21
|
+
"requests",
|
|
22
|
+
"jsonschema",
|
|
23
|
+
"gitpython",
|
|
24
|
+
],
|
|
25
|
+
classifiers=[
|
|
26
|
+
"Programming Language :: Python :: 3.10",
|
|
27
|
+
"Programming Language :: Python :: 3.9",
|
|
28
|
+
],
|
|
29
|
+
entry_points={
|
|
30
|
+
"console_scripts": [
|
|
31
|
+
"archlens=src.cli_interface:main",
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
)
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import typer
|
|
2
|
+
import json
|
|
3
|
+
import os
|
|
4
|
+
import requests
|
|
5
|
+
import jsonschema
|
|
6
|
+
import tempfile
|
|
7
|
+
import shutil
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from src.providers.json.json_render import save_json, save_json_diff
|
|
10
|
+
from src.providers.plantuml.pu_render import save_plant_uml, save_plant_uml_diff
|
|
11
|
+
from src.utils.path_manager_singleton import PathManagerSingleton
|
|
12
|
+
|
|
13
|
+
# from src.utils.functions import verify_config_options
|
|
14
|
+
from src.utils.config_manager_singleton import ConfigManagerSingleton
|
|
15
|
+
|
|
16
|
+
from src.views.view_manager import render_views, render_diff_views
|
|
17
|
+
|
|
18
|
+
from src.core.bt_graph import BTGraph
|
|
19
|
+
|
|
20
|
+
from src.git_integration.fetch_git import fetch_git_repo
|
|
21
|
+
|
|
22
|
+
from astroid.manager import AstroidManager
|
|
23
|
+
|
|
24
|
+
import astroid
|
|
25
|
+
|
|
26
|
+
astroid.MANAGER = None
|
|
27
|
+
|
|
28
|
+
app = typer.Typer(add_completion=True)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@app.command()
|
|
32
|
+
def render(config_path: str = "archlens.json"):
|
|
33
|
+
config = read_config_file(config_path)
|
|
34
|
+
|
|
35
|
+
mt_path_manager = PathManagerSingleton()
|
|
36
|
+
mt_path_manager.setup(config)
|
|
37
|
+
|
|
38
|
+
am = _create_astroid()
|
|
39
|
+
g = BTGraph(am)
|
|
40
|
+
g.build_graph(config)
|
|
41
|
+
|
|
42
|
+
render_views(g, config, save_plant_uml)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@app.command()
|
|
46
|
+
def render_json(config_path: str = "archlens.json"):
|
|
47
|
+
config = read_config_file(config_path)
|
|
48
|
+
|
|
49
|
+
mt_path_manager = PathManagerSingleton()
|
|
50
|
+
mt_path_manager.setup(config)
|
|
51
|
+
|
|
52
|
+
am = _create_astroid()
|
|
53
|
+
g = BTGraph(am)
|
|
54
|
+
g.build_graph(config)
|
|
55
|
+
|
|
56
|
+
render_views(g, config, save_json)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _create_astroid():
|
|
60
|
+
am = AstroidManager()
|
|
61
|
+
am.brain["astroid_cache"] = {}
|
|
62
|
+
return am
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
@app.command()
|
|
66
|
+
def render_diff(config_path: str = "archlens.json"):
|
|
67
|
+
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
68
|
+
print("Created temporary directory:", tmp_dir)
|
|
69
|
+
config = read_config_file(config_path)
|
|
70
|
+
|
|
71
|
+
fetch_git_repo(tmp_dir, config["github"]["url"], config["github"]["branch"])
|
|
72
|
+
|
|
73
|
+
shutil.copyfile(config_path, os.path.join(tmp_dir, "archlens.json"))
|
|
74
|
+
|
|
75
|
+
config_git = read_config_file(os.path.join(tmp_dir, "archlens.json"))
|
|
76
|
+
|
|
77
|
+
path_manager = PathManagerSingleton()
|
|
78
|
+
path_manager.setup(config, config_git)
|
|
79
|
+
|
|
80
|
+
local_am = _create_astroid()
|
|
81
|
+
local_graph = BTGraph(local_am)
|
|
82
|
+
local_graph.build_graph(config)
|
|
83
|
+
# verify_config_options(config, g)
|
|
84
|
+
|
|
85
|
+
remote_am = _create_astroid()
|
|
86
|
+
remote_graph = BTGraph(remote_am)
|
|
87
|
+
remote_graph.build_graph(config_git)
|
|
88
|
+
# verify_config_options(config_git, g_git)
|
|
89
|
+
|
|
90
|
+
render_diff_views(local_graph, remote_graph, config, save_plant_uml_diff)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
@app.command()
|
|
94
|
+
def render_diff_json(config_path: str = "archlens.json"):
|
|
95
|
+
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
96
|
+
print("Created temporary directory:", tmp_dir)
|
|
97
|
+
config = read_config_file(config_path)
|
|
98
|
+
|
|
99
|
+
fetch_git_repo(tmp_dir, config["github"]["url"], config["github"]["branch"])
|
|
100
|
+
|
|
101
|
+
shutil.copyfile(config_path, os.path.join(tmp_dir, "archlens.json"))
|
|
102
|
+
|
|
103
|
+
config_git = read_config_file(os.path.join(tmp_dir, "archlens.json"))
|
|
104
|
+
|
|
105
|
+
path_manager = PathManagerSingleton()
|
|
106
|
+
path_manager.setup(config, config_git)
|
|
107
|
+
|
|
108
|
+
local_am = _create_astroid()
|
|
109
|
+
local_graph = BTGraph(local_am)
|
|
110
|
+
local_graph.build_graph(config)
|
|
111
|
+
# verify_config_options(config, g)
|
|
112
|
+
|
|
113
|
+
remote_am = _create_astroid()
|
|
114
|
+
remote_graph = BTGraph(remote_am)
|
|
115
|
+
remote_graph.build_graph(config_git)
|
|
116
|
+
# verify_config_options(config_git, g_git)
|
|
117
|
+
|
|
118
|
+
render_diff_views(local_graph, remote_graph, config, save_json_diff)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
@app.command()
|
|
122
|
+
def init(config_path="./archlens.json"):
|
|
123
|
+
os.makedirs(os.path.dirname(config_path), exist_ok=True)
|
|
124
|
+
template_path = os.path.join(os.path.dirname(__file__), "config.template.json")
|
|
125
|
+
schema = None
|
|
126
|
+
with open(template_path, "r") as f:
|
|
127
|
+
schema = json.load(f)
|
|
128
|
+
|
|
129
|
+
schema["name"] = os.path.basename(os.getcwd())
|
|
130
|
+
with open(config_path, "w") as outfile:
|
|
131
|
+
json.dump(schema, outfile, indent=4)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
@app.command()
|
|
135
|
+
def create_action():
|
|
136
|
+
action_url = "https://raw.githubusercontent.com/archlens/ArchLens/master/.github/workflows/render-diff-on-pr.yml"
|
|
137
|
+
action_path = Path(".github/workflows/render-diff-on-pr.yml")
|
|
138
|
+
typer.secho(f"Creating the action at {action_path}", fg="green")
|
|
139
|
+
action_path.parent.mkdir(parents=True, exist_ok=True)
|
|
140
|
+
action = requests.get(action_url).text
|
|
141
|
+
|
|
142
|
+
with open(action_path, "w") as f:
|
|
143
|
+
f.write(action)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def read_config_file(config_path):
|
|
147
|
+
config = None
|
|
148
|
+
with open(config_path, "r") as f:
|
|
149
|
+
config = json.load(f)
|
|
150
|
+
|
|
151
|
+
config_schema = None
|
|
152
|
+
schema_path = os.path.join(os.path.dirname(__file__), "config.schema.json")
|
|
153
|
+
with open(schema_path) as fp:
|
|
154
|
+
config_schema = json.load(fp)
|
|
155
|
+
|
|
156
|
+
if not os.getenv("MT_DEBUG"):
|
|
157
|
+
jsonschema.validate(instance=config, schema=config_schema)
|
|
158
|
+
|
|
159
|
+
config["_config_path"] = os.path.dirname(os.path.abspath(config_path))
|
|
160
|
+
|
|
161
|
+
config["saveLocation"] = os.path.normpath(
|
|
162
|
+
os.path.join(config["_config_path"], config["saveLocation"])
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
config_manager = ConfigManagerSingleton()
|
|
166
|
+
config_manager.setup(config)
|
|
167
|
+
|
|
168
|
+
return config
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def main():
|
|
172
|
+
app()
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
if __name__ == "__main__":
|
|
176
|
+
main()
|