Flask教程中MANIFEST.in的graft命令作用及语法咨询
Great question! When working through Flask's official tutorial, MANIFEST.in is critical for ensuring all your app's non-Python assets make it into your distribution package. Let's break down your questions clearly:
What does the graft command do?
The graft command is used to recursively include an entire directory and all its contents (subdirectories and files) in your package. This is ideal for Flask folders like templates or static assets, where you have nested files and subfolders that all need to be included without manually listing each one.
For example:
graft flaskr/templates: This tells setuptools to pull in every file and subfolder inside theflaskr/templatesdirectory. No need to list individual template files—graft handles the entire tree automatically.graft flaskr/static: Similarly, this includes all CSS, JavaScript, images, and nested subfolders within the static directory.
Is graft for folders and include for individual files?
Exactly! Here's the core distinction between the two commands:
graft: Exclusively targets entire directories, recursively including everything inside. Use this when you need all content from a folder (and its subfolders) packaged.include: Targets specific individual files or file patterns (without recursion). It won't pick up subfolders unless you explicitly use a wildcard that covers them, but that's not its intended purpose.
Your line include flaskr/schema.sql is the perfect use case for include: you're specifying a single, specific file that needs to be included in the package. If you tried to use graft for a single file, it wouldn't work—graft only operates on directories.
Documentation Reference
You can find comprehensive details about MANIFEST.in and all its supported commands in the official setuptools documentation. Look for the section dedicated to MANIFEST.in, which covers command behaviors, pattern matching rules, and best practices for packaging non-Python assets.
内容的提问来源于stack exchange,提问作者mau

