Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: success check does not consider pkg_dir #836 #838

Merged
merged 17 commits into from
Nov 19, 2024

Conversation

jpfeuffer
Copy link
Contributor

completely untested but it is an obvious bug.
If you want to change the package dirs earlier in the code somewhere, please suggest changes

@jpfeuffer jpfeuffer changed the title fix #836 fix: success check does not consider pkg_dir #836 Feb 24, 2023
@jpfeuffer
Copy link
Contributor Author

@bgruening @daler Ready to review. Somehow I cannot request it from the normal UI.

@daler
Copy link
Member

daler commented Feb 27, 2023

@jpfeuffer just to clarify, is OpenMS is using bioconda-utils for internal builds?

@jpfeuffer
Copy link
Contributor Author

Hey @daler
yes, correct. We want to ensure the package builds on bioconda in the moment we trigger a release. And that nightly builds in-between are compatible with the rest of bioconda. If that is possible with pure conda build without too much hassle we can also use that.

@daler
Copy link
Member

daler commented Feb 27, 2023

Ah, ok. Can you point to where (and how) you are calling it then? I bet if it's not exactly how we call it in bioconda-recipes then that might introduce behavior that we don't otherwise test for.

@jpfeuffer
Copy link
Contributor Author

jpfeuffer commented Feb 27, 2023

Sure! Yes, you might not be using the --docker-specific --pkg_dir option to specify a directory to be mounted into the docker container. We use it, so we can reuse already-built packages for the next run and generally have access to the finished packages after the build. I did not check if we can change the upload behavior otherwise that would have been an alternative.

# output must be a valid conda "channel" (otherwise I think I encountered problems)
mkdir -p output/noarch
touch output/noarch/repodata.json
conda activate bioconda
mamba update -y bioconda-utils
conda index output

git clone https://github.com/bioconda/bioconda-recipes && cd bioconda-recipes # we usually use our own fork with ntly changes
bioconda-utils build --docker --pkg_dir $WORKSPACE/output --packages openms-meta # feel free to choose any pkg
bioconda-utils build --docker --pkg_dir $WORKSPACE/output --packages pyopenms

Note: you cannot run them together because of #751
I think it also needed to be an absolute path (therefore $WORKSPACE)

@daler
Copy link
Member

daler commented Feb 27, 2023

So the default behavior is for --pkg_dir to not be set, which in turn defaults to the identified conda-build directory on the host, which is where the built recipes will be copied to and mounted read-only into the container. So the default behavior does, I think, what you are aiming to do.

Does it work if you remove the --pkg_dir arg?

@jpfeuffer
Copy link
Contributor Author

Yes, I think it works without --pkg_dir but somehow we ended up using a subfolder in the workspace (persistency, permission reasons I guess). We might be able to reevaluate the thing but I think it would be great if the build also works with --pkg_dir.

@daler
Copy link
Member

daler commented Feb 27, 2023

I think it would be ok to merge as-is since we don't use --pkg_dir anywhere in production, but merging without tests always makes me nervous. And there are currently bigger issues to resolve that affect the entire channel (and very limited time to do so).

Can you write a test for this in the test dir, that fails in master branch but passes with your addition?

test/test_utils.py Outdated Show resolved Hide resolved
test/test_utils.py Outdated Show resolved Hide resolved
@jpfeuffer
Copy link
Contributor Author

@daler Ready. I am 90% sure it will fail on master.

@jpfeuffer
Copy link
Contributor Author

@daler Do you need anything else?

@timosachsenberg
Copy link

Hi, has there been any progress with this PR?

Comment on lines 121 to 125
platform = os.environ.get('OSTYPE', sys.platform)
if platform.startswith("darwin"):
platform = 'osx'
elif platform == "linux-gnu":
platform = "linux"
Copy link
Contributor

Choose a reason for hiding this comment

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

The platform can be inferred from RepoData().native_platform().

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, make sure that you indent only with 4 spaces.

@poshul
Copy link

poshul commented Apr 1, 2023

FAILED test/test_utils.py::test_single_build_pkg_dir - AssertionError: bug: ensure to load config before instantiating RepoData. ERROR test/test_utils.py::test_single_build_only[with docker] - AssertionError: bug: ensure to load config before instantiating RepoData.

@jpfeuffer
Copy link
Contributor Author

Sorry, I don't know what that means. I merely added the review suggestion. I guess this error is also why the suggested code was not used in the place where I copied it from 🤷.
I guess we have to wait for further suggestions..

@timosachsenberg
Copy link

any update here?

@poshul
Copy link

poshul commented May 15, 2023

@johanneskoester @daler any updates on this?

@johanneskoester johanneskoester self-assigned this Aug 9, 2023
@poshul
Copy link

poshul commented Oct 25, 2023

@johanneskoester @daler any updates?

@timosachsenberg
Copy link

any news?

bioconda_utils/build.py Outdated Show resolved Hide resolved
Copy link

coderabbitai bot commented Nov 19, 2024

Walkthrough

The changes introduced in the pull request primarily affect two files: bioconda_utils/build.py and test/test_utils.py. In bioconda_utils/build.py, modifications include the addition of import statements for sys and time, which are likely intended for enhanced functionality or logging purposes. The build function has been updated to improve the handling of package paths when using a Docker builder. Specifically, it now retrieves the native platform and adjusts the pkg_paths based on the Docker builder's package directory if docker_builder.pkg_dir is not None. This aims to ensure accurate resolution of package paths during the build process. Additionally, error handling has been refined to provide better logging for package path issues post-build, although the overall control flow remains unchanged.

In test/test_utils.py, a new test function, test_single_build_pkg_dir, has been added to evaluate the build process using a specified package directory within a Docker context. Existing Docker-related tests have been annotated to skip on macOS platforms. These changes enhance the test suite's coverage without altering the logic of existing tests.


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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

@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

🧹 Outside diff range and nitpick comments (5)
bioconda_utils/build.py (2)

8-11: Remove unused imports

The imports sys and time are not used in the code.

Apply this diff to remove the unused imports:

import logging
import os
-import sys
-import time
🧰 Tools
🪛 Ruff

10-10: sys imported but unused

Remove unused import: sys

(F401)


11-11: time imported but unused

Remove unused import: time

(F401)


145-150: LGTM! The fix correctly handles pkg_dir in Docker builds

The implementation properly adjusts package paths when using a Docker builder with a custom package directory, fixing the success check issue.

Consider these improvements:

  1. Add type hints for pkg_paths parameter
  2. Add error handling for platform conversion
-def build(recipe: str, pkg_paths: List[str] = None,
+def build(
+    recipe: str,
+    pkg_paths: Optional[List[str]] = None,
     ...
 ):
     ...
     if docker_builder.pkg_dir is not None:
         try:
             platform = utils.RepoData.native_platform()
             subfolder = utils.RepoData.platform2subdir(platform)
             conda_build_config = utils.load_conda_build_config(platform=subfolder)
             pkg_paths = [p.replace(conda_build_config.output_folder, docker_builder.pkg_dir) for p in pkg_paths]
+        except Exception as e:
+            logger.error("Failed to adjust package paths: %s", str(e))
+            return BuildResult(False, None)
test/test_utils.py (3)

255-277: LGTM! The test effectively validates pkg_dir handling.

The test is well-structured and directly addresses the PR objective of fixing pkg_dir handling in the build process. It properly sets up a docker builder with a specific pkg_dir and verifies the build result.

Consider adding cleanup of the output directory after the test:

 def test_single_build_pkg_dir(recipes_fixture):
     """
     Builds the "one" recipe with pkg_dir.
     """
+    output_dir = os.getcwd() + "/output"
     logger.error("Making recipe builder")
     docker_builder = docker_utils.RecipeBuilder(
         use_host_conda_bld=True,
-        pkg_dir=os.getcwd() + "/output",
+        pkg_dir=output_dir,
         docker_base_image=DOCKER_BASE_IMAGE)
     mulled_test = False
     logger.error("DONE")
     logger.error("Fixture: Building 'one' within docker with pkg_dir")
     res = build.build(
         recipe=recipes_fixture.recipe_dirs['one'],
         pkg_paths=recipes_fixture.pkgs['one'],
         docker_builder=docker_builder,
         mulled_test=mulled_test,
     )
     logger.error("Fixture: Building 'one' within docker and pkg_dir -- DONE")
     assert res.success
+    # Cleanup
+    if os.path.exists(output_dir):
+        shutil.rmtree(output_dir)

261-262: Improve error logging message.

The log message could be more descriptive about what's being created.

-    logger.error("Making recipe builder")
+    logger.error("Creating docker recipe builder with pkg_dir")

268-269: Enhance build logging message.

The log message could include the pkg_dir path for better debugging.

-    logger.error("Fixture: Building 'one' within docker with pkg_dir")
+    logger.error("Fixture: Building 'one' within docker with pkg_dir: %s", docker_builder.pkg_dir)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ce37553 and 386b376.

📒 Files selected for processing (2)
  • bioconda_utils/build.py (2 hunks)
  • test/test_utils.py (1 hunks)
🧰 Additional context used
🪛 Ruff
bioconda_utils/build.py

10-10: sys imported but unused

Remove unused import: sys

(F401)


11-11: time imported but unused

Remove unused import: time

(F401)

Copy link
Member

@bgruening bgruening left a comment

Choose a reason for hiding this comment

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

Thanks everyone!

@bgruening bgruening merged commit 6240d31 into bioconda:master Nov 19, 2024
10 checks passed
bgruening pushed a commit that referenced this pull request Nov 30, 2024
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.

6 participants