Skip to content

Revise docstrings, comments, and a few messages #1850

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

Merged
merged 61 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
9b5531b
Fix typos and further clarify Git.refresh docstring
EliahKagan Feb 24, 2024
c0cd8a8
Clarify comment on shell case in _safer_popen_windows
EliahKagan Feb 24, 2024
afd943a
Tweak message about GIT_PYTHON_REFRESH for 80-column terminals
EliahKagan Feb 24, 2024
e08066c
Revise docstrings in git.__init__ and git.cmd
EliahKagan Feb 24, 2024
8bb882e
Fix concurrency note for stream_object_data
EliahKagan Feb 24, 2024
ba878ef
Reword partial_to_complete_sha_hex note
EliahKagan Feb 24, 2024
3958747
Update CommandError._msg documentation
EliahKagan Feb 24, 2024
f56e1ac
Tweak code formatting in Remote._set_cache_
EliahKagan Feb 24, 2024
fa471fe
Fix up Remote.push docstring
EliahKagan Feb 24, 2024
1cd73ba
Revise docstrings in second-level modules
EliahKagan Feb 25, 2024
29c63ac
Format first Git.execute overload stub like the others
EliahKagan Feb 25, 2024
cd8a312
Show full-path refresh() in failure message differently
EliahKagan Feb 25, 2024
8ec7e32
Revise docstrings within git.index
EliahKagan Feb 26, 2024
ca2ab61
Rewrite post_clear_cache note
EliahKagan Feb 26, 2024
37421e1
Further revise post_clear_cache docstring
EliahKagan Feb 26, 2024
ca32c22
Condense output_stream description in Git.execute docstring
EliahKagan Feb 26, 2024
3813bfb
Clarify Submodule.branch_path documentation
EliahKagan Feb 26, 2024
63c62ed
Revise docstrings within git.objects.submodule
EliahKagan Feb 27, 2024
115451d
Change _write to write in SubmoduleConfigParser docstring
EliahKagan Feb 27, 2024
5219489
Fix IndexObject.abspath docstring formatting
EliahKagan Feb 27, 2024
c06dfd9
Fix parameter names in TagObject.__init__
EliahKagan Feb 27, 2024
ae37a4a
Revise docstrings within git.objects
EliahKagan Feb 27, 2024
37011bf
Fix backslash formatting in git.util docstrings
EliahKagan Feb 27, 2024
d9fb2f4
Further git.util docstring revisions
EliahKagan Feb 27, 2024
d1d18c2
Revise docstrings within git.refs
EliahKagan Feb 27, 2024
4f67369
Fix backslashes in Repo.__init__ docstring
EliahKagan Feb 27, 2024
0c8ca1a
Fix Repo.iter_commits docstring about return type
EliahKagan Feb 27, 2024
b2b6f7c
Revise docstrings within git.repo
EliahKagan Feb 28, 2024
c67b2e2
Adjust spacing in colon seach mode NotImplementedError
EliahKagan Feb 28, 2024
5ee8744
Update git source link in Repo.merge_base comment
EliahKagan Feb 28, 2024
c8b6cf0
Update comment about improving expand_path overloads
EliahKagan Feb 28, 2024
bcc0c27
Fix recent inconsistency, using :raise:, not :raises:
EliahKagan Feb 28, 2024
0231b74
Further revise docstrings in git.objects.submodule.base
EliahKagan Feb 28, 2024
8344f44
Revise Repo.archive docstring
EliahKagan Feb 28, 2024
432ec72
Fix another :raises: to :raise:
EliahKagan Feb 28, 2024
5ca5844
Fully qualify non-builtin exceptions in :raise:
EliahKagan Feb 28, 2024
e6768ec
Improve Git.execute docstring formatting re: max_chunk_size
EliahKagan Feb 28, 2024
cd61eb4
Further revise docstrings in second-level modules
EliahKagan Feb 28, 2024
fc1762b
Undo a couple minor black-incompatible changes
EliahKagan Feb 28, 2024
1b25a13
Further revise docstrings within git.index
EliahKagan Feb 28, 2024
08a80aa
Further revise docstrings within git.objects.submodule
EliahKagan Feb 28, 2024
bc48d26
Further revise other docstrings within git.objects
EliahKagan Feb 28, 2024
30f7da5
Fix erroneous reference to DateTime "class"
EliahKagan Feb 28, 2024
6126997
Improve docstrings about tags
EliahKagan Feb 29, 2024
110706e
Fix param name in TagRefernece docstring and add info
EliahKagan Feb 29, 2024
b0e5bff
Undo some expansion of "reference" parameter
EliahKagan Feb 29, 2024
a5a1b2c
Add a bit of missing docstring formatting
EliahKagan Feb 29, 2024
018ebaf
Further revise docstrings within git.repo
EliahKagan Feb 29, 2024
608147e
Better explain conditional cleanup in test_base_object
EliahKagan Feb 29, 2024
5cf5b60
Revise test suite docstrings and comments
EliahKagan Feb 29, 2024
4b04d8a
Better clarify Submodule.branch_path documentation
EliahKagan Feb 29, 2024
254c82a
More docstring revisions within git.refs
EliahKagan Feb 29, 2024
679d2e8
Fix exception type in require_remote_ref_path docstring
EliahKagan Feb 29, 2024
ee0301a
More docstring revisions in second-level modules and git.__init__
EliahKagan Feb 29, 2024
231c3ef
More docstring revisions within git.repo
EliahKagan Feb 29, 2024
e166a0a
More docstring revisions within git.objects
EliahKagan Feb 29, 2024
ffeb7e7
More docstring revisions in git.objects.submodule.base
EliahKagan Feb 29, 2024
ec93955
Further refine some docstring revisions
EliahKagan Feb 29, 2024
63983c2
Remove note in GitCmdObjectDB docstring
EliahKagan Feb 29, 2024
f43292e
Somewhat improve _get_ref_info{,_helper} docstrings
EliahKagan Feb 29, 2024
37c93de
A couple more small docstring refinements
EliahKagan Feb 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Further revise docstrings within git.index
  • Loading branch information
EliahKagan committed Feb 28, 2024
commit 1b25a13a36ec641ffd63a6f1a97c3bdf8f6d28de
147 changes: 77 additions & 70 deletions git/index/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

"""Module containing IndexFile, an Index implementation facilitating all kinds of index
manipulations such as querying and merging."""
"""Module containing :class:`IndexFile`, an Index implementation facilitating all kinds
of index manipulations such as querying and merging."""

import contextlib
import datetime
Expand Down Expand Up @@ -125,9 +125,9 @@ class IndexFile(LazyMixin, git_diff.Diffable, Serializable):
git command function calls wherever possible.

This provides custom merging facilities allowing to merge without actually changing
your index or your working tree. This way you can perform own test-merges based on
the index only without having to deal with the working copy. This is useful in case
of partial working trees.
your index or your working tree. This way you can perform your own test merges based
on the index only without having to deal with the working copy. This is useful in
case of partial working trees.

Entries:

Expand Down Expand Up @@ -211,7 +211,7 @@ def _deserialize(self, stream: IO) -> "IndexFile":
return self

def _entries_sorted(self) -> List[IndexEntry]:
""":return: list of entries, in a sorted fashion, first by path, then by stage"""
""":return: List of entries, in a sorted fashion, first by path, then by stage"""
return sorted(self.entries.values(), key=lambda e: (e.path, e.stage))

def _serialize(self, stream: IO, ignore_extension_data: bool = False) -> "IndexFile":
Expand All @@ -232,17 +232,17 @@ def write(
"""Write the current state to our file path or to the given one.

:param file_path:
If None, we will write to our stored file path from which we have been
If ``None``, we will write to our stored file path from which we have been
initialized. Otherwise we write to the given file path. Please note that
this will change the file_path of this index to the one you gave.
this will change the `file_path` of this index to the one you gave.

:param ignore_extension_data:
If True, the TREE type extension data read in the index will not be written
to disk. NOTE that no extension data is actually written.
Use this if you have altered the index and would like to use git-write-tree
afterwards to create a tree representing your written changes.
If this data is present in the written index, git-write-tree will instead
write the stored/cached tree.
If ``True``, the TREE type extension data read in the index will not be
written to disk. NOTE that no extension data is actually written.
Use this if you have altered the index and would like to use
``git write-tree`` afterwards to create a tree representing your written
changes. If this data is present in the written index, ``git write-tree``
will instead write the stored/cached tree.
Alternatively, use :meth:`write_tree` to handle this case automatically.
"""
# Make sure we have our entries read before getting a write lock.
Expand Down Expand Up @@ -479,8 +479,8 @@ def _write_path_to_stdin(
stdout string

:param read_from_stdout:
If True, proc.stdout will be read after the item was sent to stdin. In that
case, it will return None.
If ``True``, ``proc.stdout`` will be read after the item was sent to stdin.
In that case, it will return ``None``.

:note:
There is a bug in git-update-index that prevents it from sending reports
Expand Down Expand Up @@ -516,12 +516,13 @@ def iter_blobs(
) -> Iterator[Tuple[StageType, Blob]]:
"""
:return:
Iterator yielding tuples of Blob objects and stages, tuple(stage, Blob).
Iterator yielding tuples of :class:`~git.objects.blob.Blob` objects and
stages, tuple(stage, Blob).

:param predicate:
Function(t) returning True if tuple(stage, Blob) should be yielded by the
iterator. A default filter, the `~git.index.typ.BlobFilter`, allows you to
yield blobs only if they match a given list of paths.
Function(t) returning ``True`` if tuple(stage, Blob) should be yielded by
the iterator. A default filter, the `~git.index.typ.BlobFilter`, allows you
to yield blobs only if they match a given list of paths.
"""
for entry in self.entries.values():
blob = entry.to_blob(self.repo)
Expand All @@ -534,8 +535,8 @@ def iter_blobs(
def unmerged_blobs(self) -> Dict[PathLike, List[Tuple[StageType, Blob]]]:
"""
:return:
Dict(path : list( tuple( stage, Blob, ...))), being a dictionary associating
a path in the index with a list containing sorted stage/blob pairs.
Dict(path : list(tuple(stage, Blob, ...))), being a dictionary associating a
path in the index with a list containing sorted stage/blob pairs.

:note:
Blobs that have been removed in one side simply do not exist in the given
Expand All @@ -562,8 +563,8 @@ def resolve_blobs(self, iter_blobs: Iterator[Blob]) -> "IndexFile":
This will effectively remove the index entries of the respective path at all
non-null stages and add the given blob as new stage null blob.

For each path there may only be one blob, otherwise a ValueError will be raised
claiming the path is already at stage 0.
For each path there may only be one blob, otherwise a :class:`ValueError` will
be raised claiming the path is already at stage 0.

:raise ValueError:
If one of the blobs already existed at stage 0.
Expand Down Expand Up @@ -603,7 +604,8 @@ def update(self) -> "IndexFile":
This is a possibly dangerous operations as it will discard your changes to
:attr:`index.entries <entries>`.

:return: self
:return:
self
"""
self._delete_entries_cache()
# Allows to lazily reread on demand.
Expand Down Expand Up @@ -654,8 +656,9 @@ def _process_diff_args(

def _to_relative_path(self, path: PathLike) -> PathLike:
"""
:return: Version of path relative to our git directory or raise
:class:`ValueError` if it is not within our git directory.
:return:
Version of path relative to our git directory or raise :class:`ValueError`
if it is not within our git directory.

:raise ValueError:
"""
Expand Down Expand Up @@ -693,7 +696,7 @@ def _store_path(self, filepath: PathLike, fprogress: Callable) -> BaseIndexEntry
"""Store file at filepath in the database and return the base index entry.

:note:
This needs the git_working_dir decorator active!
This needs the :func:`~git.index.util.git_working_dir` decorator active!
This must be ensured in the calling code.
"""
st = os.lstat(filepath) # Handles non-symlinks as well.
Expand Down Expand Up @@ -810,33 +813,36 @@ def add(
The handling now very much equals the way string paths are processed,
except that the mode you have set will be kept. This allows you to
create symlinks by settings the mode respectively and writing the target
of the symlink directly into the file. This equals a default
Linux symlink which is not dereferenced automatically, except that it
can be created on filesystems not supporting it as well.
of the symlink directly into the file. This equals a default Linux
symlink which is not dereferenced automatically, except that it can be
created on filesystems not supporting it as well.

Please note that globs or directories are not allowed in
:class:~`git.objects.blob.Blob` objects.
:class:`~git.objects.blob.Blob` objects.

They are added at stage 0.

- :class:`~git.index.typ.BaseIndexEntry` or type

Handling equals the one of Blob objects, but the stage may be explicitly
set. Please note that Index Entries require binary sha's.
Handling equals the one of :class:~`git.objects.blob.Blob` objects, but
the stage may be explicitly set. Please note that Index Entries require
binary sha's.

:param force:
**CURRENTLY INEFFECTIVE**
If True, otherwise ignored or excluded files will be added anyway.
As opposed to the ``git add`` command, we enable this flag by default as the
If ``True``, otherwise ignored or excluded files will be added anyway. As
opposed to the ``git add`` command, we enable this flag by default as the
API user usually wants the item to be added even though they might be
excluded.

:param fprogress:
Function with signature ``f(path, done=False, item=item)`` called for each
path to be added, one time once it is about to be added where ``done=False``
and once after it was added where ``done=True``.
``item`` is set to the actual item we handle, either a Path or a

``item`` is set to the actual item we handle, either a path or a
:class:`~git.index.typ.BaseIndexEntry`.

Please note that the processed path is not guaranteed to be present in the
index already as the index is currently being processed.

Expand All @@ -845,24 +851,24 @@ def add(
for each passed entry which is the path to be actually recorded for the
object created from :attr:`entry.path <git.index.typ.BaseIndexEntry.path>`.
This allows you to write an index which is not identical to the layout of
the actual files on your hard-disk. If not None and `items` contain plain
paths, these paths will be converted to Entries beforehand and passed to the
path_rewriter. Please note that ``entry.path`` is relative to the git
the actual files on your hard-disk. If not ``None`` and `items` contain
plain paths, these paths will be converted to Entries beforehand and passed
to the path_rewriter. Please note that ``entry.path`` is relative to the git
repository.

:param write:
If True, the index will be written once it was altered. Otherwise the
If ``True``, the index will be written once it was altered. Otherwise the
changes only exist in memory and are not available to git commands.

:param write_extension_data:
If True, extension data will be written back to the index. This can lead to
issues in case it is containing the 'TREE' extension, which will cause the
``git commit`` command to write an old tree, instead of a new one
If ``True``, extension data will be written back to the index. This can lead
to issues in case it is containing the 'TREE' extension, which will cause
the ``git commit`` command to write an old tree, instead of a new one
representing the now changed index.

This doesn't matter if you use :meth:`IndexFile.commit`, which ignores the
'TREE' extension altogether. You should set it to True if you intend to use
:meth:`IndexFile.commit` exclusively while maintaining support for
'TREE' extension altogether. You should set it to ``True`` if you intend to
use :meth:`IndexFile.commit` exclusively while maintaining support for
third-party extensions. Besides that, you can usually safely ignore the
built-in extensions when using GitPython on repositories that are not
handled manually at all.
Expand All @@ -875,7 +881,7 @@ def add(
just actually added.

:raise OSError:
If a supplied Path did not exist. Please note that
If a supplied path did not exist. Please note that
:class:`~git.index.typ.BaseIndexEntry` objects that do not have a null sha
will be added even if their paths do not exist.
"""
Expand Down Expand Up @@ -999,7 +1005,7 @@ def remove(
it. If absolute paths are given, they will be converted to a path
relative to the git repository directory containing the working tree

The path string may include globs, such as \*.c.
The path string may include globs, such as ``*.c``.

- :class:~`git.objects.blob.Blob` object

Expand All @@ -1010,9 +1016,9 @@ def remove(
The only relevant information here is the path. The stage is ignored.

:param working_tree:
If True, the entry will also be removed from the working tree, physically
removing the respective file. This may fail if there are uncommitted changes
in it.
If ``True``, the entry will also be removed from the working tree,
physically removing the respective file. This may fail if there are
uncommitted changes in it.

:param kwargs:
Additional keyword arguments to be passed to ``git rm``, such as ``r`` to
Expand Down Expand Up @@ -1061,7 +1067,7 @@ def move(
for reference.

:param skip_errors:
If True, errors such as ones resulting from missing source files will be
If ``True``, errors such as ones resulting from missing source files will be
skipped.

:param kwargs:
Expand Down Expand Up @@ -1214,21 +1220,21 @@ def checkout(
case you have altered the entries dictionary directly.

:param paths:
If None, all paths in the index will be checked out. Otherwise an iterable
of relative or absolute paths or a single path pointing to files or
directories in the index is expected.
If ``None``, all paths in the index will be checked out.
Otherwise an iterable of relative or absolute paths or a single path
pointing to files or directories in the index is expected.

:param force:
If True, existing files will be overwritten even if they contain local
If ``True``, existing files will be overwritten even if they contain local
modifications.
If False, these will trigger a :class:`~git.exc.CheckoutError`.
If ``False``, these will trigger a :class:`~git.exc.CheckoutError`.

:param fprogress:
See :meth:`IndexFile.add` for signature and explanation.

The provided progress information will contain None as path and item if no
explicit paths are given. Otherwise progress information will be send prior
and after a file has been checked out.
The provided progress information will contain ``None`` as path and item if
no explicit paths are given. Otherwise progress information will be send
prior and after a file has been checked out.

:param kwargs:
Additional arguments to be passed to ``git checkout-index``.
Expand All @@ -1238,10 +1244,10 @@ def checkout(
guaranteed to match the version stored in the index.

:raise git.exc.CheckoutError:
If at least one file failed to be checked out. This is a summary, hence it
will checkout as many files as it can anyway.
If one of files or directories do not exist in the index (as opposed to the
original git command, which ignores them).
* If at least one file failed to be checked out. This is a summary, hence it
will checkout as many files as it can anyway.
* If one of files or directories do not exist in the index (as opposed to
the original git command, which ignores them).

:raise git.exc.GitCommandError:
If error lines could not be parsed - this truly is an exceptional state.
Expand Down Expand Up @@ -1394,7 +1400,7 @@ def reset(
**kwargs: Any,
) -> "IndexFile":
"""Reset the index to reflect the tree at the given commit. This will not adjust
our ``HEAD`` reference by default, as opposed to
our HEAD reference by default, as opposed to
:meth:`HEAD.reset <git.refs.head.HEAD.reset>`.

:param commit:
Expand All @@ -1406,14 +1412,14 @@ def reset(
overwrite the default index.

:param working_tree:
If True, the files in the working tree will reflect the changed index.
If False, the working tree will not be touched.
If ``True``, the files in the working tree will reflect the changed index.
If ``False``, the working tree will not be touched.
Please note that changes to the working copy will be discarded without
warning!

:param head:
If True, the head will be set to the given commit. This is False by default,
but if True, this method behaves like
If ``True``, the head will be set to the given commit. This is ``False`` by
default, but if ``True``, this method behaves like
:meth:`HEAD.reset <git.refs.head.HEAD.reset>`.

:param paths:
Expand All @@ -1433,7 +1439,8 @@ def reset(
If you want ``git reset``-like behaviour, use
:meth:`HEAD.reset <git.refs.head.HEAD.reset>` instead.

:return: self
:return:
self
"""
# What we actually want to do is to merge the tree into our existing index,
# which is what git-read-tree does.
Expand Down
4 changes: 2 additions & 2 deletions git/index/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ def read_header(stream: IO[bytes]) -> Tuple[int, int]:
def entry_key(*entry: Union[BaseIndexEntry, PathLike, int]) -> Tuple[PathLike, int]:
"""
:return:
Key suitable to be used for the :attr:`index.entries
<git.index.base.IndexFile.entries>` dictionary.
Key suitable to be used for the
:attr:`index.entries <git.index.base.IndexFile.entries>` dictionary.

:param entry:
One instance of type BaseIndexEntry or the path and the stage.
Expand Down
Loading