### Complete MPI Variant Recipe Example (Jinja/YAML) Source: https://conda-forge.org/docs/maintainer/knowledge_base This example combines `conda_build_config.yaml` and `meta.yaml` to illustrate a comprehensive setup for managing multiple MPI variants. It includes 'nompi', 'mpich', and 'openmpi' variants, prioritizes 'nompi', and sets up `run_exports` for runtime dependency management. ```yaml # conda_build_config.yaml mpi: - nompi - mpich # [not win] - openmpi # [not win] ``` ```jinja # meta.yaml {% set name = 'pkg' %} {% set build = 0 %} # ensure mpi is defined (needed for conda-smithy recipe-lint) {% set mpi = mpi or 'nompi' %} {% if mpi == 'nompi' %} # prioritize nompi variant via build number {% set build = build + 100 %} {% endif %} build: number: {{ build }} # add build string so packages can depend on # mpi or nompi variants explicitly: # `pkg * mpi_mpich_*` for mpich # `pkg * mpi_*` for any mpi # `pkg * nompi_*` for no mpi {% if mpi != 'nompi' %} {% set mpi_prefix = "mpi_" + mpi %} {% else %} {% set mpi_prefix = "nompi" %} {% endif %} string: "{{ mpi_prefix }}_h{{ PKG_HASH }}_{{ build }}" {% if mpi != 'nompi' %} run_exports: - {{ name }} * {{ mpi_prefix }}* {% endif %} requirements: host: - {{ mpi }} # [mpi != 'nompi'] run: - {{ mpi }} # [mpi != 'nompi'] ``` -------------------------------- ### Set Up Local Development Environment with Pixi Source: https://conda-forge.org/docs/user/contributing This command sets up the local development environment for the conda-forge website using Pixi. It assumes Pixi is installed and configured, and then runs the start command to launch the development server. ```bash pixi run start ``` -------------------------------- ### Verify Miniforge Installation Source: https://conda-forge.org/docs/user/transitioning_from_defaults After installing Miniforge, this command can be run to verify the installation and check the active conda channels. It should show 'conda-forge' as the channel with the highest priority, confirming the successful switch. ```bash conda info ``` -------------------------------- ### Set Up Local Development Environment with Conda/Mamba Source: https://conda-forge.org/docs/user/contributing These commands set up the local development environment for the conda-forge website using Conda or Mamba. It involves creating an environment, activating it, installing Node.js dependencies, and starting the development server. ```bash conda env create -f ./.ci_scripts/environment.yml conda activate conda-forge-docs npm install npm run start ``` -------------------------------- ### Install Specific Compilers Package using Conda Source: https://conda-forge.org/docs/maintainer/infrastructure This command demonstrates how to install specific compiler packages, such as the C++ compiler (`cxx-compiler`) and Fortran compiler (`fortran-compiler`), for direct use in a conda environment. ```bash conda install cxx-compiler fortran-compiler ``` -------------------------------- ### Install Default Compilers Package using Conda Source: https://conda-forge.org/docs/maintainer/infrastructure This command installs a convenience package that bundles the C, C++, and Fortran compilers typically used in conda-forge build environments, along with their activation scripts, for direct use in conda environments. ```bash conda install compilers ``` -------------------------------- ### Simple Existence Testing for Packages (v0 and v1) Source: https://conda-forge.org/docs/maintainer/adding_pkgs Verifies that a package has installed the expected files in the correct locations. This method is useful when full test suites are not feasible. It provides examples for both v0 (`commands` in `test`) and v1 (`package_contents` in `tests`) recipe formats. ```yaml test: commands: - test -f $PREFIX/lib/libboost_log$SHLIB_EXT # [unix] - if not exist %LIBRARY_BIN%\boost_log.dll exit 1 # [win] - if not exist %LIBRARY_LIB%\boost_log.lib exit 1 # [win] ``` ```yaml tests: - package_contents: lib: # $PREFIX/lib/libboost_log.so on Linux # $PREFIX/lib/libboost_log.dylib on macOS # %LIBRARY_BIN%/boost_log.dll and %LIBRARY_LIB%/boost_log.lib on Windows - boost_log ``` -------------------------------- ### conda-build finalized run dependencies example Source: https://conda-forge.org/docs/how-to/basics/populate-dependencies This example shows the finalized run dependencies as output by conda-build. It lists packages and their version specifications required for the package to run. These include core libraries and system components. ```yaml run: - libstdcxx >=14 - libzlib >=1.3.1,<2.0a0 - openssl >=3.5.5,<4.0a0 - libgcc >=14 - pcre2 >=10.47,<10.48.0a0 - libssh2 >=1.11.1,<2.0a0 - __glibc >=2.17,<3.0.a0 ``` -------------------------------- ### Install Package from Conda-Forge Source: https://conda-forge.org/docs/user/transitioning_from_defaults Once the environment is configured to prioritize conda-forge, this command can be used to install any desired package. Conda will search for and install the package from the highest priority channel, which is now conda-forge. ```bash conda install my_desired_package_from_conda_forge ``` -------------------------------- ### Example Archive Feedstock Configuration Source: https://conda-forge.org/docs/maintainer/updating_pkgs An example of a YAML file used to request the archiving of a specific feedstock, 'or-datasets'. ```yaml action: archive feedstocks: - or-datasets ``` -------------------------------- ### Use Pip for Installation (v0/v1 Recipe) Source: https://conda-forge.org/docs/maintainer/adding_pkgs Illustrates how to use pip for package installation within conda-forge recipes, specifying the installation command and adding 'pip' to host requirements. ```yaml build: script: "{{ PYTHON }} -m pip install . -vv" ``` ```yaml build: script: "${{ PYTHON }} -m pip install . -vv" ``` ```yaml requirements: host: - pip ``` -------------------------------- ### C Function Prototype Example Source: https://conda-forge.org/docs/maintainer/understanding_conda_forge/compilation-concepts Demonstrates a simple C function prototype, illustrating the basic structure of a function declaration including its return type, name, and parameter types. This is a fundamental concept for defining an API. ```c void foo(int32_t a); ``` -------------------------------- ### Test Command Line Utilities Installation Source: https://conda-forge.org/docs/maintainer/adding_pkgs Verify that command-line utilities installed by a Python package are accessible and executable. This is typically done by invoking a common command like `--help` or `--version`. This snippet shows the configuration for both meta.yaml and recipe.yaml. ```yaml test: commands: - util_1 --help ``` ```yaml tests: - script: - util_1 --help ``` -------------------------------- ### Add and Commit Changes using Git Source: https://conda-forge.org/docs/tutorials/first-recipe This snippet demonstrates how to stage changes for a specific file and then commit them to the repository. It requires Git to be installed and configured. The output is a staged change ready for commit. ```git git add recipes/pylast/recipe.yaml git commit ``` ```git Add a recipe for pylast package ``` -------------------------------- ### C Function Prototype Change Example Source: https://conda-forge.org/docs/maintainer/understanding_conda_forge/compilation-concepts Illustrates a change in a C function prototype, specifically widening a parameter type from int32_t to int64_t. This example highlights a potential ABI breakage scenario where a previously compiled program might not be compatible with the updated library. ```c void foo(int64_t a); ``` -------------------------------- ### CMake Build Commands for build.sh (macOS/Linux) Source: https://conda-forge.org/docs/maintainer/knowledge_base These are example CMake commands for use in a `build.sh` script on macOS or Linux. They demonstrate configuring the build with Python 3 and then performing a release build. ```bash cmake CMakeLists.txt -DPython3_EXECUTABLE="$PYTHON" cmake --build . --config Release ``` -------------------------------- ### Faster Local Debugging with Mambabuild Source: https://conda-forge.org/docs/maintainer/maintainer_faq Demonstrates how to speed up local debugging of recipes using mambabuild. This involves installing the 'boa' package and then using 'mambabuild' instead of 'conda-build' for faster solving and clearer error messages. ```bash conda install boa -c conda-forge conda mambabuild myrecipe ``` -------------------------------- ### Meson Cross-File Configuration for Cross-Compilation Source: https://conda-forge.org/docs/how-to/advanced/cross-compilation Configures Meson for cross-compilation by creating a local cross-file. This example sets paths for binaries like 'glib-mkenums' and specifies properties like 'longdouble_format'. ```bash if [[ "${CONDA_BUILD_CROSS_COMPILATION:-}" == 1 && "${CMAKE_CROSSCOMPILING_EMULATOR:-}" == "" ]]; then cat > local-cross-file.txt <<-EOF [binaries] glib-mkenums = '${BUILD_PREFIX}/bin/glib-mkenums' [properties] longdouble_format = 'IEEE_DOUBLE_LE' EOF MESON_ARGS+=" --cross-file ${PWD}/local-cross-file.txt" fi ``` -------------------------------- ### Recipe Section Order and Build Configuration Source: https://conda-forge.org/docs/maintainer/guidelines Specifies the recommended order for sections within a conda recipe and provides examples for configuring the build section, including skipping builds for specific platforms. ```yaml package: name: "{{ name }}" version: "{{ version }}" source: url: "https://example.com/{{ name }}-{{ version }}.tar.gz" sha256: "a1b2c3d4e5f6..." build: number: 0 skip: true # [win] requirements: host: - python run: - python test: imports: - {{ name }} about: home: "https://example.com/" license: "MIT" summary: "A short summary of the package." extra: recipe-maintainers: - maintainer1 - maintainer2 ``` -------------------------------- ### Specifying Future MSVC Compiler Versions Source: https://conda-forge.org/docs/maintainer/knowledge_base This example shows how to specify future MSVC compiler versions (e.g., vs2026) in the `conda_build_config.yaml` file to opt into newer compilers for C++23 support and beyond. ```yaml # note: future VS version is speculative! c_compiler: # [win] - vs2026 # [win] cxx_compiler: # [win] - vs2026 # [win] ``` -------------------------------- ### Setting up abi3 Extensions in meta.yaml Source: https://conda-forge.org/docs/maintainer/knowledge_base This example illustrates the necessary configurations within a `meta.yaml` file to build Python packages using CPython's stable `abi3` mode. It includes conditional settings for build, requirements, and testing sections. ```yaml # Example meta.yaml snippet for abi3 extensions build: # ... other build configurations # Add conditionals for is_abi3 if needed requirements: host: - python # ... other host requirements run: # ... run requirements test: # ... test configurations # Add tests related to abi3 compatibility if necessary ``` -------------------------------- ### Build Multiple Go Binaries Source: https://conda-forge.org/docs/maintainer/example_recipes/go Demonstrates how to build multiple binaries for a Go package. This involves running `go-licenses` and `go build` separately for each binary, potentially specifying a subdirectory if the Go source code is organized that way. ```bash # For the first binary: go-licenses save ./cmd/example-package --save-path ../library_licenses go build -v -o ${PREFIX}/bin/example-package -ldflags="-s -w" ./cmd/example-package # For subsequent binaries, repeat the above commands with appropriate paths and binary names. ``` -------------------------------- ### Clean Conda Installation Source: https://conda-forge.org/docs/user/transitioning_from_defaults These commands help clean up an existing conda installation by removing unused files and packages. This can reduce the size of backups and free up disk space. The `conda build purge` command may fail if `conda-build` is not installed, which is expected. ```bash # The conda build purge command may fail if you don't have conda-build installed. # this is expected conda build purge conda clean --all ``` -------------------------------- ### Declare Dependencies in setup.py Source: https://conda-forge.org/docs/how-to/basics/populate-dependencies This snippet demonstrates declaring runtime dependencies, optional extra dependencies, test dependencies, and Python version constraints within a setup.py file using setuptools. It highlights the use of keyword arguments to the setup() function. ```python setup( install_requires=[ "Twisted>=17.5", ], extras_require={ "autoscaler": [ "txzookeeper", ], }, tests_require=[ "mock", ], python_requires=">=3.8", ... ) ``` -------------------------------- ### Check Conda Package Channel Origins Source: https://conda-forge.org/docs/user/transitioning_from_defaults This command lists all installed conda packages along with their channel URLs. It helps identify packages installed from Anaconda's default channel versus conda-forge, which is crucial for ensuring a consistent environment. ```shell conda list --show-channel-urls ``` -------------------------------- ### MinGW-based Compiler Stack for Windows with compiler() Macro Source: https://conda-forge.org/docs/maintainer/infrastructure This snippet illustrates how to use the alternative MinGW-based compiler stack on Windows for C, C++, and Fortran. It requires specifying `m2w64_c`, `m2w64_cxx`, or `m2w64_fortran` in the `compiler(...)` macro and also using `stdlib('m2w64_c')`. ```yaml m2w64_c m2w64_cxx m2w64_fortran ``` -------------------------------- ### Add conda-forge Channel in Anaconda Navigator Source: https://conda-forge.org/docs/user/introduction These steps guide you through adding the conda-forge channel to Anaconda Navigator. This allows you to easily view and install conda-forge packages directly from the graphical interface. ```bash anaconda-navigator # Then navigate to Environments -> Channels -> Add and enter: https://conda.anaconda.org/conda-forge/ ``` -------------------------------- ### Using clang and clang-cl on Windows with compiler() Macro Source: https://conda-forge.org/docs/maintainer/infrastructure This snippet demonstrates how to specify the clang and clang-cl frontends for C and C++ compilers on Windows using the `compiler()` macro. It allows selection between GCC argument syntax (`clang`) and MSVC argument syntax (`clang-cl`). ```yaml {{ compiler('clang') }} {{ compiler('clangxx') }} ``` -------------------------------- ### Create Conda Environment with Conda-Forge Priority Source: https://conda-forge.org/docs/user/transitioning_from_defaults This command creates a new conda environment named 'conda-forge-env' and installs Python using only packages from the 'conda-forge' channel. It ensures that 'conda-forge' has priority over all other channels for this environment. ```bash conda create --name conda-forge-env python=3 --channel conda-forge --override-channels ``` -------------------------------- ### Configure Conda Environment to Prioritize Conda-Forge Source: https://conda-forge.org/docs/user/transitioning_from_defaults These commands activate a conda environment, add 'conda-forge' as a channel, and set the channel priority to 'strict'. This ensures that packages are preferentially installed from 'conda-forge'. The optional command to remove 'defaults' can be used to further enforce this. ```bash conda activate conda-forge-env conda config --env --add channels conda-forge # optional: # conda config --env --remove channels defaults conda config --env --set channel_priority strict ``` -------------------------------- ### Declare Dependencies in setup.cfg Source: https://conda-forge.org/docs/how-to/basics/populate-dependencies This snippet shows how to declare runtime dependencies, optional extra dependencies, and Python version constraints using the setup.cfg file format with setuptools. It utilizes the [options] and [options.extras_require] sections. ```ini [options] install_requires = numpy >= 1.12.0 ruamel.yaml >= 0.15.34 python_requires = >=3.8 [options.extras_require] hdf5 = h5py pandas = pandas ``` -------------------------------- ### Configure Conda Build Path on Windows Azure Agent in conda-forge.yml Source: https://conda-forge.org/docs/maintainer/conda_forge_yml This example shows how to specify custom paths for conda build artifacts and Miniforge installation on Windows Azure agents using `conda-forge.yml`. This can be useful for managing build output and tool locations, potentially impacting IO performance. ```yaml azure: settings_win: variables: CONDA_BLD_PATH: "C:\\bld" MINIFORGE_HOME: "C:\\Miniforge" ``` -------------------------------- ### Configure Chocolatey Package Installation (Windows) Source: https://conda-forge.org/docs/maintainer/conda_forge_yml Allows conda-smithy to install Chocolatey packages on Windows. Accepts a list of package names and optional parameters. Currently implemented for Azure Pipelines, running 'choco install {entry} -fdv -y --debug'. ```yaml choco: - nvidia-display-driver - cuda --version=11.0.3 ``` -------------------------------- ### Example meta.yaml for conda-smithy Source: https://conda-forge.org/docs/user/ci-skeleton This `meta.yaml` file defines the build and runtime specifications for a conda package. It includes package metadata, source information (using git URL), build configurations (version, number, string, script), dependencies (build, host, run), and testing requirements (imports, commands, requires, source_files). ```yaml {% set name = "myproj" %} {% set version = environ.get('GIT_DESCRIBE_TAG', 'untagged')|string|replace('-','_') %} package: name: {{ name|lower }} version: {{ version }} source: git_url: {{ environ.get('FEEDSTOCK_ROOT', '..') }} build: # Uncomment the following line if the package is pure Python and the recipe # is exactly the same for all platforms. It is okay if the dependencies are # not built for all platforms/versions, although selectors are still not allowed. # See https://conda-forge.org/docs/maintainer/knowledge_base.html#noarch-python # for more details. # noarch: python number: {{ environ.get('GIT_DESCRIBE_NUMBER', '0') }} string: {{ [build_number, ('h' + PKG_HASH), environ.get('GIT_DESCRIBE_HASH', '')]|join('_') }} # If the installation is complex, or different between Unix and Windows, # use separate bld.bat and build.sh files instead of this key. By default, # the package will be built for the Python versions supported by conda-forge # and for all major OSs. Add the line "skip: True # [py<35]" (for example) # to limit to Python 3.5 and newer, or "skip: True # [not win]" to limit # to Windows. script: "{{ PYTHON }} -m pip install . -vv" requirements: build: # If your project compiles code (such as a C extension) then add the required # compilers as separate entries here. Compilers are named 'c', 'cxx' and 'fortran'. - {{ compiler('c') }} host: - python - pip run: - python test: # Some packages might need a `test/commands` key to check CLI. # List all the packages/modules that `run_test.py` imports. imports: - myproj # Run your test commands here commands: - myproj --help - pytest # declare any test-only requirements here requires: - pytest # copy over any needed test files here source_files: - tests/ # Uncomment and fill in myproj metadata #about: # home: https://github.com/conda-forge/conda-smithy # license: BSD-3-Clause # license_family: BSD # license_file: LICENSE # Uncomment the following if this will be on a forge # Remove these lines if this is only be used for CI #extra: # recipe-maintainers: ``` -------------------------------- ### Generate Initial Recipe using Grayskull Source: https://conda-forge.org/docs/tutorials/first-recipe This command generates an initial conda recipe for the 'pylast' package (version 7.0.1) from PyPI using grayskull. It creates the recipe in v1 format within a 'recipes/pylast' subdirectory and adheres to strict conda-forge rules. A new git branch 'pylast' is created beforehand to isolate this work. ```bash git checkout -b pylast grayskull pypi --use-v1-format --strict-conda-forge -o recipes pylast==7.0.1 ``` -------------------------------- ### Install External MPI Dummy Packages with Conda Source: https://conda-forge.org/docs/user/tipsandtricks Installs dummy packages for mpich or openmpi from a specific conda-forge label. This allows conda to resolve MPI dependencies correctly on HPC systems without installing conda-forge's MPI binaries. ```bash $ conda install -c conda-forge/label/mpi-external mpich $ conda install -c conda-forge/label/mpi-external openmpi ``` -------------------------------- ### Wine Debugging Example Source: https://conda-forge.org/docs/maintainer/knowledge_base An example of an error message encountered when running a program under Wine, indicating an unimplemented function call. This can help in debugging compatibility issues. ```text wine: Call from 00006FFFFFF999EA to unimplemented function libblas.dll.cdotc_, aborting ``` -------------------------------- ### pyproject.toml for Build and Runtime Dependencies Source: https://conda-forge.org/docs/how-to/basics/populate-dependencies This example shows a pyproject.toml file declaring build system requirements, project runtime dependencies, optional dependencies ('extras'), and dependency groups for testing. It also specifies the Python version constraint. ```toml [build-system] requires = ["setuptools", "wheel"] build-backend = "setuptools.build_meta" [project] dependencies = ["lxml", "beautifulsoup4"] requires-python = ">=3.10" [project.optional-dependencies] cache = ["redis>=3.0.0"] [dependency-groups] test = ["pytest>7"] ``` -------------------------------- ### Add Conda-Forge as a High-Priority Channel Source: https://conda-forge.org/docs/user/introduction This command adds the conda-forge channel to your conda configuration, prioritizing it for package installations. This ensures that packages from conda-forge are considered first when installing new software. ```bash conda config --add channels conda-forge ``` -------------------------------- ### Jinja Templating for Versioning in Recipes Source: https://conda-forge.org/docs/maintainer/guidelines Demonstrates the use of Jinja templating to define and use package versions within a conda recipe, promoting maintainability and consistency. ```yaml {% set version = "0.10.1" %} package: name: "my-package" version: "{{ version }}" source: url: "https://example.com/my-package-{{ version }}.tar.gz" # ... rest of the recipe ``` -------------------------------- ### Run Pytest Tests for Python Packages Source: https://conda-forge.org/docs/maintainer/adding_pkgs Configure conda-build to run pytest for installed Python packages. This requires pytest to be listed as a dependency and specifies the command to execute the tests. Assumes tests are discoverable by pytest when the package is installed. ```yaml test: requires: - pytest commands: - pytest --pyargs package_name ``` ```yaml tests: - requirements: run: - pytest script: - pytest --pyargs package_name ```