add an ability to check that a Path has an executable bit set
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Nicky Sielicki · committed by David Lord · parent 24992ce · Browse files · 2 files·+27 added−9 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+27 added−9 removed
- other:+27 added−9 removed
Provenance
- Commit
06b1588- Tree
76ee50d- Author
Nicky Sielicki <sielicki@yandex.com>- Committer
David Lord <davidism@gmail.com>- Parent
24992ce
2 files changed+27 added−9 removed
modified:src/click/types.py+25 added-8 removed
751 unmodified lines752 be valid. If this is not set to ``True``, and the file does not753 exist, then all further checks are silently skipped.754 :param file_okay: Allow a file as a value.755 :param dir_okay: Allow a directory as a value.756- :param writable: The file or directory must be writable.757- :param readable: The file or directory must be readable.756+ :param readable: if true, a readable check is performed.757+ :param writable: if true, a writable check is performed.758+ :param executable: if true, an executable check is performed.759 :param resolve_path: Make the value absolute and resolve any760 symlinks. A ``~`` is not expanded, as this is supposed to be761 done by the shell only.762 :param allow_dash: Allow a single dash as a value, which indicates2 unmodified lines765 :param path_type: Convert the incoming path value to this type. If766 ``None``, keep Python's default, which is ``str``. Useful to767 convert to :class:`pathlib.Path`.768 769+ .. versionchanged:: 8.1770+ Added the ``executable`` parameter.771+772 .. versionchanged:: 8.0773 Allow passing ``type=pathlib.Path``.774 775 .. versionchanged:: 6.06 unmodified lines782 self,783 exists: bool = False,784 file_okay: bool = True,785 dir_okay: bool = True,782- writable: bool = False,786 readable: bool = True,787+ writable: bool = False,788+ executable: bool = False,789 resolve_path: bool = False,790 allow_dash: bool = False,791 path_type: t.Optional[t.Type] = None,792 ):793 self.exists = exists794 self.file_okay = file_okay795 self.dir_okay = dir_okay791- self.writable = writable796 self.readable = readable797+ self.writable = writable798+ self.executable = executable799 self.resolve_path = resolve_path800 self.allow_dash = allow_dash801 self.type = path_type802 64 unmodified lines867 ctx,868 )869 if not self.dir_okay and stat.S_ISDIR(st.st_mode):870 self.fail(865- _("{name} {filename!r} is a directory.").format(871+ _("{name} '{filename}' is a directory.").format(872 name=self.name.title(), filename=os.fsdecode(value)873 ),874 param,875 ctx,876 )877+878+ if self.readable and not os.access(rv, os.R_OK):879+ self.fail(880+ _("{name} '{filename}' is not executable.").format(881+ name=self.name.title(), filename=os.fsdecode(value)882+ ),883+ param,884+ ctx,885+ )886+887 if self.writable and not os.access(rv, os.W_OK):888 self.fail(873- _("{name} {filename!r} is not writable.").format(889+ _("{name} '{filename}' is not writable.").format(890 name=self.name.title(), filename=os.fsdecode(value)891 ),892 param,893 ctx,894 )879- if self.readable and not os.access(rv, os.R_OK):895+896+ if self.executable and not os.access(value, os.X_OK):897 self.fail(881- _("{name} {filename!r} is not readable.").format(898+ _("{name} {filename!r} is not executable.").format(899 name=self.name.title(), filename=os.fsdecode(value)900 ),901 param,902 ctx,164 unmodified linesmodified:CHANGES.rst+2 added-1 removed
1 unmodified line2 3 Version 8.1.04 -------------5 6-Unreleased6+- An an argument to ``Path`` which mirrors writable/readable, but for7+ executable bits. :issue:`1961`8 9 - Drop support for Python 3.6. :pr:`2129`10 - Remove previously deprecated code. :pr:`2130`11 966 unmodified lines