GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: Transferable by rhoban13 · Pull Request #852 · testcontainers/testcontainers-python

Conversation

@rhoban13

@rhoban13 rhoban13 commented Jul 28, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

In #676 for copying to/from DockerContainer, it was suggested that we should clarify the interface & usage a bit before proceeding. This PR aims to push that conversation forward with some test cases illustrating proposed usages. Although here I created a Transferable object, in most cases there's no need for the caller to explicitly construct a Transferable, just pass the bytes | Path

Proposed use cases:

  1. Copy into a container by passing a TransferSpec into the initializer:
DockerContainer(... transferrables=[TransferSpec(source, destination_in_container), ...)
  1. Copy into the container via the builder pattern, prior to starting the container:
DockerContainer(...)
     .with_copy_into_container(b"some_bytes", destination_in_container)
     .with_copy_into_container(some_path, destination_in_container)
  1. Copy into the container at runtime:
with DockerContainer(...) as container:
    container.copy_into_container(b"some_bytes", destination_in_container)
    container.copy_into_container(some_path, destination_in_container)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Tranquility2 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
rhoban13 added 2 commits July 28, 2025 20:37
@rhoban13
Tests demonstrating copy file interfaces
c2cda80
@rhoban13
spelling and split out dataclass
631740e
@rhoban13 rhoban13 changed the title Tests demonstrating copy file interfaces feat: tests demonstrating copy file interfaces Jul 28, 2025
@codecov

codecov Bot commented Jul 28, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.33333% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.54%. Comparing base (2ca2321) to head (d032a55).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
core/testcontainers/core/container.py 92.85% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #852      +/-   ##
==========================================
+ Coverage   78.86%   79.54%   +0.67%     
==========================================
  Files          14       15       +1     
  Lines        1221     1281      +60     
  Branches      142      151       +9     
==========================================
+ Hits          963     1019      +56     
- Misses        216      218       +2     
- Partials       42       44       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rhoban13
fixes
8c29c86
@rhoban13
rhoban13 force-pushed the copy_file_tests branch from 8ddf5c6 to 8c29c86 Compare July 28, 2025 22:13
rhoban13 and others added 2 commits August 13, 2025 22:16
@rhoban13
Merge branch 'main' into copy_file_tests
a78ce9f
@Tranquility2
Merge branch 'main' into copy_file_tests
e989f8c
@wtf-is-flying

wtf-is-flying commented Sep 9, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Hi @rhoban13, what is the current status of this feature? What could I do to help?

For what it's worth, I think the suggested interface is clear. I haven't tested it with my use cases yet though.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rhoban13

rhoban13 commented Sep 10, 2025

Copy link
Copy Markdown
Contributor Author

Tagging a few maintainers seeking feedback @terry-docker @alexanderankin @Tranquility2

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@alexanderankin

alexanderankin commented Sep 10, 2025

Copy link
Copy Markdown
Member

i think my current priorities are docs, anything that makes this library behave like the others (this PR is illustrating current state not improving it), so far the only new issue from the new release is someone complaining about warning logs - so i think that means that the new release was successful (either that or there are no more users of this library). anecdotally someone reached out on slack asking for a new release but they are only allowed to use it at work a week after it has been released. so there may be new issues in some time.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@alexanderankin alexanderankin changed the title feat: tests demonstrating copy file interfaces feat: Transferable Sep 10, 2025
@alexanderankin

alexanderankin commented Sep 10, 2025

Copy link
Copy Markdown
Member

wait, this adds Transferable - this is great - if we can also fix the immediate starting of the container this almost entirely fixes copying. just have to maybe see about creating folders automatically and i think we may have parity on copying files with the other impls

Josephrp reacted with laugh emoji wtf-is-flying reacted with hooray emoji
All reactions
  • 😄 1 reaction
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rhoban13

rhoban13 commented Sep 10, 2025

Copy link
Copy Markdown
Contributor Author

Yes I was just about to update the PR title - my original intent was just some tests, but I found it easier to write those tests using TDD & just implement it at the same time. I think this brings the library a bit closer to feature parity with some others.

I'll take a look at adding some tests around folders if it sounds like you're in agreement with the interface at a high level.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@wtf-is-flying

wtf-is-flying commented Sep 10, 2025

Copy link
Copy Markdown

Thanks! I'll try to run some tests then and will let you know how they went.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rhoban13

rhoban13 commented Sep 10, 2025

Copy link
Copy Markdown
Contributor Author

if we can also fix the immediate starting of the container

This is independent of this PR, right? I presume you're referring to the fact that we're calling docker run instead of create+start?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@alexanderankin

alexanderankin commented Sep 10, 2025

Copy link
Copy Markdown
Member

yeah this whole API is not going to behave as intended until we start doing create then start

rhoban13 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

rhoban13
rhoban13 commented Sep 11, 2025
View reviewed changes
Comment thread core/testcontainers/core/container.py Outdated
pass

def with_copy_into_container(
self, file_content: Union[bytes, pathlib.Path], destination_in_container: str, mode: int = 0o644

@rhoban13 rhoban13 Sep 11, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Maybe the name file_content here isn't great? Maybe source or copy_source?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@alexanderankin alexanderankin Sep 11, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

In java they all just take transferable and destination I think

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@rhoban13 rhoban13 Sep 11, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I refined the initial definition of Transferable to now simply the be the union of those types. I kinda like that the signatures all just contain transferable: Transferable. It was an easy update except for the case of passing args to the initializer, which I changed to more closely mirror the type passed to volumes.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
rhoban13 added 2 commits September 11, 2025 02:09
@rhoban13
parametrize tests to simplify a little
612e30f
@rhoban13
Make Transferable simply a Union
3d5e078
@wtf-is-flying

wtf-is-flying commented Sep 11, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

I ran some tests with this PR, it went well 🙂.

I used this function to transfer directories:

def transferables_from_directory(
    source_dir: Path, dest_dir: Path, mode: int
) -> list[TransferSpec]:
    transferables: list[TransferSpec] = []
    for dirpath, _, filenames in source_dir.walk():
        for name in filenames:
            origin = dirpath / name
            destination = dest_dir / dirpath.relative_to(source_dir) / name
            transferables.append((origin, str(destination), mode))

    return transferables
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rhoban13
Implement & test copying a directory
1fd9831
@rhoban13

rhoban13 commented Sep 12, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

I updated the implementation so all these methods should work if the transferable Path is a directory as well.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@alexanderankin

alexanderankin commented Oct 7, 2025

Copy link
Copy Markdown
Member

going to ping @Tranquility2 in an attempt to make sure this PR doesnt get forgotten - I want either this or the DB stuff to be the next release (sometime in the next couple weeks)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Tranquility2

Tranquility2 commented Oct 8, 2025

Copy link
Copy Markdown
Contributor

going to ping @Tranquility2 in an attempt to make sure this PR doesnt get forgotten - I want either this or the DB stuff to be the next release (sometime in the next couple weeks)

How can I assist?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

rhoban13 added 2 commits October 30, 2025 15:34
@rhoban13
Merge branch 'main' into copy_file_tests
847c42e
@rhoban13
Merge branch 'main' into copy_file_tests
f4b9dca
@rhoban13 rhoban13 mentioned this pull request Mar 11, 2026
feat: support with_copy_to #976
Merged
@Tranquility2
Merge branch 'main' into copy_file_tests
d032a55
alexanderankin
alexanderankin approved these changes Apr 1, 2026
View reviewed changes
@alexanderankin
alexanderankin merged commit 6301a0c into testcontainers:main Apr 1, 2026
8 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@Tranquility2 Tranquility2 mentioned this pull request Apr 1, 2026
fix(core): Refactor copy file #996
Merged
Tranquility2 added a commit that referenced this pull request Apr 1, 2026
@Tranquility2
fix(core): Refactor copy file (#996)
0e0bb24
Follow-up to #852, cleaning up the copy file feature after it landed.
(Related to #676)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@alexanderankin alexanderankin alexanderankin approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@rhoban13 @wtf-is-flying @alexanderankin @Tranquility2
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.