Skip to content

fix: disable execute after print compilation#3041

Merged
johanneskoester merged 7 commits intosnakemake:mainfrom
Hocnonsense:main
Aug 29, 2024
Merged

fix: disable execute after print compilation#3041
johanneskoester merged 7 commits intosnakemake:mainfrom
Hocnonsense:main

Conversation

@Hocnonsense
Copy link
Copy Markdown
Contributor

@Hocnonsense Hocnonsense commented Aug 23, 2024

with flag print-compilation, it is not intend to execute the code, which can be incomplete, and running it will waste time and print errors to the screen.

Also, I add some asserts to some properties as they are typing as Optional.

QC

  • The PR contains a test case for the changes or the changes are already covered by an existing test case.
  • The documentation (docs/) is updated to reflect the changes or this is not necessary (e.g. if the change does neither modify the language nor the behavior or functionalities of Snakemake).

Summary by CodeRabbit

  • New Features

    • Introduced a reusable decorator that standardizes resource settings in the Workflow API.
  • Enhancements

    • Improved type annotations for better clarity and type safety across multiple classes.
    • Added assertions in critical methods to ensure necessary settings are initialized before use.
  • Refactor

    • Streamlined several function signatures and internal logic for enhanced readability and maintainability.

with flag `print-compilation`, it is not intend to execute the code,
which can be incomplete, and running it will waste time and
print errors to the screen.

Also, I add some asserts to some properties as they are typing as
Optional.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Aug 23, 2024

Walkthrough

The changes involve multiple modifications across several files in the Snakemake codebase. A new decorator function _no_dag is introduced to standardize resource settings in the WorkflowApi class. Type annotations are enhanced in the snakemake/parser.py, snakemake/persistence.py, and snakemake/workflow.py files for improved clarity and type safety. Various assertions are added throughout the Workflow class to check critical settings, increasing the robustness of the code.

Changes

File Change Summary
snakemake/api.py Introduced _no_dag decorator to set cores to 1 for specific methods; decorated lint method with _no_dag.
snakemake/parser.py Updated lineno function with type annotation; reformatted parse function signature and added type hints; refactored linemap updates.
snakemake/persistence.py Changed path parameter annotation from Path = None to `Path
snakemake/workflow.py Enhanced type annotations for properties and method signatures; added assertions to validate critical settings before access.
snakemake/common/__init__.py Changed environ parameter annotation in set_env function to use Dict[str, unicode].
snakemake/io.py Updated type annotations from dict to Dict for various parameters and attributes to improve type clarity.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9a60046 and fad0939.

Files selected for processing (4)
  • snakemake/api.py (2 hunks)
  • snakemake/parser.py (2 hunks)
  • snakemake/persistence.py (1 hunks)
  • snakemake/workflow.py (33 hunks)
Additional context used
Path-based instructions (4)
snakemake/persistence.py (1)

Pattern **/*.py: Do not try to improve formatting.
Do not suggest type annotations for functions that are defined inside of functions or methods.
Do not suggest type annotation of the self argument of methods.
Do not suggest type annotation of the cls argument of classmethods.
Do not suggest return type annotation if a function or method does not contain a return statement.

snakemake/api.py (1)

Pattern **/*.py: Do not try to improve formatting.
Do not suggest type annotations for functions that are defined inside of functions or methods.
Do not suggest type annotation of the self argument of methods.
Do not suggest type annotation of the cls argument of classmethods.
Do not suggest return type annotation if a function or method does not contain a return statement.

snakemake/parser.py (1)

Pattern **/*.py: Do not try to improve formatting.
Do not suggest type annotations for functions that are defined inside of functions or methods.
Do not suggest type annotation of the self argument of methods.
Do not suggest type annotation of the cls argument of classmethods.
Do not suggest return type annotation if a function or method does not contain a return statement.

snakemake/workflow.py (1)

Pattern **/*.py: Do not try to improve formatting.
Do not suggest type annotations for functions that are defined inside of functions or methods.
Do not suggest type annotation of the self argument of methods.
Do not suggest type annotation of the cls argument of classmethods.
Do not suggest return type annotation if a function or method does not contain a return statement.

Ruff
snakemake/parser.py

1311-1311: Ambiguous variable name: l

(E741)

snakemake/workflow.py

20-20: typing.Dict imported but unused

Remove unused import: typing.Dict

(F401)

Additional comments not posted (38)
snakemake/persistence.py (1)

44-44: Type annotation update is appropriate.

The change from Path = None to Path | None = None enhances type clarity and aligns with modern Python type hinting practices.

snakemake/api.py (2)

290-295: Introduction of _no_dag decorator is well-structured.

The _no_dag decorator is defined outside of the dag function, enhancing code organization and reusability. It sets cores to 1, aligning with the PR objective.


297-297: Application of _no_dag decorator to lint method is appropriate.

The lint method now inherits the behavior of setting cores to 1, which is consistent with the intended functionality.

snakemake/parser.py (2)

73-74: Type annotation added for lineno function.

The addition of type annotation for the token parameter enhances clarity and type safety.


1299-1305: Type annotations and reformatting added to parse function.

The type annotations for workflow and linemap enhance clarity and type safety. The reformatting improves readability.

snakemake/workflow.py (33)

151-151: LGTM!

The change from Mapping[str, str] to dict[str, str] is appropriate for specifying the type more precisely.


152-152: LGTM!

The change to allow overwrite_workdir to be of type str or Path enhances flexibility in handling file paths.


253-253: LGTM!

The assertion ensures that storage_settings is not None, which helps prevent potential runtime errors.


274-274: LGTM!

The assertion ensures that storage_settings is not None, which helps prevent potential runtime errors.


386-389: LGTM!

The condition ensures that execution_settings is not None before accessing use_threads, which is a good practice.


473-473: LGTM!

The assertion ensures that dag_settings is not None, which helps prevent potential runtime errors.


478-478: LGTM!

The assertion ensures that deployment_settings is not None, which helps prevent potential runtime errors.


666-669: LGTM!

The condition ensures that storage_settings and default_storage_provider are not None before proceeding, which is a good practice.


679-680: LGTM!

The change to allow shadow_prefix to be of type str, Path, or None enhances flexibility.


698-698: LGTM!

The assertion ensures that dag_settings is not None, which helps prevent potential runtime errors.


799-799: LGTM!

The assertion ensures that deployment_settings is not None, which helps prevent potential runtime errors.


818-818: LGTM!

The assertion ensures that dag_settings is not None, which helps prevent potential runtime errors.


837-837: LGTM!

The assertion ensures that dag_settings is not None, which helps prevent potential runtime errors.


857-857: LGTM!

The assertion ensures that dag_settings is not None, which helps prevent potential runtime errors.


912-912: LGTM!

The assertion ensures that dag_settings is not None, which helps prevent potential runtime errors.


928-928: LGTM!

The assertion ensures that dag_settings is not None, which helps prevent potential runtime errors.


938-938: LGTM!

The assertion ensures that dag_settings is not None, which helps prevent potential runtime errors.


948-948: LGTM!

The assertion ensures that dag_settings is not None, which helps prevent potential runtime errors.


958-958: LGTM!

The assertion ensures that dag_settings is not None, which helps prevent potential runtime errors.


971-971: LGTM!

The assertion ensures that dag_settings is not None, which helps prevent potential runtime errors.


987-987: LGTM!

The assertion ensures that dag_settings is not None, which helps prevent potential runtime errors.


1006-1006: LGTM!

The assertion ensures that dag_settings is not None, which helps prevent potential runtime errors.


1017-1017: LGTM!

The assertion ensures that dag_settings is not None, which helps prevent potential runtime errors.


1040-1040: LGTM!

The assertion ensures that dag_settings is not None, which helps prevent potential runtime errors.


1048-1048: LGTM!

The assertion ensures that deployment_settings is not None, which helps prevent potential runtime errors.


1054-1054: LGTM!

The assertion ensures that dag_settings is not None, which helps prevent potential runtime errors.


1064-1064: LGTM!

The assertion ensures that dag_settings is not None, which helps prevent potential runtime errors.


1086-1091: LGTM!

The assertions ensure that critical settings are not None, which helps prevent potential runtime errors.


1360-1361: LGTM!

The assertion ensures that the frame is not None, which helps prevent potential runtime errors.


1388-1389: LGTM!

The assertion ensures that the frame is not None, which helps prevent potential runtime errors.


1435-1435: LGTM!

Adding a type hint for linemap improves code clarity and type safety.


1447-1447: LGTM!

The return statement aligns with the PR objective to disable execution after print compilation.


1969-1969: LGTM!

The assertion ensures that deployment_settings is not None, which helps prevent potential runtime errors.

johanneskoester and others added 3 commits August 27, 2024 16:04
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@johanneskoester johanneskoester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much! I have just a few questions about the changes.

deploy.append("conda")
if DeploymentMethod.APPTAINER in self.deployment_settings.deployment_method:
deploy.append("singularity")
if self.deployment_settings is not None:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why would this be none here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These following checks of None are added as these params are setted as None when it was created. mypy warned me that. Probably an assert is proper here, or I will ignore these type of warnings? Thanks for your advice!

assert self.dag_settings is not None
self._prepare_dag(
forceall=self.dag_settings.forceall,
forceall=self.dag_settings.forceall, # True?
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, why not?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the trailing comment added here, I've deleted it

path = str(path)
if self.storage_settings.default_storage_provider is not None:
if (
self.storage_settings is not None
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would this be None here?

return (
self.execution_settings.use_threads
(
self.execution_settings is not None
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would this be None here?

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between fad0939 and 6069ad6.

Files selected for processing (2)
  • snakemake/parser.py (2 hunks)
  • snakemake/workflow.py (33 hunks)
Files skipped from review as they are similar to previous changes (2)
  • snakemake/parser.py
  • snakemake/workflow.py

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6069ad6 and f894795.

Files selected for processing (1)
  • snakemake/workflow.py (36 hunks)
Files skipped from review as they are similar to previous changes (1)
  • snakemake/workflow.py

def parse(
path,
workflow: "workflow.Workflow",
linemap: dict[int, int],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
linemap: dict[int, int],
linemap: Dict[int, int],

I rather used typing.Dict so far for backwards compatibility. Can you change the rest?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah wait, I will do that quickly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for my miss, and I'm grateful for your help!

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f894795 and 4b4051d.

Files selected for processing (4)
  • snakemake/common/init.py (1 hunks)
  • snakemake/io.py (2 hunks)
  • snakemake/parser.py (2 hunks)
  • snakemake/workflow.py (36 hunks)
Files skipped from review due to trivial changes (2)
  • snakemake/common/init.py
  • snakemake/io.py
Files skipped from review as they are similar to previous changes (2)
  • snakemake/parser.py
  • snakemake/workflow.py

@johanneskoester johanneskoester merged commit 86ed3cd into snakemake:main Aug 29, 2024
johanneskoester pushed a commit that referenced this pull request Aug 29, 2024
🤖 I have created a release *beep* *boop*
---


##
[8.19.0](v8.18.2...v8.19.0)
(2024-08-29)


### Features

* check consistency of output file mtimes (must be newer than input
files) ([#3050](#3050))
([666cf62](666cf62))
* print host name when executing workflow
([#3048](#3048))
([b0ff787](b0ff787))


### Bug Fixes

* `mem` and `disk` inference fixes
([#3040](#3040))
([7530794](7530794))
* avoid error accessing superclass in ioutils
([#3056](#3056))
([a66a5f5](a66a5f5))
* disable execute after print compilation
([#3041](#3041))
([86ed3cd](86ed3cd))
* download report assets upon package build such that reports become
possible offline (cont. of
[#2904](#2904))
([#3026](#3026))
([e8dad4b](e8dad4b))


### Documentation

* Add 'Editor integrations' section to Installation page
([#3045](#3045))
([9a4006d](9a4006d))
* Fix typo (seesee to see)
([#3037](#3037))
([de201fb](de201fb))
* various documentation fixes
([#3052](#3052))
([b11460c](b11460c))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
vandalt pushed a commit to vandalt/snakemake that referenced this pull request Aug 29, 2024
with flag `print-compilation`, it is not intend to execute the code,
which can be incomplete, and running it will waste time and print errors
to the screen.

Also, I add some asserts to some properties as they are typing as
Optional.

<!--Add a description of your PR here-->

### QC
<!-- Make sure that you can tick the boxes below. -->

* [ ] The PR contains a test case for the changes or the changes are
already covered by an existing test case.
* [ ] The documentation (`docs/`) is updated to reflect the changes or
this is not necessary (e.g. if the change does neither modify the
language nor the behavior or functionalities of Snakemake).


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Introduced a reusable decorator that standardizes resource settings in
the Workflow API.

- **Enhancements**
- Improved type annotations for better clarity and type safety across
multiple classes.
- Added assertions in critical methods to ensure necessary settings are
initialized before use.

- **Refactor**
- Streamlined several function signatures and internal logic for
enhanced readability and maintainability.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Johannes Köster <johannes.koester@uni-due.de>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
vandalt pushed a commit to vandalt/snakemake that referenced this pull request Aug 29, 2024
🤖 I have created a release *beep* *boop*
---


##
[8.19.0](snakemake/snakemake@v8.18.2...v8.19.0)
(2024-08-29)


### Features

* check consistency of output file mtimes (must be newer than input
files) ([snakemake#3050](snakemake#3050))
([666cf62](snakemake@666cf62))
* print host name when executing workflow
([snakemake#3048](snakemake#3048))
([b0ff787](snakemake@b0ff787))


### Bug Fixes

* `mem` and `disk` inference fixes
([snakemake#3040](snakemake#3040))
([7530794](snakemake@7530794))
* avoid error accessing superclass in ioutils
([snakemake#3056](snakemake#3056))
([a66a5f5](snakemake@a66a5f5))
* disable execute after print compilation
([snakemake#3041](snakemake#3041))
([86ed3cd](snakemake@86ed3cd))
* download report assets upon package build such that reports become
possible offline (cont. of
[snakemake#2904](snakemake#2904))
([snakemake#3026](snakemake#3026))
([e8dad4b](snakemake@e8dad4b))


### Documentation

* Add 'Editor integrations' section to Installation page
([snakemake#3045](snakemake#3045))
([9a4006d](snakemake@9a4006d))
* Fix typo (seesee to see)
([snakemake#3037](snakemake#3037))
([de201fb](snakemake@de201fb))
* various documentation fixes
([snakemake#3052](snakemake#3052))
([b11460c](snakemake@b11460c))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@coderabbitai coderabbitai bot mentioned this pull request Jul 24, 2025
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants