Skip to content

Commit f57ab1a

Browse files
authored
Merge pull request #236 from CycloneDX/enhancement/issue-235-requirements-unpinned-versions
fix: handle `requirements.txt` which contain dependencies without a v…
2 parents c8b00bc + e637e56 commit f57ab1a

File tree

4 files changed

+42
-6
lines changed

4 files changed

+42
-6
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,26 @@ cyclonedx-py -r -rf PATH/TO/requirements.txt -o -
101101

102102
This will generate a CycloneDX and output to STDOUT in XML using the latest schema version `1.3` by default.
103103

104+
#### Unpinned dependencies in `requirements.txt`
105+
106+
If you failed to freeze your dependencies before passing the `requirements.txt` data to `cyclonedx-py`, you'll be
107+
warned about this and the dependencies that do not have pinned versions WILL NOT be included in the resulting CycloneDX
108+
output.
109+
110+
```
111+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
112+
!! Some of your dependencies do not have pinned version !!
113+
!! numbers in your requirements.txt !!
114+
!! !!
115+
!! -> idna !!
116+
!! -> requests !!
117+
!! -> urllib3 !!
118+
!! !!
119+
!! The above will NOT be included in the generated !!
120+
!! CycloneDX as version is a mandatory field. !!
121+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
122+
```
123+
104124
## Python Support
105125

106126
We endeavour to support all functionality for all [current actively supported Python versions](https://www.python.org/downloads/).

cyclonedx_py/client.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,24 @@ def __init__(self, args: argparse.Namespace):
4545
self._debug_message('Parsed Arguments: {}'.format(self._arguments))
4646

4747
def get_output(self) -> BaseOutput:
48+
parser = self._get_input_parser()
49+
50+
if parser.has_warnings():
51+
print('')
52+
print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
53+
print('!! Some of your dependencies do not have pinned version !!')
54+
print('!! numbers in your requirements.txt !!')
55+
print('!! !!')
56+
for warning in parser.get_warnings():
57+
print('!! -> {} !!'.format(warning.get_item().ljust(49)))
58+
print('!! !!')
59+
print('!! The above will NOT be included in the generated !!')
60+
print('!! CycloneDX as version is a mandatory field. !!')
61+
print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
62+
print('')
63+
4864
return get_instance(
49-
bom=Bom.from_parser(self._get_input_parser()),
65+
bom=Bom.from_parser(parser=parser),
5066
output_format=OutputFormat[str(self._arguments.output_format).upper()],
5167
schema_version=SchemaVersion['V{}'.format(
5268
str(self._arguments.output_schema_version).replace('.', '_')

poetry.lock

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

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ include = [
1616

1717
[tool.poetry.dependencies]
1818
python = "^3.6"
19-
cyclonedx-python-lib = "^0.4.0"
19+
cyclonedx-python-lib = "0.4.1"
2020

2121
[tool.poetry.dev-dependencies]
2222
tox = "^3.24.3"

0 commit comments

Comments
 (0)