admin管理员组

文章数量:1435859

I have a Python project with a flat layout that has some resource files. My pyproject.toml has the following entries:

[tool.setuptools]
packages = [
    "linton",
    "linton.subcommand",
]

[tool.setuptools.package-data]
linton = ["init-pages/**"]

and the following layout:

linton
├── argparse_util.py
├── init-pages
│   ├── Author.in.txt
│   ├── body.in.md
│   ├── breadcrumb.in.py
│   ├── email.in.py
│   ├── Email.in.txt
│   ├── index.nancy.html
│   ├── lastmodified.in.py
│   ├── markdown-to-html.in.sh
│   ├── menudirectory.in.py
│   ├── pageinsite.in.py
│   ├── path-to-root.in.py
│   ├── Sample page
│   │   ├── body.in.md
│   │   └── index.nancy.html
│   ├── style.css
│   ├── template.in.html
│   └── Title.in.txt
├── __init__.py
├── __main__.py
├── subcommand
│   ├── init.py
│   ├── publish.py
│   └── serve.py
└── warnings_util.py

Note the init-pages directory: it contains resource files for a linton init command, which, like many similar tools, creates a template project (in this case, a web site), and copies files into it (the contents of init-pages).

Also note that init-pages contains some .py files.

Packaging this project works fine: the source files and resource files are included as expected by pip.

The surprise to me is that when I pip install this project, pip compiles the .py files in the init-pages directory, although this directory is not included in packages and is only marked as package data.

I am unable to find any documentation about how pip decides which files to byte-compile on installation. I can turn it off globally, but of course I don't want to do that, and it doesn't help my users.

I could also work around the problem by making linton init skip the generated __pycache__ directory when copying the resource files into the user's project. But it seems wrong that they exist in the first place, and I would like to prevent this.

本文标签: How can I stop resource files that are Python source from being compiled by pipStack Overflow