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

[Feature Request] Proposal of supporting matplotlib-type preview for other Python tools like Pipenv #332

Closed
Take-Me1010 opened this issue Oct 14, 2023 · 2 comments
Assignees

Comments

@Take-Me1010
Copy link
Contributor

Hello, I always use MPE when writing markdonws in VSCode. Thank you for your great tools.

The problem is that when using Pipenv, the matplotlib option in code-chunk is ignored.

Pipenv is one of the most popular virtualenvs tools in Python.
We run Python code in the vertualenv like pipenv run python $input_file.
So the code-chunk format is python {cmd="pipenv" args=["run", "python", "-u", "$input_file"] matplotlib}.
However, the option matplotlib is ignored.

After reading this repository codes, I found that the matplotlib option is valid only when the cmd = "python".
The easiest solution is to change the conditions for detemining matplotlib preview as follows:

// before: https://github.com/shd101wyy/crossnote/blob/402d89ee329d1c281e8b39905bef0a101c67a755/src/code-chunk/code-chunk.ts#L89
if (cmd.match(/python/) &&
            (normalizedAttributes["matplotlib"] || normalizedAttributes["mpl"])) {
    // ...
}

// after
if ((cmd.match(/python/) || cmd.match(/pipenv/)) &&
            (normalizedAttributes["matplotlib"] || normalizedAttributes["mpl"])) {
    // ...
}
// before https://github.com/shd101wyy/crossnote/blob/402d89ee329d1c281e8b39905bef0a101c67a755/src/render-enhancers/fenced-code-chunks.ts#L244
else if (cmd.match(/python/) &&
                (normalizedAttributes["matplotlib"] || normalizedAttributes["mpl"])) {
                outputFormat = "markdown";
            }

// after
            else if ((cmd.match(/python/) || cmd.match(/pipenv/)) &&
                (normalizedAttributes["matplotlib"] || normalizedAttributes["mpl"])) {
                outputFormat = "markdown";
            }

The change I proposed above is not ideal solution, because additional condition change will be required in order to support other virtualenv tools.
Another idea is to remove cmd.match(/python/) condition.
In typical cases, matplotlib option will be used by only Python users and I don't think the condition is neccesarry.

Additional context
Before v0.7, I modified the js local code directly and used it.
However in recent update JavaScript code is minified, which made me submit this issue lol

@shd101wyy
Copy link
Owner

Hi there. Yes, we can remove cmd.match(/python/). Could you please help submit a pr for that? Thanks!

@Take-Me1010
Copy link
Contributor Author

Thank you for your reply:)
OK, I will make a PR as soon as possible!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants