简体   繁体   English

配置 conda build 以从 conda 包输出中排除某些文件夹

[英]Configure conda build to exclude some folders from the conda package output

tl;dr: tl;博士:

How do you exclude folders from being packaged by conda build ?你如何排除conda build打包的文件夹?

Context语境

I am building my first packages with conda build .我正在使用conda build构建我的第一个包。

My meta.yaml file looks like this:我的 meta.yaml 文件如下所示:

package:
    name: 'some_name'
    version: {{ load_setup_py_data().get('version') }}

source:
    path: ./

build:
    script: python setup.py install --single-version-externally-managed --record=record.txt

requirements:
    run:
        - python >=3.6
        - pandas >=0.2
        - numpy >=1.12
        # Packages that must be installed
        # in the user's conda environment
        # to run this package.

    build:
        # Packages used by setup.py
        # to install this package.
        # May also install compilers
        # for non-python code.
        - python
        - setuptools

And my root directory (where lies the setup.py & meta.yaml files) looks like this:我的根目录(setup.py 和 meta.yaml 文件所在的位置)如下所示:

$ ls
README.md   __pycache__      input       isi_classif meta.yaml   
notebooks   output      scripts     setup.py    version.py

Some folders are only there because they were useful during the prototyping but I don't want to delete them from the repo.有些文件夹之所以存在是因为它们在原型设计过程中很有用,但我不想从 repo 中删除它们。

How do I exclude a folder (like input or notebooks here) and its content from the package that conda builds ?如何从 conda 构建的包中排除文件夹(如此处的inputnotebooks )及其内容?

For info, I build with the following command:有关信息,我使用以下命令构建:

$ conda build some_folder_name

I think the best way would be to create a directory recipe/ and move the recipe related files there.我认为最好的方法是创建一个目录recipe/并将与配方相关的文件移动到那里。 Then change the meta.yaml to然后将meta.yaml更改为

source:
    path: ./..

So only the contents of the recipe directory would be copied over by conda into the package.所以只有配方目录的内容会被 conda 复制到包中。 Secondly, the folders notebooks and input would only be included if they are specified in the setup.py to be included.其次,只有在要包含的 setup.py 中指定了文件夹notebooksinput ,才会包含它们。 Otherwise they are ignored.否则它们将被忽略。 So they are not installed as part of the setup.py install and would not be included in the package.所以它们不是作为setup.py install一部分setup.py install ,也不会包含在包中。 So your source directory structure would look like:所以你的源目录结构看起来像:

some_folder_name
|--README.md
|--__pycache__
|--input
|--isi_classif
|--recipe
   |--meta.yaml   
|--notebooks
|--output
|--scripts
|--setup.py
|--version.py

then you could still build the package using conda build some_folder_name那么你仍然可以使用conda build some_folder_nameconda build some_folder_name

I am looking for an answer and everything I found were already in the comment of the question.我正在寻找答案,我发现的所有内容都已在问题的评论中。 Since those solutions seems working (not as intended but still works), I will explain it here.由于这些解决方案似乎有效(不符合预期但仍然有效),我将在此处进行解释。 I try the second solution on a test project and it works.我在一个测试项目中尝试了第二种解决方案,它有效。 I still not used to conda.我还是不习惯 conda。

First: Explicite output第一:显式输出

Explicit file lists:显式文件列表:

Explicit file lists are relative paths from the root of the build prefix.显式文件列表是从构建前缀的根开始的相对路径。 Explicit file lists support glob expressions.显式文件列表支持 glob 表达式。 Directory names are also supported, and they recursively include contents.也支持目录名称,它们递归地包含内容。

 outputs: - name: subpackage-name files: - a-file - a-folder - *.some-extension - somefolder/*.some-extension

Scripts that move files into the build prefix:将文件移动到构建前缀的脚本:

Scripts that create or move files into the build prefix can be any kind of script.创建或移动文件到构建前缀的脚本可以是任何类型的脚本。 Known script types need only specify the script name.已知脚本类型只需要指定脚本名称。 Currently the list of recognized extensions is py, bat, ps1 and sh.目前公认的扩展名列表是 py、bat、ps1 和 sh。

 outputs: - name: subpackage-name script: move-files.py

Specifying files to include in output 指定要包含在输出中的文件

Second: Ignore prefix files第二:忽略前缀文件

To specify individual filenames, use:要指定单个文件名,请使用:

 build: ignore_prefix_files: - file1

Ignore prefix files 忽略前缀文件

I didn't try the Michael Sarahan answer but it should work if correctly done.我没有尝试 Michael Sarahan 的答案,但如果正确完成它应该可以工作。

"You need to alter your build.sh/bld.bat to remove files from $PREFIX before the end of those scripts." “您需要更改 build.sh/bld.bat 以在这些脚本结束之前从 $PREFIX 中删除文件。”

I came across this thread while trying to address a similar issue.我在尝试解决类似问题时遇到了这个线程。 Since my meta.yaml is in a subfolder of the project root and I wanted to exclude only files that were not part of the repo (eg .tox folder), I ended up using the repository itself to specify the files to be included as follows:由于我的meta.yaml位于项目根目录的子文件夹中,并且我只想排除不属于 repo 的文件(例如.tox文件夹),因此我最终使用存储库本身来指定要包含的文件,如下所示:

...  
source:
    git_url: ..
...

Note:笔记:

  • the .tox folder wasn't actually being included in the final conda package - I just wanted to avoid having conda-build copy a large folder for no good reason. .tox文件夹实际上并未包含在最终的 conda 包中 - 我只是想避免让conda-build无缘无故地复制一个大文件夹。
  • it may be possible to achieve what you want by having your additional items live only in a specific branch of the repo, and using a different branch without those items for your build - see the docs for details.通过让额外的项目仅存在于 repo 的特定分支中,并使用没有这些项目的不同分支进行构建,可能会实现您想要的 - 有关详细信息,请参阅文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM