python / cpython

The Python programming language
https://www.python.org
Other
62.47k stars 29.99k forks source link

Finding programs in PATH, adding shutil.which #34832

Closed 44e76c4e-f397-45e7-8e63-ae88bc35aef5 closed 11 years ago

44e76c4e-f397-45e7-8e63-ae88bc35aef5 commented 23 years ago
BPO 444582
Nosy @loewis, @birkenfeld, @abalkin, @pitrou, @vstinner, @giampaolo, @tiran, @devdanzin, @tarekziade, @merwok, @agbuckley, @bitdancer, @voidspace, @briancurtin, @petere, @sandrotosi, @takluyver
Files
  • find_in_path.py: Reference implementation of which and find_in_path (which anyone is free to use)
  • shutil_which.patch: patch against 76432
  • which.py: Another reference implementation as a standalone module based on '2010-01-13 shutil_which.patch' with several fixes, mostly but not only for windows
  • which.py: Updated version of reference implementation as a standalone module
  • which.py: Updated version of reference implementation as a standalone module
  • shutil_which_82778.patch: patch against 82778
  • which.py: updated reference implementation as a standalone module
  • shutil_which_82778.patch: updated patch against 82778
  • which.py: updated reference implementation as a standalone module
  • shutil_which_82778.patch: updated patch against 82778
  • which.py: updated reference implementation as a standalone module
  • pathtest.bat: Batch file demonstrating Windows PATH behaviour with quoted paths
  • issue444582.diff
  • issue444582_v2.diff
  • issue444582_v3.diff
  • issue444582_v4.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: ```python assignee = 'https://github.com/briancurtin' closed_at = created_at = labels = ['type-feature', 'library'] title = 'Finding programs in PATH, adding shutil.which' updated_at = user = 'https://bugs.python.org/edemaine' ``` bugs.python.org fields: ```python activity = actor = 'eric.araujo' assignee = 'brian.curtin' closed = True closed_date = closer = 'eric.araujo' components = ['Library (Lib)'] creation = creator = 'edemaine' dependencies = [] files = ['8185', '15381', '16441', '16447', '16459', '17957', '17958', '17962', '17963', '18000', '18001', '23797', '26054', '26059', '26078', '26090'] hgrepos = [] issue_num = 444582 keywords = ['patch'] message_count = 61.0 messages = ['53174', '53175', '53176', '55402', '57774', '83484', '95614', '100444', '100460', '100469', '106046', '106055', '109234', '109554', '109583', '109587', '109764', '110033', '110034', '110049', '110068', '110073', '110084', '110085', '110291', '113241', '113285', '113944', '115016', '121398', '121424', '124996', '125222', '125233', '134306', '148475', '163201', '163242', '163253', '163376', '163454', '163466', '163479', '163481', '163482', '163483', '163484', '163485', '163487', '163488', '163490', '163492', '163493', '163764', '163800', '163802', '179889', '179891', '185218', '185220', '185221'] nosy_count = 31.0 nosy_names = ['loewis', 'tmick', 'georg.brandl', 'edemaine', 'belopolsky', 'pitrou', 'vstinner', 'wrstlprmpft', 'giampaolo.rodola', 'christian.heimes', 'ajaksu2', 'sfllaw', 'schmir', 'tarek', 'eric.araujo', 'Christophe Simonis', 'andybuckley', 'weeble', 'r.david.murray', 'tleeuwenburg@gmail.com', 'michael.foord', 'brian.curtin', 'meatballhat', 'petere', 'sandro.tosi', 'iki', 'BreamoreBoy', 'Iztok.Kavkler', 'python-dev', 'takluyver', 'Omega_Weapon'] pr_nums = [] priority = 'normal' resolution = 'fixed' stage = 'resolved' status = 'closed' superseder = None type = 'enhancement' url = 'https://bugs.python.org/issue444582' versions = ['Python 3.3'] ```

    bitdancer commented 12 years ago

    I'm fine with it changing. Hopefully it won't introduce subtle bugs in anyone's programs :)

    1762cc99-3127-4a62-9baf-30c3d0f51ef7 commented 12 years ago

    New changeset 9d2fe615a400 by Antoine Pitrou in branch 'default': Issue bpo-444582: shutil.which() respects relative paths. http://hg.python.org/cpython/rev/9d2fe615a400

    pitrou commented 12 years ago

    There is another small issue: it returns the normcase'd dir, which means that the case is lost under Windows. Not very serious, but cosmetically imperfect I suppose.

    birkenfeld commented 12 years ago

    From 3.2, os has a function get_exec_path -- shouldn't which() use it instead of rolling its own query of $PATH?

    abalkin commented 12 years ago

    I don't think the Windows example in the reST documentation is correct:

          >>> print(shutil.which("python"))
          'c:\\python33\\python.exe'

    It should be either

          >>> shutil.which("python")
          'c:\\python33\\python.exe'

    or

          >>> print(shutil.which("python"))
          c:\python33\python.exe
    1762cc99-3127-4a62-9baf-30c3d0f51ef7 commented 12 years ago

    New changeset 84b48551cd13 by Georg Brandl in branch 'default': bpo-444582: fix example and rewrap docs a bit. http://hg.python.org/cpython/rev/84b48551cd13

    cd34197f-d4a4-4e30-9fbe-454f267f097e commented 11 years ago

    The 'short circuit' appears to do what I'd consider the wrong thing when an executable file of the same name exists in the working directory. i.e. which('setup.py') can return 'setup.py', even though running 'setup.py' in a shell doesn't work (you need ./setup.py).

    This is on UNIX-y systems, I see from the comments that the cwd is implicitly on the path in Windows.

    Is this in scope for which() to deal with? Should I open a bug for it? Apologies if it's been discussed already.

    briancurtin commented 11 years ago

    Please open a separate issue.

    83d2e70e-e599-4a04-b820-3814bbdb9bef commented 11 years ago

    Was a separate issue opened? Is anything outstanding here or can this issue be closed?

    cd34197f-d4a4-4e30-9fbe-454f267f097e commented 11 years ago

    Yes, I opened that as bpo-16957, and it has been dealt with. So no objection from me to closing this.

    merwok commented 11 years ago

    It’s probably too late to address Georg’s comment about reusing os.get_exec_path, so everything is done.