Skip to content

Commit ae24ba9

Browse files
committed
Added support for Python versions 3.7+
1 parent c750ec6 commit ae24ba9

File tree

7 files changed

+96
-8
lines changed

7 files changed

+96
-8
lines changed

.github/workflows/poetry.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ jobs:
2525
fail-fast: false
2626
matrix:
2727
python-version:
28-
- "3.9" # highest and lowest supported
28+
- "3.9" # highest supported
29+
- "3.8"
30+
- "3.7"
31+
- "3.6" # lowest supported
2932
timeout-minutes: 30
3033
steps:
3134
- name: Checkout

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# Python Library for generating CycloneDX
22

33
[![CircleCI](https://circleci.com/gh/sonatype-nexus-community/cyclonedx-python-lib.svg?style=shield)](https://circleci.com/gh/sonatype-nexus-community/cyclonedx-python-lib)
4+
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/sonatype-nexus-community/cyclonedx-python-lib/Python%20CI)
5+
![Python Version Support](https://img.shields.io/badge/python-3.7%20%7C%203.8%20%7C%203.9-blue)
6+
[![GitHub license](https://img.shields.io/github/license/sonatype-nexus-community/cyclonedx-python-lib)](https://github.com/sonatype-nexus-community/cyclonedx-python-lib/blob/main/LICENSE)
7+
[![GitHub issues](https://img.shields.io/github/issues/sonatype-nexus-community/cyclonedx-python-lib)](https://github.com/sonatype-nexus-community/cyclonedx-python-lib/issues)
8+
[![GitHub forks](https://img.shields.io/github/forks/sonatype-nexus-community/cyclonedx-python-lib)](https://github.com/sonatype-nexus-community/cyclonedx-python-lib/network)
9+
[![GitHub stars](https://img.shields.io/github/stars/sonatype-nexus-community/cyclonedx-python-lib)](https://github.com/sonatype-nexus-community/cyclonedx-python-lib/stargazers)
10+
11+
----
412

513
This CycloneDX module for Python can generate valid CycloneDX bill-of-material document containing an aggregate of all
614
project dependencies.
@@ -159,6 +167,11 @@ _Note: We refer throughout using XPath, but the same is true for both XML and JS
159167
1. N/A is where the CycloneDX standard does not include this
160168
2. If the table above does not refer to an element, it is not currently supported
161169

170+
## Python Support
171+
172+
We endeavour to support all functionality for all [current actively supported Python versions](https://www.python.org/downloads/).
173+
However, some features may not be possible/present in older Python versions due to their lack of support.
174+
162175
## The Fine Print
163176

164177
Remember:

cyclonedx/parser/environment.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
import sys
2+
3+
if sys.version_info >= (3, 8, 0):
4+
from importlib.metadata import metadata
5+
else:
6+
from importlib_metadata import metadata
7+
18
from . import BaseParser
29

310
from ..model.cyclonedx import Component
@@ -12,14 +19,20 @@ class EnvironmentParser(BaseParser):
1219

1320
def __init__(self):
1421
import pkg_resources
15-
from importlib.metadata import metadata
1622

1723
i: pkg_resources.DistInfoDistribution
1824
for i in iter(pkg_resources.working_set):
1925
c = Component(name=i.project_name, version=i.version)
20-
i_metadata = metadata(i.project_name)
2126

27+
i_metadata = self._get_metadata_for_package(i.project_name)
2228
if 'Author' in i_metadata.keys():
2329
c.set_author(i_metadata.get('Author'))
2430

2531
self._components.append(c)
32+
33+
@staticmethod
34+
def _get_metadata_for_package(package_name: str):
35+
if sys.version_info >= (3, 8, 0):
36+
return metadata(package_name)
37+
else:
38+
return metadata(package_name)

poetry.lock

Lines changed: 60 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ authors = ["Paul Horton <[email protected]>"]
66
license = "Apache-2.0"
77

88
[tool.poetry.dependencies]
9-
python = "^3.9"
9+
python = "^3.7"
1010
packageurl-python = "^0.9.4"
1111
requirements_parser = "^0.2.0"
1212
setuptools = "^50.3.2"
13+
importlib-metadata = "^4.8.1"
1314

1415
[tool.poetry.dev-dependencies]
1516
tox = "^3.24.3"

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
'Programming Language :: Python :: 3'
3030
],
3131
packages=find_packages(),
32-
python_requires='>=3.9',
32+
python_requires='>=3.7',
3333
package_data={
3434
'cyclonedx': ['schema/*.json', 'schema/*.xsd', 'schema/ext/*.json', 'schema/ext/*.xsd']
3535
},

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tox]
22
minversion=3.9.0
3-
envlist = flake8,py39
3+
envlist = flake8,py39,py38,py37
44

55
[testenv]
66
deps =

0 commit comments

Comments
 (0)