diff --git a/pyproject.toml b/pyproject.toml index 8ea8668..c41b330 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -74,4 +74,4 @@ python-build = ">=1.2.2,<2" build = { cmd = "python -m build", description = "Build the package into the dist/ directory" } check-build = { cmd = "python -m twine check dist/*", depends-on = [ "build", -], description = "Check that the package can be uploaded" } \ No newline at end of file +], description = "Check that the package can be uploaded" } diff --git a/snakedeploy/snakemake_wrappers.py b/snakedeploy/snakemake_wrappers.py index 90677e3..36a1559 100644 --- a/snakedeploy/snakemake_wrappers.py +++ b/snakedeploy/snakemake_wrappers.py @@ -107,37 +107,28 @@ def update_snakemake_wrappers( repo = None pr = None + has_updates = False if create_prs: repo = get_repo() if pr_add_label and not entity_regex: raise UserError("Cannot add label to PR without --entity-regex specified.") - if create_prs and not per_snakefile_prs: - if pr_add_label: - raise UserError( - "Cannot add label to PR when updating all snakefiles at once." + if not per_snakefile_prs: + if pr_add_label: + raise UserError( + "Cannot add label to PR when updating all snakefiles at once." + ) + pr = PR( + "perf: autobump wrappers", + f"Automatic bump of wrappers in {', '.join(snakefiles)}.", + "autobump/wrappers", + repo, ) - pr = PR( - "perf: autobump wrappers", - f"Automatic bump of wrappers in {', '.join(snakefiles)}.", - "autobump/wrappers", - repo, - ) with WrapperRepo() as wrapper_repo: for snakefile in snakefiles: - if create_prs and per_snakefile_prs: - pr = PR( - f"perf: autobump wrappers in {snakefile}", - f"Automatic bump of wrappers in {snakefile}.", - f"autobump/wrappers/{snakefile.replace('/', '-')}", - repo, - entity=snakefile, - label_entity_regex=entity_regex if pr_add_label else None, - ) - with open(snakefile, "r") as infile: - snakefile_content = infile.read() + ori_snakefile_content = infile.read() def update_spec(matchobj): spec = matchobj.group("spec") @@ -182,22 +173,39 @@ def update_spec(matchobj): snakefile_content = re.sub( "(?P(meta_)?wrapper:\\n?\\s*)(?P['\"])(?P.+)(?P=quote)", update_spec, - snakefile_content, + ori_snakefile_content, ) - with open(snakefile, "w") as outfile: - outfile.write(snakefile_content) - - if create_prs: - assert pr is not None - pr.add_file( - snakefile, - snakefile_content, - is_updated=True, - msg=f"perf: update {snakefile}.", - ) - pr.create() + if snakefile_content != ori_snakefile_content: + with open(snakefile, "w") as outfile: + outfile.write(snakefile_content) + + if create_prs: + if per_snakefile_prs: + pr = PR( + f"perf: autobump wrappers in {snakefile}", + f"Automatic bump of wrappers in {snakefile}.", + f"autobump/wrappers/{snakefile.replace('/', '-')}", + repo, + entity=snakefile, + label_entity_regex=( + entity_regex if pr_add_label else None + ), + ) + assert pr is not None + pr.add_file( + snakefile, + snakefile_content, + is_updated=True, + msg=f"perf: update {snakefile}.", + ) + has_updates = True + + if per_snakefile_prs: + pr.create() + else: + logger.info(f"No wrapper updates in {snakefile}.") - if create_prs and not per_snakefile_prs: + if has_updates and create_prs and not per_snakefile_prs: assert pr is not None pr.create()