Git Product home page Git Product logo

Comments (9)

MarcosNicolau avatar MarcosNicolau commented on July 30, 2024

Hi @LEMettler,

I think I know what is going wrong. When setting a custom path, the quotes are being added to the path. when they should not. Instead of being /usr/bin/wolframscript is doing "/usr/bin/wolframscript".

Since this should be an easy fix I'll push the changes asap and I'll let you know!

For the time being, I guess you could just copy the generated code and run it yourself.

from obsidian-mathematica-plot.

MarcosNicolau avatar MarcosNicolau commented on July 30, 2024

Ok, I've just tested and it is clearly not that, could you try to run this command /bin/sh -c 'wolframscript' on your terminal. Also, maybe you could try with /bin/wolframscript and see if that works.

from obsidian-mathematica-plot.

LEMettler avatar LEMettler commented on July 30, 2024

Hi @MarcosNicolau,

thank you for your quick reply.
Both /bin/sh -c 'wolframscript' and /bin/wolframscript both launch wolframscript in terminal. But both produce the same type of error with the plugin.

from obsidian-mathematica-plot.

MarcosNicolau avatar MarcosNicolau commented on July 30, 2024

It probably has to do with the PATH env var not being loaded. Since you told you were able to use the plugin via git clone, would you mind replacing the getBase64Plot function located in this file in your machine for:

export const getBase64Plot = async (
	plot: string,
	{ useCloud, wolframScriptPath }: GetBase64PlotSettings
): Promise<{ error: string; base64: string }> => {
	try {
		const { stdout, stderr } = await promisify(exec)(
			`${
				wolframScriptPath
					? '"' + wolframScriptPath + '"'
					: "wolframscript"
			} ${
				useCloud ? "--cloud" : ""
			}  --code "ExportString[${plot}, {\\"Base64\\", \\"PNG\\"}]"`,
			{
				// Here we make sure that the path gets loaded
				env: { PATH: process.env.PATH },
			}
		);
		if (stderr) return { error: stderr, base64: "" };
		// If it is not a valid image, it means there was a mistake in the wolfram syntax
		// So we return the base64 to debug the err, since it tells you whats wrong.
		if (!isValidBase64(stdout)) return { error: stdout, base64: "" };
		return { error: "", base64: stdout };
	} catch (err) {
		return { error: err, base64: "" };
	}
};

After that, you'd have to run npm run build and before that npm install. If that works for you, I'll push these changes asap.

Sorry that I am making you do this, but I have no way to test it on my end since it works on my machine 😁.

from obsidian-mathematica-plot.

LEMettler avatar LEMettler commented on July 30, 2024

No worries. I appreciate your help :)

I did as you instructed. Same error.
npm run build returned

> [email protected] build
> tsc -noEmit -skipLibCheck && node esbuild.config.mjs production

I never worked with js/ts. Is the second line is the expected output?

from obsidian-mathematica-plot.

MarcosNicolau avatar MarcosNicolau commented on July 30, 2024

Yes, the output is ok. If it's still not working, it is because exec creates a new process and a new shell, but for some reason, it is not creating the PATH env you have on your config files. It probably has to do with electron doing weird stuff or your Obsidian installation (did you install it via flatpak? If so it won't invoke your app PATH for security reasons I believe).

Could you try this version please:

export const getBase64Plot = async (
	plot: string,
	{ useCloud, wolframScriptPath }: GetBase64PlotSettings
): Promise<{ error: string; base64: string }> => {
	try {
		console.log(process.env.PATH);
		const { stdout, stderr } = await promisify(exec)(
			`"wolframscript" ${
				useCloud ? "--cloud" : ""
			}  --code "ExportString[${plot}, {\\"Base64\\", \\"PNG\\"}]"`,
			{ env: { PATH: "/usr/bin/" } }
		);
		if (stderr) return { error: stderr, base64: "" };
		// If it is not a valid image, it means there was a mistake in the wolfram syntax
		// So we return the base64 to debug the err, since it tells you whats wrong.
		if (!isValidBase64(stdout)) return { error: stdout, base64: "" };
		return { error: "", base64: stdout };
	} catch (err) {
		return { error: err, base64: "" };
	}
};

As you probably noticed, there is a console log that prints the PATH env, could you tell me the output, please? If it is empty, that is why the exec does not have the PATH defined, coz it inherits the current process env variables.

PD: sorry for the delayed response! 😁

from obsidian-mathematica-plot.

LEMettler avatar LEMettler commented on July 30, 2024

I got it to work!

Solution: switching from flatpak to a .deb obsidian installation.

Before, I tested the console output of the PATH env. It was not empty, but i can confirm that it did not match my defined $PATH. Only think is that I forgot to copy it before deleting obsidian. 😆

Anyway, thank you very much for your help. Have a great day!

from obsidian-mathematica-plot.

MarcosNicolau avatar MarcosNicolau commented on July 30, 2024

Excellent!!! Glad you could solve the issue! I'll make sure to make it work on flatpak for the next release!! Thank you for opening the issue and helping with the bugs!! 😃

from obsidian-mathematica-plot.

MarcosNicolau avatar MarcosNicolau commented on July 30, 2024

#4

from obsidian-mathematica-plot.

Related Issues (4)

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.