Skip to content

Commit 9895952

Browse files
authored
Merge pull request #159 from M4rtinK/master-modernize_setup.py
Modernize project build
2 parents 181c42e + b843e93 commit 9895952

File tree

5 files changed

+93
-73
lines changed

5 files changed

+93
-73
lines changed

.packit.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ upstream_package_name: initial-setup
33
upstream_tag_template: r{version}-1
44
srpm_build_deps:
55
- make
6+
- python3-build
67
actions:
78
create-archive:
89
- "make BUILD_ARGS=sdist archive"

Makefile

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ RELEASE=$(shell awk '/Release:/ { print $$2 }' $(PKGNAME).spec | sed -e 's|%.*$$
2626
TAG=r$(VERSION)-$(RELEASE)
2727

2828
PYTHON=python3
29-
# Arguments used for setup.py call for creating archive
30-
BUILD_ARGS ?= sdist bdist_wheel
29+
# Use modern python -m build instead of setup.py
30+
BUILD_CMD ?= $(PYTHON) -m build
3131

3232
# LOCALIZATION SETTINGS
3333
L10N_REPOSITORY ?= https://github.com/rhinstaller/initial-setup-l10n.git
@@ -45,13 +45,13 @@ all: po-files
4545

4646
.PHONY: install
4747
install:
48-
$(PYTHON) setup.py install --root=$(DESTDIR)
48+
$(PYTHON) -m pip install . --root=$(DESTDIR) --verbose --no-deps --no-build-isolation
4949
$(MAKE) -C po install
5050

5151
.PHONY: clean
5252
clean:
5353
-rm *.tar.gz ChangeLog initial-setup-*.src.rpm
54-
-rm -rf $(TEST_BUILD_DIR) dist/ initial_setup.egg-info
54+
-rm -rf $(TEST_BUILD_DIR) dist/ build/ *.egg-info
5555
-find . -name "*.pyc" -exec rm -rf {} \;
5656

5757
# local run of TMT tests
@@ -91,15 +91,23 @@ release:
9191

9292
.PHONY: archive
9393
archive: po-pull ChangeLog
94-
$(PYTHON) setup.py $(BUILD_ARGS)
94+
$(BUILD_CMD)
95+
# Fix naming: setuptools creates initial_setup-* but we want initial-setup-*
96+
if [ -f "dist/initial_setup-$(VERSION).tar.gz" ]; then \
97+
cd dist && \
98+
tar -xzf initial_setup-$(VERSION).tar.gz && \
99+
mv initial_setup-$(VERSION) $(PKGNAME)-$(VERSION) && \
100+
tar -czf $(PKGNAME)-$(VERSION).tar.gz $(PKGNAME)-$(VERSION) && \
101+
rm -rf initial_setup-$(VERSION).tar.gz $(PKGNAME)-$(VERSION); \
102+
fi
95103
@echo "The archive is in $(PKGNAME)-$(VERSION).tar.gz"
96104

97105
.PHONY: local
98106
local: po-pull ChangeLog
99107
@rm -rf $(PKGNAME)-$(VERSION).tar.gz
100108
@rm -rf /tmp/$(PKGNAME)-$(VERSION) /tmp/$(PKGNAME)
101109
@dir=$$PWD; cp -a $$dir /tmp/$(PKGNAME)-$(VERSION)
102-
@cd /tmp/$(PKGNAME)-$(VERSION) ; $(PYTHON) setup.py -q sdist
110+
@cd /tmp/$(PKGNAME)-$(VERSION) ; $(PYTHON) -m build --sdist --no-isolation
103111
@cp /tmp/$(PKGNAME)-$(VERSION)/dist/$(PKGNAME)-$(VERSION).tar.gz .
104112
@rm -rf /tmp/$(PKGNAME)-$(VERSION)
105113
@echo "The archive is in $(PKGNAME)-$(VERSION).tar.gz"
@@ -166,10 +174,10 @@ bumpver: po-push
166174
(head -n $$cl initial-setup.spec ; echo "$$DATELINE" ; make --quiet --no-print-directory rpmlog 2>/dev/null ; echo ""; cat speclog) > initial-setup.spec.new ; \
167175
mv initial-setup.spec.new initial-setup.spec ; rm -f speclog ; \
168176
sed -i "s/Version: $(VERSION)/Version: $$NEWVERSION/" initial-setup.spec ; \
169-
sed -i "s/version = \"$(VERSION)\"/version = \"$$NEWVERSION\"/" setup.py ; \
177+
sed -i "s/version = \"$(VERSION)\"/version = \"$$NEWVERSION\"/" pyproject.toml ; \
170178
sed -i "s/__version__ = \"$(VERSION)\"/__version__ = \"$$NEWVERSION\"/" initial_setup/__init__.py ; \
171179

172180
.PHONY: commit
173181
commit:
174-
git add initial-setup.spec initial_setup/__init__.py po/initial-setup.pot setup.py ; \
182+
git add initial-setup.spec initial_setup/__init__.py po/initial-setup.pot pyproject.toml ; \
175183
git commit -m "New version $(VERSION)" ; \

initial-setup.spec

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ Source0: %{name}-%{version}.tar.gz
2121

2222
BuildRequires: gettext
2323
BuildRequires: python3-devel
24-
BuildRequires: python3-setuptools
2524
BuildRequires: systemd-units
2625
BuildRequires: gtk3-devel
2726
BuildRequires: glade-devel
@@ -138,12 +137,21 @@ RemovePathPostfixes: .guixorg
138137
# remove upstream egg-info
139138
rm -rf *.egg-info
140139

140+
%generate_buildrequires
141+
%pyproject_buildrequires
142+
141143
%build
142144
%make_build
143145

144146
%install
145147
%make_install
146148

149+
# Manually install configuration files to /etc (avoid /usr/etc issue)
150+
install -d %{buildroot}%{_sysconfdir}/%{name}/conf.d
151+
install -m 644 data/10-initial-setup.conf %{buildroot}%{_sysconfdir}/%{name}/conf.d/
152+
install -d %{buildroot}%{_sysconfdir}/pam.d
153+
install -m 644 pam/initial-setup %{buildroot}%{_sysconfdir}/pam.d/
154+
147155
# Remove the default link, provide subpackages for alternatives
148156
rm %{buildroot}%{_libexecdir}/%{name}/run-gui-backend
149157

pyproject.toml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
[build-system]
2+
requires = ["setuptools>=61.0", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "initial-setup"
7+
version = "0.3.101"
8+
authors = [
9+
{name = "Martin Kolman", email = "mkolman@redhat.com"}
10+
]
11+
description = "Post-installation configuration utility"
12+
readme = "README.rst"
13+
license = {text = "GPL-2.0-or-later"}
14+
keywords = ["firstboot", "initial", "setup"]
15+
classifiers = [
16+
"Development Status :: 3 - Alpha",
17+
"Environment :: X11 Applications :: GTK",
18+
"Environment :: Console",
19+
"Intended Audience :: System Administrators",
20+
"Topic :: System :: Systems Administration",
21+
"Programming Language :: Python :: 3",
22+
]
23+
requires-python = ">=3.8"
24+
dynamic = ["dependencies"]
25+
26+
[project.urls]
27+
Homepage = "https://fedoraproject.org/wiki/InitialSetup"
28+
Repository = "https://github.com/rhinstaller/initial-setup"
29+
issues = "https://github.com/rhinstaller/initial-setup/issues"
30+
31+
[tool.setuptools.packages.find]
32+
exclude = ["po*", "scripts*", "systemd*", "tests*"]
33+
34+
[tool.setuptools.package-data]
35+
"*" = ["*.glade"]
36+
37+
[tool.setuptools.data-files]
38+
"lib/systemd/system" = ["systemd/*.service"]
39+
"libexec/initial-setup" = [
40+
"scripts/run-initial-setup",
41+
"scripts/firstboot-windowmanager",
42+
"scripts/initial-setup-text",
43+
"scripts/initial-setup-graphical",
44+
"scripts/run-gui-backend.guixorg",
45+
"scripts/run-gui-backend.guiweston",
46+
"scripts/run-gui-backend",
47+
"scripts/reconfiguration-mode-enabled"
48+
]
49+
"share/doc/initial-setup" = ["ChangeLog"]
50+
51+
[tool.setuptools.dynamic]
52+
dependencies = {file = ["requirements.txt"]}

setup.py

Lines changed: 15 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,21 @@
1-
#!/usr/bin/python3
2-
# Setup file for initial-setup
3-
#
4-
# Copyright (C) 2020 Red Hat, Inc.
5-
#
6-
# This program is free software: you can redistribute it and/or modify
7-
# it under the terms of the GNU General Public License as published by
8-
# the Free Software Foundation, either version 2 of the License, or
9-
# (at your option) any later version.
10-
#
11-
# This program is distributed in the hope that it will be useful, but
12-
# WITHOUT ANY WARRANTY; without even the implied warranty of
13-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14-
# General Public License for more details.
15-
#
16-
# You should have received a copy of the GNU General Public License
17-
# along with this program. If not, see
18-
# <http://www.gnu.org/licenses/>.
19-
#
1+
#!/usr/bin/env python3
2+
"""
3+
Minimal setup.py for dynamic configuration that pyproject.toml cannot handle.
4+
Most configuration is now in pyproject.toml.
5+
"""
206

217
import os
22-
from glob import glob
23-
from setuptools import setup, find_packages
8+
from setuptools import setup
249

25-
26-
data_files = [('/usr/lib/systemd/system', glob('systemd/*.service')),
27-
('/etc/initial-setup/conf.d', glob('data/*.conf')),
28-
('/etc/pam.d', glob('pam/*')),
29-
('/usr/libexec/initial-setup/',
30-
["scripts/run-initial-setup", "scripts/firstboot-windowmanager",
31-
"scripts/initial-setup-text", "scripts/initial-setup-graphical",
32-
"scripts/run-gui-backend.guixorg", "scripts/run-gui-backend.guiweston",
33-
"scripts/run-gui-backend", # symlink to the default backend
34-
"scripts/reconfiguration-mode-enabled"]),
35-
('/usr/share/doc/initial-setup/', ["ChangeLog"])]
36-
37-
# add the firstboot start script for s390 architectures
10+
# Handle s390 architecture-specific files dynamically
11+
data_files = []
3812
if os.uname()[4].startswith('s390'):
39-
data_files.append(('/etc/profile.d', ['scripts/s390/initial-setup.sh']))
40-
data_files.append(('/etc/profile.d', ['scripts/s390/initial-setup.csh']))
41-
42-
with open("README.rst", "r") as f:
43-
long_description = f.read()
13+
data_files.extend([
14+
('etc/profile.d', ['scripts/s390/initial-setup.sh']),
15+
('etc/profile.d', ['scripts/s390/initial-setup.csh']),
16+
])
4417

45-
setup(name="initial-setup",
46-
version="0.3.101",
47-
author="Martin Kolman",
48-
author_email="mkolman@redhat.com",
49-
description='Post-installation configuration utility',
50-
long_description=long_description,
51-
long_description_content_type="text/x-rst",
52-
url='https://fedoraproject.org/wiki/InitialSetup',
53-
license="GPLv2+",
54-
keywords="firstboot initial setup",
55-
packages=find_packages(),
56-
package_data={
57-
"": ["*.glade"]
58-
},
59-
data_files=data_files,
60-
test_suite="initial_setup",
61-
classifiers=[
62-
"Development Status :: 3 - Alpha",
63-
"Environment :: X11 Applications :: GTK",
64-
"Environment :: Console",
65-
"Intended Audience :: System Administrators",
66-
"Topic :: System :: Systems Administration",
67-
"License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)",
68-
"Programming Language :: Python :: 3",
69-
],
18+
# Call setup with only the dynamic parts
19+
setup(
20+
data_files=data_files,
7021
)

0 commit comments

Comments
 (0)