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

Return destination values in some shutil functions #58977

Closed
briancurtin opened this issue May 10, 2012 · 12 comments
Closed

Return destination values in some shutil functions #58977

briancurtin opened this issue May 10, 2012 · 12 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@briancurtin
Copy link
Member

BPO 14772
Nosy @merwok, @briancurtin, @hynek
Files
  • shutil_return_values.diff
  • issue14772.diff
  • issue14772_v2.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/briancurtin'
    closed_at = <Date 2012-06-18.23:45:27.088>
    created_at = <Date 2012-05-10.19:26:27.133>
    labels = ['type-feature', 'library']
    title = 'Return destination values in some shutil functions'
    updated_at = <Date 2012-06-24.06:28:19.477>
    user = 'https://github.com/briancurtin'

    bugs.python.org fields:

    activity = <Date 2012-06-24.06:28:19.477>
    actor = 'eric.araujo'
    assignee = 'brian.curtin'
    closed = True
    closed_date = <Date 2012-06-18.23:45:27.088>
    closer = 'brian.curtin'
    components = ['Library (Lib)']
    creation = <Date 2012-05-10.19:26:27.133>
    creator = 'brian.curtin'
    dependencies = []
    files = ['25522', '25526', '25527']
    hgrepos = []
    issue_num = 14772
    keywords = ['patch', 'needs review']
    message_count = 12.0
    messages = ['160363', '160370', '160371', '160372', '160386', '160387', '160390', '160408', '160853', '163129', '163176', '163725']
    nosy_count = 4.0
    nosy_names = ['eric.araujo', 'brian.curtin', 'python-dev', 'hynek']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue14772'
    versions = ['Python 3.3']

    @briancurtin
    Copy link
    Member Author

    Attached is a patch to return the final destination of files or directories sent through shutil's copy, copy2, and move functions. This removes the need to construct the destination path on your own.

    This is especially useful for copy/copy2 where you copy a file into a directory and need to know that resulting path. Rather than calling os.path.join(dest, os.path.basename(source)) you could get that path from copy/copy2 (which does that join internally).

    Patch has docs and tests.

    @briancurtin briancurtin self-assigned this May 10, 2012
    @briancurtin briancurtin added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels May 10, 2012
    @briancurtin
    Copy link
    Member Author

    Here's a patch that fixes the trailing whitespace Hynek noticed as well as adds an additional test case for copy/copy2.

    @briancurtin
    Copy link
    Member Author

    Added another test using move as renaming the destination file.

    @hynek
    Copy link
    Member

    hynek commented May 10, 2012

    Code LGTM, a deeper discussion happened on IRC. :)

    I'd still suggest for the sake of consistency to return the destination from copytree() too, but that can be done separately.

    @merwok
    Copy link
    Member

    merwok commented May 10, 2012

    packaging/distutils2 definitely needs that; the similar functions in distutils.file_util used to return the file paths, this was lost in the conversion to shutil, and there is at least one open bug that needs it back.

    @briancurtin
    Copy link
    Member Author

    When you say "needs that", do you mean the patch as-is, or Hynek's suggestion to return consistently?

    @merwok
    Copy link
    Member

    merwok commented May 10, 2012

    I meant that packaging needs some shutil functions to return the destination, but haven’t checked to see if that includes copytree.

    @merwok
    Copy link
    Member

    merwok commented May 11, 2012

    In distutils, both copy_file and copy_tree return the destination path(s), which is needed by many commands. In packaging there is code to compute and return those paths, as shutil functions return None; I’d love to remove that code.

    The bug I was thinking about is actually about copy(_)file parameters, not return value: bpo-13336.

    @hynek
    Copy link
    Member

    hynek commented May 16, 2012

    Brian, are you going to update that patch so we can close this? :)

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jun 18, 2012

    New changeset 8281233ec648 by Brian Curtin in branch 'default':
    Fix bpo-14772: Return the destination from some shutil functions.
    http://hg.python.org/cpython/rev/8281233ec648

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jun 19, 2012

    New changeset e8ea27ab9fa6 by Brian Curtin in branch 'default':
    Add versionchanged tags for bpo-14772 changes
    http://hg.python.org/cpython/rev/e8ea27ab9fa6

    @merwok
    Copy link
    Member

    merwok commented Jun 24, 2012

    Thanks!

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants