Skip to content

Commit

Permalink
Use create_artifacts.py to remove a Requires line
Browse files Browse the repository at this point in the history
For code reuse. It is better to use this library to do the removing than
to have a sed command being run in two separate places, both of which
have to be kept up-to-date as necessary.

Signed-off-by: mulhern <[email protected]>
  • Loading branch information
mulkieran committed Nov 3, 2023
1 parent 6cb230a commit 7b3c1ca
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
3 changes: 0 additions & 3 deletions mockbuild_test/generate_sourcerpms.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ cd stratis-cli
../../../release_management/create_artifacts.py ../../SOURCES/ --pre-release --specfile-path=../../SPECS/stratis-cli.spec stratis-cli
cd ../..

# Remove the "Requires: stratisd" line in stratis-cli.spec.
sed -i "/Requires.*stratisd/d" SPECS/stratis-cli.spec

mock --buildsrpm -r $MOCKCONFIG --spec SPECS/stratisd.spec --sources SOURCES/ --resultdir=SRPMS/stratisd/
mock --buildsrpm -r $MOCKCONFIG --spec SPECS/stratis-cli.spec --sources SOURCES/ --resultdir=SRPMS/stratis-cli/

Expand Down
6 changes: 5 additions & 1 deletion release_management/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,16 @@ def calc_pre_release_suffix():
return f"{datetime.today():%Y%m%d%H%M}git{commit_hash}"


def edit_specfile(specfile_path, *, release_version=None, sources=None):
def edit_specfile(specfile_path, *, release_version=None, sources=None, arbitrary=None):
"""
Edit the specfile in place
:param specfile_path: abspath of specfile
:type specfile_path: str or NoneType
:param ReleaseVersion release_version: release version to set in spec file
:param sources: local source files
:type sources: list of str or NoneType
:param arbitrary: a function that takes the spec and does some action
:type arbitrary: Specfile -> NoneType
"""
if specfile_path is not None:
with specfile.Specfile(specfile_path) as spec:
Expand All @@ -92,6 +94,8 @@ def edit_specfile(specfile_path, *, release_version=None, sources=None):
with spec.sources() as entries: # pylint: disable=not-context-manager
for index, value in enumerate(sources):
entries[index].location = value
if arbitrary is not None:
arbitrary(spec)


def get_python_package_info(name):
Expand Down
18 changes: 18 additions & 0 deletions release_management/create_artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,28 @@ def _stratis_cli_artifacts(namespace):
output_path,
)

def remove_stratisd_requires(spec):
"""
Remove stratisd-related Requires line, if present.
"""
with spec.tags() as tags:
index = next(
(
index
for index, tag in enumerate(tags)
if tag.name == "Requires" and "stratisd" in tag.value
),
None,
)

if index is not None:
del tags[index]

edit_specfile(
specfile_path,
release_version=release_version,
sources=[os.path.basename(source_tarfile)],
arbitrary=remove_stratisd_requires,
)

print(os.path.relpath(source_tarfile))
Expand Down

0 comments on commit 7b3c1ca

Please sign in to comment.