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.pyin theseleniumdirectory is included in the source distribution.include selenium/__init__.py: Ensures that the__init__.pyfile in theseleniumdirectory is included. This is typically needed to mark the directory as a package.include selenium/py.typed: Includes thepy.typedfile, which is used to indicate that the package supports type hints, according to PEP 561.include selenium/webdriver/common/linux/selenium-manager: Includes theselenium-managerexecutable for Linux.include selenium/webdriver/common/macos/selenium-manager: Includes theselenium-managerexecutable for macOS.include selenium/webdriver/common/windows/selenium-manager.exe: Includes theselenium-manager.exeexecutable for Windows.include CHANGES: Includes theCHANGESfile, which usually contains the change log for the project.include README.rst: Includes theREADME.rstfile, which often contains the project’s readme, providing an overview and instructions.include LICENSE: Includes theLICENSEfile, which contains the licensing information for the project.
Why Include These Files?
Python Source Files and Package Metadata:
- Including Python source files like
selenium.pyand__init__.pyis necessary for the functionality of the package. - The
py.typedfile is included to ensure that type information is available for tools like mypy, which check type hints.
Executables:
- The
selenium-managerexecutables 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, andLICENSEfiles 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.infile.
Published on: Jun 27, 2024, 04:46 AM