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

Add Path.is_relative_to() #81870

Closed
pitrou opened this issue Jul 26, 2019 · 4 comments
Closed

Add Path.is_relative_to() #81870

pitrou opened this issue Jul 26, 2019 · 4 comments
Labels
3.9 only security fixes easy stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@pitrou
Copy link
Member

pitrou commented Jul 26, 2019

BPO 37689
Nosy @brettcannon, @pitrou, @shihai1991
PRs
  • bpo-37689: add Path.is_relative_to() method #14982
  • 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 = None
    closed_at = <Date 2019-08-13.19:54:35.857>
    created_at = <Date 2019-07-26.15:56:04.658>
    labels = ['easy', 'type-feature', 'library', '3.9']
    title = 'Add Path.is_relative_to()'
    updated_at = <Date 2019-08-13.19:54:35.857>
    user = 'https://github.com/pitrou'

    bugs.python.org fields:

    activity = <Date 2019-08-13.19:54:35.857>
    actor = 'pitrou'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-08-13.19:54:35.857>
    closer = 'pitrou'
    components = ['Library (Lib)']
    creation = <Date 2019-07-26.15:56:04.658>
    creator = 'pitrou'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 37689
    keywords = ['patch', 'easy']
    message_count = 4.0
    messages = ['348498', '348504', '348553', '349612']
    nosy_count = 3.0
    nosy_names = ['brett.cannon', 'pitrou', 'shihai1991']
    pr_nums = ['14982']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue37689'
    versions = ['Python 3.9']

    @pitrou
    Copy link
    Member Author

    pitrou commented Jul 26, 2019

    Right now, to know whether a Path is relative to another one, you have to call Path.relative_to(), catch ValueError, and act in consequence.

    It would be nice to have a Path.is_relative_to() that does the equivalent for you and returns True/False.

    This is probably a good easy issue for a beginner contributor.

    @pitrou pitrou added 3.9 only security fixes stdlib Python modules in the Lib dir easy type-feature A feature request or enhancement labels Jul 26, 2019
    @shihai1991
    Copy link
    Member

    antoine, let me try it;)

    @shihai1991
    Copy link
    Member

    Hi, Antoine, pls review this PR if you have free time.
    Looks is_relative_to only catch valueError is good enough.

    @pitrou
    Copy link
    Member Author

    pitrou commented Aug 13, 2019

    New changeset 82642a0 by Antoine Pitrou (Hai Shi) in branch 'master':
    bpo-37689: add Path.is_relative_to() method (GH-14982)
    82642a0

    @pitrou pitrou closed this as completed Aug 13, 2019
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    mika added a commit to sipwise/ngcpcfg that referenced this issue Apr 19, 2022
    Path.is_relative() (as used in t/fixtures/programs.py) is a new feature
    as of Python 3.9, see
    https://docs.python.org/3.9/whatsnew/changelog.html?highlight=is_relative_to
    and python/cpython#81870
    
    When running with an older python3 version, tests fail with:
    
    | env = {}
    |
    |     def prepare_conf(env={}):
    |         testenv = define_env(env)
    |         ngcpcfg_path = testenv["NGCPCFG"]
    | >       if not ngcpcfg_path.is_relative_to(CWD):
    | E       AttributeError: 'PosixPath' object has no attribute 'is_relative_to'
    
    While python3-pytest depends on python3:any, let's keep the build
    dependency slim, by build-depending on the python3-minimal package only.
    
    Problem spotted while trying to debug the git safe.directory issue
    in an outdated bullseye based container, providing python3 3.7.5-3.
    
    Change-Id: Ib620a796a780817a81a51d791a766c950b1a541c
    mika added a commit to sipwise/ngcpcfg that referenced this issue Apr 19, 2022
    Path.is_relative() (as used in t/fixtures/programs.py) is a new feature
    as of Python 3.9, see
    https://docs.python.org/3.9/whatsnew/changelog.html?highlight=is_relative_to
    and python/cpython#81870
    
    When running with an older python3 version, tests fail with:
    
    | env = {}
    |
    |     def prepare_conf(env={}):
    |         testenv = define_env(env)
    |         ngcpcfg_path = testenv["NGCPCFG"]
    | >       if not ngcpcfg_path.is_relative_to(CWD):
    | E       AttributeError: 'PosixPath' object has no attribute 'is_relative_to'
    
    While python3-pytest depends on python3:any, let's keep the build
    dependency slim, by build-depending on the python3-minimal package only.
    
    Problem spotted while trying to debug the git safe.directory issue
    in an outdated bullseye based container, providing python3 3.7.5-3.
    
    Change-Id: Ib620a796a780817a81a51d791a766c950b1a541c
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes easy stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants