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

Add Python Path for Windows #533

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

GreasySlug
Copy link
Member

@GreasySlug GreasySlug commented Nov 6, 2024

Changes proposed in this PR:

  • add or fix path
    • Scripts
    • uv
    • poerty
  • fix test
    • encoding utf-8

@mtshiba

@GreasySlug GreasySlug force-pushed the fix-py-path branch 2 times, most recently from b659dfc to 019a6b6 Compare November 10, 2024 06:34
@mtshiba
Copy link
Member

mtshiba commented Nov 10, 2024

I looked into the cause of the test error, and it seems that it may not be a problem with the Python interpreter selection.
When I ran cargo test without workaround on Windows, I got the following result.

Traceback (most recent call last):
File "<string>", line 1, in <module>
File "examples/helloworld.er", line -1, in <module>
UnicodeEncodeError: 'cp932' codec can't encode character '\u03ac' in position 3: illegal multibyte sequence

I don't remember seeing this error when I wrote this test, but this output may have been obtained as a result of several improvements to make the test results readable.

\u03ac is the Greek letter ά. Indeed, this character is included in the source code. In this test, I wanted to check whether Erg can support multilingual source code, but there may be a codec problem on Windows.

In fact, the test passed when I deleted everything except alphabets and hiragana.

@GreasySlug GreasySlug changed the title [WIP] Allow Python Search Recursively Add Python Path for Windows Nov 14, 2024
@GreasySlug GreasySlug marked this pull request as ready for review November 14, 2024 01:18
@GreasySlug GreasySlug requested a review from mtshiba November 14, 2024 01:18
@@ -1,3 +1,6 @@
sys = pyimport "sys"
sys.stdout.reconfigure!(encoding:="utf-8")
Copy link
Member

Choose a reason for hiding this comment

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

It is inconvenient that multilingual support is only available if the user sets it up using sys.stdout.reconfigure!, so I think it would be better to include a process to embed this code when generating the code.
For example, Erg embeds a code in the bytecode that passes its own standard API path and loads it. Using this as a reference, it is possible to call sys.stdout.reconfigure first.

fn load_prelude_py(&mut self) {
self.emit_global_import_items(
Identifier::static_public("sys"),
vec![(
Identifier::static_public("path"),
Some(Identifier::private("#path")),
)],
);
self.emit_load_name_instr(Identifier::private("#path"));
self.emit_load_method_instr(Identifier::static_public("append"), BoundAttr);
self.emit_load_const(erg_core_path().to_str().unwrap());
self.emit_call_instr(1, BoundAttr);
self.stack_dec();
self.emit_pop_top();
let erg_std_mod = Identifier::static_public("_erg_std_prelude");
// escaping
self.emit_global_import_items(
erg_std_mod.clone(),
vec![(
Identifier::static_public("contains_operator"),
Some(Identifier::private("#contains_operator")),
)],
);
self.emit_import_all_instr(erg_std_mod);
}

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

Successfully merging this pull request may close these issues.

2 participants