diff --git a/cli/src/init.rs b/cli/src/init.rs index 64d1c107..dffc0294 100644 --- a/cli/src/init.rs +++ b/cli/src/init.rs @@ -624,10 +624,15 @@ pub fn generate_grammar_files( allow_update, |path| generate_file(path, SETUP_PY_TEMPLATE, language_name, &generate_opts), |path| { - let contents = fs::read_to_string(path)?; + let mut contents = fs::read_to_string(path)?; if !contents.contains("egg_info") || !contents.contains("Py_GIL_DISABLED") { eprintln!("Replacing setup.py"); generate_file(path, SETUP_PY_TEMPLATE, language_name, &generate_opts)?; + } else { + contents = contents + .replace("path\nfrom platform import system", "name as os_name, path") + .replace("system() != \"Windows\"", "os_name != \"nt\""); + write_file(path, contents)?; } Ok(()) }, diff --git a/cli/src/templates/setup.py b/cli/src/templates/setup.py index 534bd9f2..9fdc3098 100644 --- a/cli/src/templates/setup.py +++ b/cli/src/templates/setup.py @@ -1,5 +1,4 @@ -from os import path -from platform import system +from os import name as os_name, path from sysconfig import get_config_var from setuptools import Extension, find_packages, setup @@ -21,7 +20,7 @@ macros: list[tuple[str, str | None]] = [ if limited_api := not get_config_var("Py_GIL_DISABLED"): macros.append(("Py_LIMITED_API", "0x030A0000")) -if system() != "Windows": +if os_name != "nt": cflags = ["-std=c11", "-fvisibility=hidden"] else: cflags = ["/std:c11", "/utf-8"]