Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A new test for file existence inside a package (for the new recipe format) #57

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions cep-20.3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# A new recipe format – part 3 - file existence test section

<table>
<tr><td> Title </td><td> A new recipe format - file existence test section </td>
<tr><td> Status </td><td> Proposed</td></tr>
<tr><td> Author(s) </td><td> Wolf Vollprecht &lt;[email protected]&gt;</td></tr>
<tr><td> Created </td><td> June 15, 2023</td></tr>
<tr><td> Updated </td><td> June 15, 2023</td></tr>
<tr><td> Discussion </td><td> </td></tr>
<tr><td> Implementation </td><td>https://github.com/prefix-dev/rattler-build (coming soon)</td></tr>
</table>

## Abstract

We propose a new test-section for recipes (building on top of two previous CEPs that are in discussion).
The new test section will make it easier to test for package contents in a cross-platform fashion.

See also:

- [CEP for YAML Format for new recipe](https://github.com/conda-incubator/ceps/pull/54)
- [Content definition for new recipe format, incl. new test section & outputs](https://github.com/conda-incubator/ceps/pull/56)

## Motivation

In many recipes, people use bash- or batch commands to test for file existence. This has several downsides:

- It is not guaranteed that the file is actually part of _this_ package (could come from another dependency)
- The syntax is very fragile. Few people are well-versed in cmd.exe or bash scripting.
- The files appear in different locations on Windows vs. Unix, but these locations are somewhat well-specified (so we should make sure that the files _are_ in the right place)

This is an example of the current `xtensor` recipe:

```yaml
test:
commands:
- test -d ${PREFIX}/include/xtensor # [unix]
- test -f ${PREFIX}/include/xtensor/xarray.hpp # [unix]
- test -f ${PREFIX}/share/cmake/xtensor/xtensorConfig.cmake # [unix]
- test -f ${PREFIX}/share/cmake/xtensor/xtensorConfigVersion.cmake # [unix]
- if not exist %LIBRARY_PREFIX%\include\xtensor\xarray.hpp (exit 1) # [win]
- if not exist %LIBRARY_PREFIX%\share\cmake\xtensor\xtensorConfig.cmake (exit 1) # [win]
- if not exist %LIBRARY_PREFIX%\share\cmake\xtensor\xtensorConfigVersion.cmake (exit 1) # [win]
```

## The specification

We propose a new "test" section (following the split of testing sections in this [CEP](https://github.com/conda-incubator/ceps/pull/56)) to test for package file existence.
The test are executed on the raw package contents (without installing them). That should make them very fast to execute, as well as less brittle vs. cmd.exe / bash scripts.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does "without installing them" mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It means that the tests only require the paths.json file. The package does not need to be extracted or linked into an environment.


```yaml
package_contents:
# checks for the existence of files inside $PREFIX or %PREFIX%
files:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
files:
prefix:

Given that the rest of the categories use the "base location" as key name, this might make more sense.

- etc/libmamba/test.txt
- etc/libmamba
- etc/libmamba/*.mamba.txt # can also use globs, then _at least_ one file needs to match

# checks for the existence of `mamba/api/__init__.py` inside of the Python site-packages directory
# NOTE: the user can/should also use Python import checks
site_packages:
- mamba.api
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that we can have direct access to site_packages, but I am not sure about the Python import path syntax. How can I make sure I have a data file in my Python package, for example? I'd say we stick to normal paths here, so this would be written like this:

Suggested change
- mamba.api
- mamba/api/__init__.py

After all, we have the imports: tests anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's a good point.


# looks in $PREFIX/bin/mamba for unix and %PREFIX%\Library\bin\mamba.exe on Windows
# NOTE: the user can/should also check the `commands` and execute something like `mamba --help` to make
# sure things work fine
bin:
- mamba

# searches for `$PREFIX/lib/libmamba.so` or `$PREFIX/lib/libmamba.dylib` on Linux or macOS,
# on Windows for %PREFIX%\Library\lib\mamba.dll & %PREFIX%\Library\bin\mamba.lib
lib:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about versioned libraries? The numbered suffixes are placed in different spots of the filename in linux and macos.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check what CMake is doing (they also have some "find_library" heuristic).

I also think it would be nice if one can add the version number, e.g. libmamba.0 (and it would find either libmamba.so.0 or libmamba.0.dylib but that would require some more logic in the string parsing (or we make it more explicit).

- mamba # (look for libmamba)
- mamba_ext # (look for libmamba_ext)

# searches for `$PREFIX/include/libmamba/mamba.hpp` on unix, and
# on Windows for `%PREFIX%\Library\include\mamba.hpp`
include:
- libmamba/mamba.hpp
- if: win
then:
- libmamba/windows/include.h
- libmamba/windows/hello_world.h
```