2626
2727def build_rpm_with_docker ():
2828 # Load the pyproject.toml file
29- with open (' pyproject.toml' ) as f :
30- project = toml .load (f )[' project' ]
29+ with open (" pyproject.toml" ) as f :
30+ project = toml .load (f )[" project" ]
3131
32- pkg_name = project [' name' ]
32+ pkg_name = project [" name" ]
3333 # Insert "python3-"" prefix that follows a common convention for Python RPMs
3434 rpm_name = f"python3-{ pkg_name .lower ()} "
3535
3636 docker_cmd = [
37- 'docker' , 'run' , '--rm' ,
38- '-v' , f"{ os .getcwd ()} :/workspace" ,
39- '-w' , '/workspace' ,
40- 'fedora:42' ,
41- '/bin/bash' , '-c' ,
37+ "docker" ,
38+ "run" ,
39+ "--rm" ,
40+ "-v" ,
41+ f"{ os .getcwd ()} :/workspace" ,
42+ "-w" ,
43+ "/workspace" ,
44+ "fedora:42" ,
45+ "/bin/bash" ,
46+ "-c" ,
4247 f"""set -ex
43- # Install All build dependencies
44- dnf install -y rpm-build python3-devel python3-setuptools python3-wheel python3-build python3-toml
48+ # Install All build dependencies
49+ dnf install -y rpm-build python3-devel python3-setuptools python3-wheel python3-build python3-toml
4550
46- # Build the wheel
47- python3 -m build --wheel
51+ # Build the wheel
52+ python3 -m build --wheel
4853
49- # Get the wheel file name
50- WHEEL_FILE=$(ls dist/*.whl)
51- if [ -z "$WHEEL_FILE" ]; then
52- echo "Error: No wheel file found in dist/." >&2
53- exit 1
54- fi
55- WHEEL_FILENAME=$(basename "$WHEEL_FILE")
54+ # Get the wheel file name
55+ WHEEL_FILE=$(ls dist/*.whl)
56+ if [ -z "$WHEEL_FILE" ]; then
57+ echo "Error: No wheel file found in dist/." >&2
58+ exit 1
59+ fi
60+ WHEEL_FILENAME=$(basename "$WHEEL_FILE")
5661
57- # Keep RPM version as is for sorting
58- RPM_VERSION="{ project [' version' ].replace ("-dev" , "~dev" )} "
62+ # Keep RPM version as is for sorting
63+ RPM_VERSION="{ project [" version" ].replace ("-dev" , "~dev" )} "
5964
60- # Creates the standard directory structure required by rpmbuild
61- mkdir -p dist/rpmbuild/{{BUILD,RPMS,SOURCES,SPECS,SRPMS}}
62- mv "$WHEEL_FILE" dist/rpmbuild/SOURCES/
65+ # Creates the standard directory structure required by rpmbuild
66+ mkdir -p dist/rpmbuild/{{BUILD,RPMS,SOURCES,SPECS,SRPMS}}
67+ mv "$WHEEL_FILE" dist/rpmbuild/SOURCES/
6368
64- # Get the changelog date
65- CHANGELOG_DATE=$(date '+%a %b %d %Y')
69+ # Get the changelog date
70+ CHANGELOG_DATE=$(date '+%a %b %d %Y')
6671
67- # Generate spec file with correct deps
68- cat > dist/rpmbuild/SPECS/{ rpm_name } .spec << EOF
72+ # Generate spec file with correct deps
73+ cat > dist/rpmbuild/SPECS/{ rpm_name } .spec << EOF
6974Name: { rpm_name }
7075Version: $RPM_VERSION
7176Release: 1%{{?dist}}
72- Summary: { project .get ('description' , 'Automate open source license compliance and ensure supply chain integrity' )}
73-
74- License: { project .get ('license' , 'AGPL-3.0-only' )}
75- URL: { project .get ('urls' , '' ).get ('Homepage' , 'https://github.com/aboutcode-org/dejacode' )}
77+ Summary: {
78+ project .get (
79+ "description" ,
80+ "Automate open source license complianceand ensure supply chain integrity" ,
81+ )
82+ }
83+
84+ License: { project .get ("license" , "AGPL-3.0-only" )}
85+ URL: {
86+ project .get ("urls" , "" ).get ("Homepage" , "https://github.com/aboutcode-org/dejacode" )
87+ }
7688Source0: "$WHEEL_FILENAME"
7789
7890BuildArch: noarch
7991BuildRequires: python3-devel python3-setuptools python3-wheel python3-build python3-toml
8092
8193%description
82- { project .get ('description' , 'Automate open source license compliance and ensure supply chain integrity' )}
94+ {
95+ project .get (
96+ "description" ,
97+ "Automate open source license compliance and ensuresupply chain integrity" ,
98+ )
99+ }
83100
84101%prep
85102
@@ -93,22 +110,26 @@ def build_rpm_with_docker():
93110%{{python3_sitelib}}/*
94111
95112%changelog
96- * $CHANGELOG_DATE { project .get ('authors' , [{}])[0 ].get ('name' , 'nexB Inc.' )} - $RPM_VERSION-1
97- - { project .get ('urls' , '' ).get ('Changelog' , 'https://github.com/aboutcode-org/dejacode/blob/main/CHANGELOG.rst' )}
113+ * $CHANGELOG_DATE { project .get ("authors" , [{}])[0 ].get ("name" , "nexB Inc." )} - $RPM_VERSION-1
114+ - {
115+ project .get ("urls" , "" ).get (
116+ "Changelog" , "https://github.com/aboutcode-org/dejacode/blob/main/CHANGELOG.rst"
117+ )
118+ }
98119EOF
99120
100- # Build the RPM
101- rpmbuild --define "_topdir /workspace/dist/rpmbuild" -bb dist/rpmbuild/SPECS/{ rpm_name } .spec
121+ # Build the RPM
122+ rpmbuild --define "_topdir /workspace/dist/rpmbuild" -bb dist/rpmbuild/SPECS/{ rpm_name } .spec
102123
103- # Fix permissions for Windows host
104- chmod -R u+rwX dist/rpmbuild
105- """
124+ # Fix permissions for Windows host
125+ chmod -R u+rwX dist/rpmbuild
126+ """ ,
106127 ]
107128
108129 try :
109- subprocess .run (docker_cmd , check = True )
130+ subprocess .run (docker_cmd , check = True , shell = False ) # noqa: S603
110131 # Verify the existance of the .rpm
111- rpm_file = next (Path (' dist/rpmbuild/RPMS/noarch' ).glob (' *.rpm' ), None )
132+ rpm_file = next (Path (" dist/rpmbuild/RPMS/noarch" ).glob (" *.rpm" ), None )
112133 if rpm_file :
113134 print (f"\n Success! RPM built: { rpm_file } " )
114135 else :
@@ -119,9 +140,9 @@ def build_rpm_with_docker():
119140 sys .exit (1 )
120141
121142
122- if __name__ == ' __main__' :
143+ if __name__ == " __main__" :
123144 # Check if "docker" is available
124- if not shutil .which (' docker' ):
145+ if not shutil .which (" docker" ):
125146 print ("Error: Docker not found. Please install Docker first." , file = sys .stderr )
126147 sys .exit (1 )
127148
0 commit comments