Skip to content

Commit 9fa810c

Browse files
authored
Merge pull request #686 from KnowledgeCaptureAndDiscovery/dev
Dev
2 parents 3c9f27d + 02894dc commit 9fa810c

File tree

3 files changed

+76
-9
lines changed

3 files changed

+76
-9
lines changed

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,24 @@ With the following instruction, we can see the environments available in the pro
158158
poetry env list
159159
```
160160

161-
And this way, we enter the virtual environment established by Poetry. Once inside the environment, we can perform the installation test for SOMEF detailed later.
161+
Now we need to access our virtual environment, to do so you have to install the [poetry plugin shell](https://github.com/python-poetry/poetry-plugin-shell) and run the following possible commands:
162162

163+
- If you want to install the `shell` plugin is via the `self add` command of Poetry
164+
```
165+
poetry self add poetry-plugin-shell
166+
```
167+
- or if you used pipx to install Poetry:
168+
```
169+
pipx inject poetry poetry-plugin-shell
170+
```
171+
- otherwise if you used pip install:
172+
```
173+
pip install poetry-plugin-shell
174+
```
175+
After `shell` is set up, you can run the following comand to access the virtual environment
163176
```
164177
poetry shell
165178
```
166-
167179
Test SOMEF installation
168180

169181
```bash

src/somef/export/json_export.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ def save_codemeta_output(repo_data, outfile, pretty=False):
3838
@param outfile: path where to save the codemeta file
3939
@param pretty: option to show the JSON results in a nice format
4040
"""
41-
4241
def format_date(date_string):
4342
date_object = date_parser.parse(date_string)
4443
return date_object.strftime("%Y-%m-%d")
@@ -67,8 +66,12 @@ def format_date(date_string):
6766
author_name = None
6867
if constants.CAT_OWNER in repo_data:
6968
author_name = repo_data[constants.CAT_OWNER][0][constants.PROP_RESULT][constants.PROP_VALUE]
69+
70+
# add a check for the existence of the 'description' property, similar way to most properties in the method.
71+
descriptions = None
72+
if constants.CAT_DESCRIPTION in repo_data:
73+
descriptions = repo_data[constants.CAT_DESCRIPTION]
7074

71-
descriptions = repo_data[constants.CAT_DESCRIPTION]
7275
descriptions_text = []
7376
if descriptions is not None:
7477
descriptions.sort(key=lambda x: (x[constants.PROP_CONFIDENCE] + (1 if x[constants.PROP_TECHNIQUE] == constants.GITHUB_API else 0)),
@@ -85,12 +88,30 @@ def format_date(date_string):
8588
for l in repo_data[constants.CAT_LICENSE]:
8689
if constants.PROP_NAME in l[constants.PROP_RESULT].keys():
8790
l_result["name"] = l[constants.PROP_RESULT][constants.PROP_NAME]
91+
# else:
92+
# print(f"PROP_NAME key not found in: {l[constants.PROP_RESULT].keys()}")
93+
94+
# change this structure because is posible l_result["url"] doesnt exist
95+
# if "url" not in l_result.keys() and constants.PROP_URL in l[constants.PROP_RESULT].keys():
96+
# l_result["url"] = l[constants.PROP_RESULT][constants.PROP_URL]
97+
# # We get the first license we find from the repo
98+
# elif l[constants.PROP_TECHNIQUE] == constants.TECHNIQUE_FILE_EXPLORATION and constants.PROP_SOURCE in l.keys() and "api.github.com" in l_result["url"]:
99+
# l_result["url"] = l[constants.PROP_SOURCE]
100+
101+
# checking if PROP_URL is in the keys PROP_RESULT and key "url" is not in results
88102
if "url" not in l_result.keys() and constants.PROP_URL in l[constants.PROP_RESULT].keys():
89-
l_result["url"] = l[constants.PROP_RESULT][constants.PROP_URL]
90-
# We get the first license we find from the repo
91-
elif l[constants.PROP_TECHNIQUE] == constants.TECHNIQUE_FILE_EXPLORATION \
92-
and constants.PROP_SOURCE in l.keys() and "api.github.com" in l_result["url"]:
93-
l_result["url"] = l[constants.PROP_SOURCE]
103+
l_result["url"] = l[constants.PROP_RESULT][constants.PROP_URL]
104+
# else:
105+
# print(f"PROP_URL key not found in: {l[constants.PROP_RESULT].keys()}")
106+
107+
# Thist block run if url is not found in the previous
108+
if l[constants.PROP_TECHNIQUE] == constants.TECHNIQUE_FILE_EXPLORATION and constants.PROP_SOURCE in l.keys():
109+
if "url" in l_result and "api.github.com" in l_result["url"]:
110+
l_result["url"] = l[constants.PROP_SOURCE]
111+
else:
112+
if "url" not in l_result.keys() and constants.PROP_URL in l[constants.PROP_RESULT].keys():
113+
l_result["url"] = l[constants.PROP_RESULT][constants.PROP_URL]
114+
94115
codemeta_output["license"] = l_result
95116
if code_repository is not None:
96117
codemeta_output["codeRepository"] = code_repository
@@ -118,6 +139,7 @@ def format_date(date_string):
118139
install_links.append(inst[constants.PROP_SOURCE])
119140
elif inst[constants.PROP_TECHNIQUE] == constants.TECHNIQUE_FILE_EXPLORATION:
120141
install_links.append(inst[constants.PROP_RESULT][constants.PROP_VALUE])
142+
121143
if constants.CAT_DOCUMENTATION in repo_data:
122144
for inst in repo_data[constants.CAT_DOCUMENTATION]:
123145
if inst[constants.PROP_TECHNIQUE] == constants.TECHNIQUE_HEADER_ANALYSIS and constants.PROP_SOURCE in inst.keys():
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import os
2+
import unittest
3+
from pathlib import Path
4+
from .. import somef_cli
5+
from ..utils import constants
6+
7+
test_data_path = str(Path(__file__).parent / "test_data") + os.path.sep
8+
9+
class TestCodemetaGitlabExport(unittest.TestCase):
10+
def test_codemeta_gitlab_export(self):
11+
"""Checks if codemeta file has been exported from a gitlab repo"""
12+
somef_cli.run_cli(threshold=0.8,
13+
ignore_classifiers=False,
14+
repo_url='https://gitlab.com/escape-ossr/eossr',
15+
doc_src=None,
16+
in_file=None,
17+
output=None,
18+
graph_out=None,
19+
graph_format="turtle",
20+
codemeta_out=test_data_path + 'test_gitlab.json',
21+
pretty=False,
22+
missing=False)
23+
24+
json_file_path = test_data_path + "test_gitlab.json"
25+
# check if the file has been created in the correct path
26+
assert os.path.exists(json_file_path), f"File {json_file_path} doesn't exist."
27+
28+
text_file = open(test_data_path + "test_gitlab.json", "r")
29+
data = text_file.read()
30+
text_file.close()
31+
# check if has been correctly created with the normal structure
32+
assert data.find(constants.CAT_IDENTIFIER) > 0
33+
os.remove(test_data_path + "test_gitlab.json")

0 commit comments

Comments
 (0)