$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>How can I stop resource files that are Python source from being compiled by pip? - Stack Overflow|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

How can I stop resource files that are Python source from being compiled by pip? - Stack Overflow

matteradmin12PV0评论

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.

Post a comment

comment list (0)

  1. No comments so far