除非我删除“pyproject.toml”,否则无法使用“pip install -e”进行开发安装

Pet*_*Kie 6 python pip setuptools setup.py pyproject.toml

我有以下情况,pip install -e .除非我删除不包含打包信息,但黑色配置的版本,否则不会构建版本。developpyproject.toml

有人知道该怎么做才能获得构建develop

我的pyproject.toml样子是这样的:

# Source https://github.com/psf/black#configuration-format
[tool.black]
line-length = 100
target-version = ['py38']
exclude = '''

'''
Run Code Online (Sandbox Code Playgroud)

setup.py

from setuptools import find_namespace_packages
from setuptools import setup

setup(
    name="webservice",
    packages=find_packages(),
    version="0.1.0",
    description="description",
    author="Author",
    license="License",
)
Run Code Online (Sandbox Code Playgroud)

pip install -e .使用这两个文件运行...

(webservice_tool)pk@LAP1:~/webservice_tool$ pip install -e .
Obtaining file:///home/pk/webservice_tool
  Installing build dependencies ... done
  Checking if build backend supports build_editable ... done
  Getting requirements to build editable ... done
  Preparing editable metadata (pyproject.toml) ... done
Building wheels for collected packages: webservice
  Building editable for webservice (pyproject.toml) ... done
  Created wheel for webservice: filename=webservice-0.1.0-0.editable-py3-none-any.whl size=4070 sha256=dcb7c034ba437503d1059fe9370ccafbda144cd19f3e5d92340a63a7da396422
  Stored in directory: /tmp/pip-ephem-wheel-cache-6iqiqbob/wheels/e6/b5/ba/40d8c3d66df94ee2ae46e181034e0c3c47132784db53284d0b
Successfully built webservice
Installing collected packages: webservice
Successfully installed webservice-0.1.0
Run Code Online (Sandbox Code Playgroud)

我删除pyproject.toml了然后才Running setup.py develop出现。

(webservice_tool) pk@LAP1:~/webservice_tool$ pip install -e .
Obtaining file:///home/pk/webservice_tool
  Preparing metadata (setup.py) ... done
Installing collected packages: webservice
  Attempting uninstall: webservice
    Found existing installation: webservice 0.1.0
    Uninstalling webservice-0.1.0:
      Successfully uninstalled webservice-0.1.0
  Running setup.py develop for webservice
Successfully installed webservice-0.1.0
Run Code Online (Sandbox Code Playgroud)

我的 conda env 中某些选定软件包的版本,在 wsl2 中运行

packaging                 21.3               pyhd3eb1b0_0  
pip                       22.1.2           py38h06a4308_0  
python                    3.8.13               h12debd9_0  
setuptools                61.2.0           py38h06a4308_0  
Run Code Online (Sandbox Code Playgroud)

文件夹结构

|-- data_utils
|   |-- clean_cache.py
|   `-- advanced_utils.py
|-- deployment
|   |-- base_deployment
|   |   |-- auth-proxy.yaml
|   |   |-- kustomization.yaml
|   |   |-- webapi.yaml
|   |   `-- webui.yaml
|   `-- mysql_from_helm
|       |-- mysql-from-helm.yaml
|       `-- mysql-kustomization.yaml
|-- docker-compose.yml
|-- Dockerfile
|-- environment.yml
|-- live_api
|   |-- definitions.json
|   |-- __init__.py
|   `-- live_api.py
|-- params.py
|-- pyproject.toml
|-- setup.py
|-- shared_helpers
|   |-- data_cleaning.py
|   |-- handle_time.py
|   |-- __init__.py
|   |-- plot_timesequence.py
|   |-- read_samples.py
|   `-- save_samples.py
|-- setup.py
|-- util.py
|-- webtool
|   |-- clean_data
|   |   |-- clean_data.py
|   |   `-- __init__.py
|   |-- evaluation
|   |   |-- draw_figures.py
|   |   |-- __init__.py
|   |   `-- webtool_metrics.py
|   |-- __init__.py
|   |-- preprocess
|   |   |-- __init__.py
|   |   `-- preprocess.py
|   |-- ui
|   |   |-- __init__.py
|   |   `-- create_ui.py
|   `-- util
|       |-- data_input.py
|       |-- data_redefinitions.py
|       `-- __init__.py
|-- webtool.egg-info
|   |-- dependency_links.txt
|   |-- entry_points.txt
|   |-- PKG-INFO
|   |-- SOURCES.txt
|   `-- top_level.txt
`-- webtool_tests
    |-- clean_data
    |   `-- test_clean_data.py
    |-- evaluation
    |   `-- test_draw_figures.py
    |-- preprocess
    |   `-- test_preprocess.py
    `-- util
        |-- test_data_input.py
        `-- test_data_redefinitions.py
Run Code Online (Sandbox Code Playgroud)

wim*_*wim 3

这些都是开发安装。这里 pip 输出的差异是因为文件的存在(或不存在)pyproject.toml会导致 pip 使用(或不使用)构建后端挂钩。来自 PEP 517

如果pyproject.toml文件不存在...源树不使用此规范,工具应恢复到运行 setup.py 的旧行为

您还可以使用 pip 命令行选项来控制:

$ pip install --help | grep pep
  --use-pep517                Use PEP 517 for building source distributions
                              (use --no-use-pep517 to force legacy behaviour).
Run Code Online (Sandbox Code Playgroud)

不同之处在于,使用 PEP 517 样式构建时,pip 设置 venv 并全新安装 setuptools,以便在幕后进行包构建(请参阅日志中的“安装构建依赖项...完成”python setup.py develop ),而不是直接调用这里只是假设您用来执行setup.py. 这里的要点是,使用 PEP 517 风格的构建系统允许项目指定它所需的 setuptools 版本(或者,实际上,完全使用其他一些构建系统)。

最终结果将是相同的 - .pth路径配置文件会将源目录公开为开发安装。

由于util.py不包含在任何包中,因此要在开发安装中选取它(而不是仅从当前工作目录导入),您还需要在调用中将其find_packages()列出setup

# in setup.py 
from setuptools import setup

setup(
    name="webservice",
    version="0.1.0",
    packages=find_packages(),
    py_modules=["util"],  # <--- here
    ...
)
Run Code Online (Sandbox Code Playgroud)