manifest file in Python
Purpose of the MANIFEST.in
File
The MANIFEST.in
file allows you to specify which files should be included in the source distribution of your package. When you run the setup.py sdist
command, Python’s setuptools or distutils reads this file and includes the specified files in the created tarball or zip file.
Example MANIFEST.in
Content and Explanation
Let's break down the example MANIFEST.in
file:
include selenium/selenium.py
include selenium/__init__.py
include selenium/py.typed
include selenium/webdriver/common/linux/selenium-manager
include selenium/webdriver/common/macos/selenium-manager
include selenium/webdriver/common/windows/selenium-manager.exe
include CHANGES
include README.rst
include LICENSE
Explanation of Each Line
include selenium/selenium.py
: Ensures thatselenium.py
in theselenium
directory is included in the source distribution.include selenium/__init__.py
: Ensures that the__init__.py
file in theselenium
directory is included. This is typically needed to mark the directory as a package.include selenium/py.typed
: Includes thepy.typed
file, which is used to indicate that the package supports type hints, according to PEP 561.include selenium/webdriver/common/linux/selenium-manager
: Includes theselenium-manager
executable for Linux.include selenium/webdriver/common/macos/selenium-manager
: Includes theselenium-manager
executable for macOS.include selenium/webdriver/common/windows/selenium-manager.exe
: Includes theselenium-manager.exe
executable for Windows.include CHANGES
: Includes theCHANGES
file, which usually contains the change log for the project.include README.rst
: Includes theREADME.rst
file, which often contains the project’s readme, providing an overview and instructions.include LICENSE
: Includes theLICENSE
file, which contains the licensing information for the project.
Why Include These Files?
Python Source Files and Package Metadata:
- Including Python source files like
selenium.py
and__init__.py
is necessary for the functionality of the package. - The
py.typed
file is included to ensure that type information is available for tools like mypy, which check type hints.
Executables:
- The
selenium-manager
executables for different platforms (Linux, macOS, Windows) are included to ensure that the package can provide platform-specific functionality without requiring users to manually download these executables.
Documentation and Licensing:
- Including
CHANGES
,README.rst
, andLICENSE
files is important for documentation and legal compliance. These files provide users with information about the project’s updates, usage instructions, and licensing terms.
How MANIFEST.in
Works with setup.py
The MANIFEST.in
file works in conjunction with the setup.py
script. Here’s a simple example of how the setup.py
might look:
from setuptools import setup, find_packages
setup(
name='selenium',
version='4.0.0',
packages=find_packages(),
include_package_data=True, # This is important to ensure MANIFEST.in is respected
...
)
include_package_data=True
: This line tells setuptools to include any additional files specified in theMANIFEST.in
file.
Published on: Jun 27, 2024, 04:46 AM