Skip to content

Commit e256d2f

Browse files
authored
Remove PyYAML dependency (#61)
1 parent 6f05b77 commit e256d2f

File tree

4 files changed

+6
-132
lines changed

4 files changed

+6
-132
lines changed

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 1.2.7
2+
3+
- [CHANGED] Removed PyYAML dependency to resolve downstream dependency issues.
4+
- [CHANGED] Removed Github.get_issue_template helper method.
5+
16
# 1.2.6
27

38
- [FIXED] ComplianceFetcher.session can now be reset.

compliance/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
# limitations under the License.
1515
"""Compliance automation package."""
1616

17-
__version__ = '1.2.6'
17+
__version__ = '1.2.7'

compliance/utils/services/github.py

Lines changed: 0 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,15 @@
1414
# limitations under the License.
1515
"""Compliance Github service helper."""
1616

17-
import base64
1817
import json
1918
import random
20-
import re
21-
import sys
2219
from collections import OrderedDict
2320
from urllib.parse import parse_qs, urlparse
2421

2522
from compliance.utils.credentials import Config
2623
from compliance.utils.data_parse import deep_merge
2724
from compliance.utils.http import BaseSession
2825

29-
import yaml
30-
3126

3227
class Github(object):
3328
"""Github service helper class."""
@@ -286,103 +281,6 @@ def get_all_issues(self, owner, repo, **kwargs):
286281
)
287282
return all_issues
288283

289-
def get_issue_template(
290-
self,
291-
owner,
292-
repo,
293-
template_name,
294-
strip_annotations=False,
295-
strip_header=True,
296-
annotations=None,
297-
render=False
298-
):
299-
"""
300-
Retrieve the contents of an issue template based on template name.
301-
302-
The .md extension and any numeric prefix) from the owner and repo
303-
are ignored. Both the header (the YAML section at the top), and any
304-
defined annotations (the JSON code block inside the issue body) are
305-
returned as dictionaries along with the body of the template. You can
306-
pass ``strip_annotations`` or ``strip_header`` to remove these sections
307-
from the body that's returned. You can pass a dictionary as
308-
``annotations``, and the values will be merged with those extracted
309-
from the template.
310-
311-
If ``render`` is ``True``, then all annotations will be substituted on
312-
the body and header.
313-
"""
314-
# get a list of all templates in this repo
315-
path_elements = [
316-
'repos', owner, repo, 'contents', '.github', 'ISSUE_TEMPLATE'
317-
]
318-
response = self._make_request('get', '/'.join(path_elements))
319-
templates = [t['name'] for t in response]
320-
321-
# find the required template, ignoring any numeric prefix
322-
template_file = next(
323-
(
324-
t for t in templates
325-
if re.sub(r'(^[0-9]+\.)?(.*)\.md$', r'\2', t) == template_name
326-
),
327-
None
328-
)
329-
if not template_file:
330-
raise ValueError(f'Template {template_name} not found')
331-
332-
# get the template from .github/ISSUE_TEMPLATE in the
333-
# repo (master branch)
334-
path_elements = [
335-
'repos',
336-
owner,
337-
repo,
338-
'contents',
339-
'.github',
340-
'ISSUE_TEMPLATE',
341-
template_file
342-
]
343-
response = self._make_request('get', '/'.join(path_elements))
344-
345-
# result is base64 encoded (and bytes in py3)
346-
assert response['encoding'] == 'base64'
347-
template = base64.b64decode(response['content'])
348-
template = template.decode(sys.stdout.encoding)
349-
350-
# extract header data structure (YAML)
351-
body_no_header, extracted_header = extract_header(template)
352-
353-
# optionally strip off the leading header section
354-
if strip_header:
355-
template = body_no_header
356-
357-
# extract annotations (JSON)
358-
body_no_annotations, extracted_annotations = extract_annotations(
359-
template
360-
)
361-
362-
# if we were passed some annotations,
363-
# merge them into what's in the template
364-
if annotations:
365-
deep_merge(extracted_annotations, annotations)
366-
367-
if render:
368-
body_no_annotations = body_no_annotations.format(
369-
**extracted_annotations
370-
)
371-
extracted_header = {
372-
k: v.format(**extracted_annotations)
373-
for k,
374-
v in extracted_header.items()
375-
}
376-
# optionally strip off the annotations section
377-
if strip_annotations:
378-
template = body_no_annotations
379-
else:
380-
template = self._annotate_body(
381-
body_no_annotations, extracted_annotations
382-
)
383-
384-
return template, extracted_annotations, extracted_header
385-
386284
def search_issues(
387285
self, query, sort=None, order=None, owner=None, repo=None
388286
):
@@ -605,31 +503,3 @@ def extract_annotations(content):
605503
annotations = OrderedDict({})
606504

607505
return content_no_annotations, annotations
608-
609-
610-
def extract_header(content):
611-
"""
612-
Retrieve header (YAML) from a string (issue body).
613-
614-
Returns the remaining content without the header,
615-
and then the header fields themselves as a dictionary.
616-
"""
617-
header_yaml = []
618-
lines = content.splitlines(True)
619-
if lines[0] == '---\n':
620-
header_yaml.append(lines.pop(0))
621-
line = ''
622-
while line != '---\n':
623-
line = lines.pop(0)
624-
if line != '---\n':
625-
header_yaml.append(line)
626-
if lines[0] == '\n':
627-
lines.pop(0)
628-
629-
content_no_header = ''.join(lines)
630-
if header_yaml:
631-
header_fields = yaml.safe_load(''.join(header_yaml))
632-
else:
633-
header_fields = {}
634-
635-
return content_no_header, header_fields

setup.cfg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ install_requires =
2626
ibm-cloud-security-advisor-findingsapi-sdk>=2.0.5
2727
deprecated>=1.2.9
2828
ilcli>=0.3.1
29-
PyYAML>=5.3.1
3029

3130
[options.packages.find]
3231
exclude =

0 commit comments

Comments
 (0)