Skip to content

Commit 338d1c0

Browse files
Check SONiC dependencies before installation. (#2716)
#### What I did SONiC related packages shouldn't be intalled from Pypi. It is security compliance requirement. Check SONiC related packages when using setup.py.
1 parent 64d2efd commit 338d1c0

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

setup.py

+26-5
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,34 @@
55
# under scripts/. Consider stop using scripts and use console_scripts instead
66
#
77
# https://stackoverflow.com/questions/18787036/difference-between-entry-points-console-scripts-and-scripts-in-setup-py
8+
from __future__ import print_function
9+
import sys
810
import fastentrypoints
911

1012
from setuptools import setup
13+
import pkg_resources
14+
from packaging import version
15+
16+
# sonic_dependencies, version requirement only supports '>='
17+
sonic_dependencies = [
18+
'sonic-config-engine',
19+
'sonic-platform-common',
20+
'sonic-py-common',
21+
'sonic-yang-mgmt',
22+
]
23+
24+
for package in sonic_dependencies:
25+
try:
26+
package_dist = pkg_resources.get_distribution(package.split(">=")[0])
27+
except pkg_resources.DistributionNotFound:
28+
print(package + " is not found!", file=sys.stderr)
29+
print("Please build and install SONiC python wheels dependencies from sonic-buildimage", file=sys.stderr)
30+
exit(1)
31+
if ">=" in package:
32+
if version.parse(package_dist.version) >= version.parse(package.split(">=")[1]):
33+
continue
34+
print(package + " version not match!", file=sys.stderr)
35+
exit(1)
1136

1237
setup(
1338
name='sonic-utilities',
@@ -211,16 +236,12 @@
211236
'prettyprinter>=0.18.0',
212237
'pyroute2>=0.5.14, <0.6.1',
213238
'requests>=2.25.0',
214-
'sonic-config-engine',
215-
'sonic-platform-common',
216-
'sonic-py-common',
217-
'sonic-yang-mgmt',
218239
'tabulate==0.8.2',
219240
'toposort==1.6',
220241
'www-authenticate==0.9.2',
221242
'xmltodict==0.12.0',
222243
'lazy-object-proxy',
223-
],
244+
] + sonic_dependencies,
224245
setup_requires= [
225246
'pytest-runner',
226247
'wheel'

0 commit comments

Comments
 (0)