libgit2 / pygit2

Python bindings for libgit2
https://www.pygit2.org/
Other
1.62k stars 392 forks source link

It's not documented how to use constants #1289

Open hramrach opened 7 months ago

hramrach commented 7 months ago

Documentation says:

insert(name: str, oid: Oid, attr: FileMode) Insert or replace an entry in the treebuilder.

Parameters:

attr Available values are FileMode.BLOB, FileMode.BLOB_EXECUTABLE, FileMode.TREE, FileMode.LINK and FileMode.COMMIT.

Where is FileMode.BLOB defined?

import tempfile
import pygit2
import shutil
import sys

print(f"python: {sys.version}")
print(f"libgit2: {pygit2.LIBGIT2_VERSION}")
print(f"pygit2: {pygit2.__version__}")

repodir = tempfile.mkdtemp()
repo = pygit2.init_repository(repodir, bare=True)

sig = pygit2.Signature('Test User', 'testuser@nowhere.net')

data = 'blah blah master'
tree = repo.TreeBuilder()
data = repo.create_blob(data.encode())

try:
    tree.insert('file', data, pygit2.FileMode.BLOB)
except Exception as e:
    print(e)

try:
    tree.insert('file', data, pygit2.TreeBuilder.FileMode.BLOB)
except Exception as e:
    print(e)

shutil.rmtree(repodir)
python: 3.11.8 (main, Feb 29 2024, 12:19:47) [GCC]
libgit2: 1.8.0
pygit2: 1.14.1
module 'pygit2' has no attribute 'FileMode'
type object '_pygit2.TreeBuilder' has no attribute 'FileMode'
qaqland commented 6 months ago
from pygit2 import enums
hramrach commented 6 months ago

Yes, looking at the source I can understand this is required.

How am I supposed to infer that from the docs?

siddhpant commented 4 months ago

Bump