Code Monkey home page Code Monkey logo

wolfram-app-discovery-rs's Introduction

wolfram-app-discovery

Crates.io License Documentation

About

Find local installations of the Wolfram Language and Wolfram applications.

This crate provides:

Examples

Using the API

Locate the default Wolfram Language installation on this computer:

use wolfram_app_discovery::WolframApp;

let app = WolframApp::try_default()
    .expect("unable to locate any Wolfram applications");

// Prints a path like:
//   $InstallationDirectory: /Applications/Mathematica.app/Contents/
println!("$InstallationDirectory: {}", app.installation_directory().display());

See also: WolframApp::try_default()

Using the command-line tool

Locate the default Wolfram Language installation on this computer:

$ wolfram-app-discovery default
App type:                           Mathematica
Wolfram Language version:           13.1.0
Application directory:              /Applications/Wolfram/Mathematica.app

See CommandLineHelp.md for more information on the wolfram-app-discovery command-line interface.

Scenario: Building a LibraryLink library

Suppose you have the following C program that provides a function via the Wolfram LibraryLink interface, which you would like to compile and call from Wolfram Language:

#include "WolframLibrary.h"

/* Adds one to the input, returning the result  */
DLLEXPORT int increment(
  WolframLibraryData libData,
  mint argc,
  MArgument *args,
  MArgument result
) {
    mint arg = MArgument_getInteger(args[0]);
    MArgument_setInteger(result, arg + 1);
    return LIBRARY_NO_ERROR;
}

To successfully compile this program, a C compiler will need to be able to find the included "WolframLibrary.h" header file. We can use wolfram-app-discovery to get the path to the appropriate directory:

# Get the LibraryLink includes directory
$ export WOLFRAM_C_INCLUDES=`wolfram-app-discovery default --raw-value library-link-c-includes-directory`

And then pass that value to a C compiler:

# Invoke the C compiler
$ clang increment.c -I$WOLFRAM_C_INCLUDES -shared -o libincrement

The resulting compiled library can be loaded into Wolfram Language using LibraryFunctionLoad and then called:

func = LibraryFunctionLoad["~/libincrement", "increment", {Integer}, Integer];

func[5]  (* Returns 6 *)

Installing wolfram-app-discovery

Download wolfram-app-discovery releases.

Precompiled binaries for the wolfram-app-discovery command-line tool are available for all major platforms from the GitHub Releases page.

Using cargo

wolfram-app-discovery can be installed using cargo (the Rust package manager) by executing:

$ cargo install --features=cli wolfram-app-discovery

This will install the latest version of wolfram-app-discovery from crates.io.

Configuration

The default method used to locate a Wolfram Language installation (WolframApp::try_default()) will use the following steps to attempt to locate any local installations, returning the first one found:

  1. The location specified by the WOLFRAM_APP_DIRECTORY environment variable, if set.
  2. If wolframscript is on PATH, use it to locate the system installation.
  3. Check in the operating system applications directory.

Configuration example

Specify a particular Wolfram Language installation to use (on macOS):

$ export WOLFRAM_APP_DIRECTORY="/Applications/Mathematica.app"

This environment variable is checked by both the wolfram-app-discovery library and command-line executable.

License

Licensed under either of

at your option.

Wolfram application licenses

Wolfram applications are covered by different licensing terms than wolfram-app-discovery.

Wolfram Engine Community Edition is a free distribution of the Wolfram Language, licensed for personal and non-production use cases.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

See CONTRIBUTING.md for more information.

See Development.md for instructions on how to perform common development tasks when contributing to this project.

See Maintenance.md for instructions on how to maintain this project.

wolfram-app-discovery-rs's People

Contributors

connorgray avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

wolfram-app-discovery-rs's Issues

Linux: could not find installation

I tried using this on our local cluster (Linux), which provides several different Mathematica versions via modules. I tried it with Mathematica 12.3 (which happened to be the most recent version available).

  1. It was initially unable to find the installation:

    $ wolfram-app-discovery default
    warning: error looking for Wolfram apps in '/usr/local/Wolfram': No such file or directory (os error 2)
    warning: error looking for Wolfram apps in '/opt/Wolfram': No such file or directory (os error 2)
    Error: Error(Undiscoverable { resource: "default Wolfram Language installation", environment_variable:    Some("WOLFRAM_APP_DIRECTORY") })
    

    this is despite the binary directory being in the PATH. For example:

    WolframKernel -noprompt -run "WriteString[\$Output,\$InstallationDirectory];Exit[]"
    

    gives me the correct directory.

  2. I then set the WOLFRAM_APP_DIRECTORY environment variable. This then gave the following error:

    $ wolfram-app-discovery default
    Error: Error(Other("Unable to determine Wolfram app type from LICENSE.txt: first line was: \"Wolfram Mathematica License Agreement\""))
    

Linux: WolframApp::try_default() fails even though discover() is capable of finding WolframApp instances

OS: Pop!_OS 22.04
Wolfram products: Mathematica 13.1 and 12.0

Issue:
WolframApp::try_default() returns an Error on Linux and Other operating systems when try_wolframscript_installation_directory() is successful because WolframApp::from_installation_directory(dir) errors for these system types. This is incorrect behavior, since wolframscript is discoverable on $PATH thus wolfram_app_discovery::discover_with_filter should be given a chance to locate it.
I am working on a Pull Request that will add minimal extra logic within try_default() to solve the problem.

problem locating wolfram installation on Linux

Hi,
the program has trouble locating Wolfram Language installation on Linux. Locating Wolfram application using wolfram_app_discovery::WolframApp leads to an error

thread 'main' panicked at 'unable to locate any Wolfram applications: Error(UnsupportedPlatform { operation: "WolframApp::from_installation_directory()" })' 

According to the section Configuration it should be sufficient to add the correct path to .bashrc, such as
export WOLFRAM_APP_DIRECTORY="/usr/local/Wolfram/Mathematica/13.0/Executables/"
this also leads to the error above.

  • Installing wolframscript does not fix the problem,
  • using Arch Linux, Mathematica 13.0, rustc 1.65.0, wolfram-app-discovery = "0.3.0"

For more details, the result from RUST_BACKTRACE=1:

thread 'main' panicked at 'unable to locate any Wolfram applications: Error(UnsupportedPlatform { operation: "WolframApp::from_app_directory()" })', src/main.rs:8:6
stack backtrace:
   0: rust_begin_unwind
             at /rustc/1.65.0/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/1.65.0/library/core/src/panicking.rs:142:14
   2: core::result::unwrap_failed
             at /rustc/1.65.0/library/core/src/result.rs:1785:5
   3: core::result::Result<T,E>::expect
             at /rustc/1.65.0/library/core/src/result.rs:1064:23
   4: tutorial::main
             at ./src/main.rs:7:15
   5: core::ops::function::FnOnce::call_once
             at /rustc/1.65.0/library/core/src/ops/function.rs:248:5
          

Thanks for any advice on fixing this issue.

MacOS: Wolfram Engine homebrew installation triggers wolframscript exited with non-success status code

Using Wolfram Engine installed by Homebrew (brew install --cask wolfram-engine), I get the following error:

thread 'main' panicked at 'wolframscript exited with non-success status code: exit status: 255', src/lib.rs:1218:9
stack backtrace:
   0:        0x100d01ec6 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h0a1c410dd2eebc30
   1:        0x100d1a1ba - core::fmt::write::hfa389e524187f2c6
   2:        0x100cff2fc - std::io::Write::write_fmt::h366bfde824bc90c5
   3:        0x100d01caa - std::sys_common::backtrace::print::hc90b083c930997af
   4:        0x100d03313 - std::panicking::default_hook::{{closure}}::h75efc5c6aebec0e0
   5:        0x100d03068 - std::panicking::default_hook::hc8ee2f0ee4fbe744
   6:        0x100d03a4f - std::panicking::rust_panic_with_hook::h479ead1480e59d8d
   7:        0x100d03814 - std::panicking::begin_panic_handler::{{closure}}::h69ffc77690b7f126
   8:        0x100d02368 - std::sys_common::backtrace::__rust_end_short_backtrace::h7fbeef7420a96564
   9:        0x100d034dd - _rust_begin_unwind
  10:        0x100d23283 - core::panicking::panic_fmt::h9b5d807e24bcaaed
  11:        0x100c8e6a7 - wolfram_app_discovery::WolframApp::try_default_with_filter::hef1227a40160ade8
  12:        0x100c7169f - wolfram_app_discovery::main::haa4810c74479aee4
  13:        0x100c6d72b - std::sys_common::backtrace::__rust_begin_short_backtrace::hb68d3b8234a767b2
  14:        0x100c7ad4b - std::rt::lang_start::{{closure}}::h6b6f4c676d08f646
  15:        0x100cfa680 - std::rt::lang_start_internal::h72dc55d09e0a2397
  16:        0x100c76e3c - _main

https://github.com/JuliaInterop/MathLink.jl/actions/runs/4635530121/jobs/8202662463#step:7:89

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.