Setuptools Git Plugin

1.2 · maintenance · verified Sat Apr 11

setuptools-git is a plugin for setuptools that enables integration with Git. It allows setuptools to automatically include all files tracked by Git in a package distribution, serving as an alternative to explicitly listing files in MANIFEST.in. The current version is 1.2, last released in February 2017, and it was formerly known as gitlsfiles.

Warnings

Install

Imports

Quickstart

To use setuptools-git, ensure it is listed in `setup_requires` in your `setup.py` and set `include_package_data=True` in your `setup()` call. It requires an initialized Git repository with committed files. This example creates a minimal `setup.py` and a dummy Git repository to demonstrate how tracked files (like `my_package/module.py` and `my_package/data.txt`) are included, while ignored files (`ignored.tmp`) are not, when building a source distribution.

import os
import subprocess
from setuptools import setup, find_packages

# Create a dummy git repo for demonstration
if not os.path.exists('.git'):
    print("Initializing git repository...")
    subprocess.run(['git', 'init', '-b', 'main'], check=True)
    with open('README.md', 'w') as f: f.write('# My Project')
    os.makedirs('my_package', exist_ok=True)
    with open('my_package/__init__.py', 'w') as f: f.write('__version__ = "0.1.0"')
    with open('my_package/module.py', 'w') as f: f.write('def hello(): return "Hello"')
    with open('my_package/data.txt', 'w') as f: f.write('some data')
    with open('.gitignore', 'w') as f: f.write('*.tmp')
    with open('ignored.tmp', 'w') as f: f.write('temp file')
    subprocess.run(['git', 'add', '.'], check=True)
    subprocess.run(['git', 'commit', '-m', 'Initial commit'], check=True)


setup(
    name='my-project',
    version='0.1.0',
    packages=find_packages(),
    include_package_data=True, # This activates setuptools-git functionality
    setup_requires=["setuptools-git >= 0.3"],
    # Minimal metadata for a runnable setup.py
    author='Your Name',
    author_email='your.email@example.com',
    description='A short description',
    long_description='A longer description.',
    url='http://example.com/your-project',
    python_requires='>=3.6',
    install_requires=[]
)

print("\n--- To build the source distribution (sdist): ---")
print("python setup.py sdist")
print("This will include git-tracked files like my_package/module.py and my_package/data.txt, but exclude ignored.tmp.")

# Clean up dummy repo (optional)
# import shutil
# if os.path.exists('.git'):
#     shutil.rmtree('.git')
# if os.path.exists('my_package'):
#     shutil.rmtree('my_package')
# if os.path.exists('README.md'):
#     os.remove('README.md')
# if os.path.exists('.gitignore'):
#     os.remove('.gitignore')
# if os.path.exists('ignored.tmp'):
#     os.remove('ignored.tmp')

view raw JSON →