代码之家  ›  专栏  ›  技术社区  ›  Arne

从卸载的控制盘生成requirements.txt

  •  1
  • Arne  · 技术社区  · 6 年前

    我正在尝试从本地卸载的控制盘生成一个需求列表。只需获取作为 packages 参数输入 setup.py setuptools.setup -打电话是最好的。一个 pip freeze 如果安装了轮子也能工作。


    我想建立一个docker映像,将在CI链中使用。为了减少管道时间,它应该首先加载所有运行时依赖项。但是在构建映像的时候,python包还没有构建,在链外部构建包只是为了获得一个 requirements.txt

    我试过的东西

    把它植入Dockerfile

    python -c $'\
    import setuptools\n\
    setuptools.setup = lambda *args, **kwargs: None\n\
    exec(compile(open("setup.py").read(), "setup.py", "exec"))\n\
    for requirement in requirements: print(requirement)\n' > python_packages.txt
    # `requirements` is the name of variable that holds the package list 
    

    这并不能很好地工作,因为docker在其构建上下文中做了一些奇怪的事情。有密码吗 VERSION 文件)打破了这个黑客。

    修复docker构建上下文以使此代码正常工作可以解决我的问题,但我更喜欢一个适当的解决方案,它不隐式地依赖于内容的外观 设置.py .

    使用pip/pipreqs/pipenv/pipdeptree

    所有这些工具都在本地环境上工作,无法处理未安装的控制盘。 This answer pip ,但是1)只有当包在pyPI上传时才有效(我的目标包不是),2)进行大量的干构建来获取包列表。

    1 回复  |  直到 6 年前
        1
  •  1
  •   wim    6 年前

    我的项目 johnnydep 具有从 轮锉。

    pip install johnnydep
    johnnydep your-wheel-file.whl --output-format=pinned
    

    $ johnnydep johnnydep-0.5-py2.py3-none-any.whl --output-format pinned
    johnnydep==0.5
    anytree==2.4.3
    cachetools==2.1.0
    colorama==0.3.9
    oyaml==0.7
    packaging==18.0
    pip==18.0
    pkginfo==1.4.2
    pytoml==0.1.19
    setuptools==40.4.3
    structlog==18.2.0
    tabulate==0.8.2
    wheel==0.32.1
    wimpy==0.4
    six==1.11.0
    pyyaml==3.13
    pyparsing==2.2.2