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

Issue with Accented Characters in Script Paths Generated by [project.scripts] on Windows 11 (PT-BR) #10193

Open
Jojojmo opened this issue Feb 17, 2025 · 1 comment
Labels
kind/bug Something isn't working as expected status/triage This issue needs to be triaged

Comments

@Jojojmo
Copy link

Jojojmo commented Feb 17, 2025

Description

Description:
When using Poetry on Windows 11 in Portuguese, the generated .cmd files for scripts defined in [project.scripts] contain paths with accented characters that are incorrectly encoded. As a result, when executing the command, the system is unable to locate the specified path.

Steps to Reproduce:

  1. Project Structure:

    C:.
    │   .venv
    │   poetry.lock
    │   pyproject.toml
    │   README.md
    │
    ├───example
    │       cli.py
    │       __init__.py
    │
    └───tests
            __init__.py
    
  2. Contents of example/cli.py:

    from typer import Typer
    
    app = Typer()
    
    @app.command(name="hello")
    def Hello(nome: str):
        print(f"Hello, {nome}")
    
    if __name__ == '__main__':
        app()
  3. Contents of pyproject.toml:

    [project]
    name = "example"
    version = "0.1.0"
    description = ""
    authors = [
        {name = "foo", email = "[email protected]"}
    ]
    readme = "README.md"
    requires-python = ">=3.12"
    dependencies = [
        "typer"
    ]
    
    [project.scripts]
    say-hello = "example.cli:app"
    
    [build-system]
    requires = ["poetry-core>=2.0.0,<3.0.0"]
    build-backend = "poetry.core.masonry.api"
  4. Execution:
    Activate the virtual environment and run:

    say-hello "Word"

Expected Result:
The command say-hello "Word" should invoke the defined script, displaying the message Hello, Word or the corresponding behavior.

Observed Result:
The command fails with the following error message:

O sistema não pode encontrar o caminho especificado.

Translate:

The system cannot find the specified path.

Upon inspecting the file .venv\Scripts\say-hello.cmd (after removing the @echo off to view the commands), the content is as follows:

"C:\Users\jmoni\OneDrive\├ürea de Trabalho\scripts\clis-pyproject\example\.venv\Scripts\python.exe" "C:\Users\jmoni\OneDrive\Área de Trabalho\scripts\clis-pyproject\example\.venv\Scripts\\say-hello"

It can be observed that the folder Área de Trabalho appears as ├ürea de Trabalho, indicating an encoding issue with accented characters.

Additional Notes:

  • The problem seems to be related to how Poetry generates the .cmd files, not correctly handling the encoding of special characters present in the paths.
  • This error occurs specifically in environments with the Portuguese locale (Windows 11 PT-BR).

Workarounds

To work around the issue with locating the .cmd executable due to incorrect encoding of accented characters on Windows, you can modify the file .venv\Scripts\say-hello.cmd by adding the following line at the beginning of the file:

chcp 65001 >nul

This line changes the code page. Although this solution works for this specific case, it may not be suitable as a universal fix for all scenarios.

Poetry Installation Method

pipx

Operating System

Windows 11

Poetry Version

2.0.1

Poetry Configuration

cache-dir = "C:\\Users\\jmoni\\AppData\\Local\\pypoetry\\Cache"
installer.max-workers = null
installer.no-binary = null
installer.only-binary = null
installer.parallel = true
installer.re-resolve = true
keyring.enabled = true
requests.max-retries = 0
solver.lazy-wheel = true
system-git-client = false
virtualenvs.create = true
virtualenvs.in-project = true
virtualenvs.options.always-copy = false
virtualenvs.options.no-pip = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = "{cache-dir}\\virtualenvs"  # C:\Users\jmoni\AppData\Local\pypoetry\Cache\virtualenvs
virtualenvs.prompt = "{project_name}-py{python_version}"
virtualenvs.use-poetry-python = false

Python Sysconfig

sysconfig.log
Paste the output of 'python -m sysconfig', over this line.

Example pyproject.toml

[project]
name = "example"
version = "0.1.0"
description = ""
authors = [
    {name = "foo",email = "[email protected]"}
]
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
    "typer"
]


[project.scripts]
say-hello = "example.cli:app"


[build-system]
requires = ["poetry-core>=2.0.0,<3.0.0"]
build-backend = "poetry.core.masonry.api"

Poetry Runtime Logs

poetry-runtime.log poetry -vvv install
Loading configuration file C:\Users\jmoni\AppData\Roaming\pypoetry\config.toml
Trying to detect current active python executable as specified in the config.
Found: C:\Users\jmoni\OneDrive\Área de Trabalho\scripts\clis-pyproject\example\.venv\Scripts\python.EXE
Using virtualenv: C:\Users\jmoni\OneDrive\Área de Trabalho\scripts\clis-pyproject\example\.venv
Installing dependencies from lock file

Finding the necessary packages for the current system

Package operations: 0 installs, 0 updates, 0 removals, 9 skipped

- Installing click (8.1.8): Pending...
- Installing click (8.1.8): Skipped for the following reason: Already installed                                                                                                                                                
- Installing colorama (0.4.6): Pending...                                                                                                                                                                                      
- Installing colorama (0.4.6): Skipped for the following reason: Already installed                                                                                                                                             
- Installing markdown-it-py (3.0.0): Pending...                                                                                                                                                                                
- Installing markdown-it-py (3.0.0): Skipped for the following reason: Already installed                                                                                                                                       
- Installing mdurl (0.1.2): Pending...                                                                                                                                                                                         
- Installing mdurl (0.1.2): Skipped for the following reason: Already installed                                                                                                                                                
- Installing rich (13.9.4): Pending...                                                                                                                                                                                         
- Installing rich (13.9.4): Skipped for the following reason: Already installed                                                                                                                                                
- Installing shellingham (1.5.4): Pending...                                                                                                                                                                                   
- Installing shellingham (1.5.4): Skipped for the following reason: Already installed                                                                                                                                          
- Installing typer (0.15.1): Pending...                                                                                                                                                                                        
- Installing typer (0.15.1): Skipped for the following reason: Already installed                                                                                                                                               
- Installing pygments (2.19.1): Pending...
- Installing pygments (2.19.1): Skipped for the following reason: Already installed                                                                                                                                            
- Installing typing-extensions (4.12.2): Pending...                                                                                                                                                                            
- Installing typing-extensions (4.12.2): Skipped for the following reason: Already installed

Installing the current project: example (0.1.0)
- Building package example in editable mode
- Removed example-0.1.0.dist-info directory from C:\Users\jmoni\OneDrive\Área de Trabalho\scripts\clis-pyproject\example\.venv\Lib\site-packages
- Adding example.pth to C:\Users\jmoni\OneDrive\Área de Trabalho\scripts\clis-pyproject\example\.venv\Lib\site-packages for C:\Users\jmoni\OneDrive\Área de Trabalho\scripts\clis-pyproject\example
- Adding the say-hello script to C:\Users\jmoni\OneDrive\Área de Trabalho\scripts\clis-pyproject\example\.venv\Scripts
- Adding the say-hello.cmd script wrapper to C:\Users\jmoni\OneDrive\Área de Trabalho\scripts\clis-pyproject\example\.venv\Scripts
- Adding the example-0.1.0.dist-info directory to C:\Users\jmoni\OneDrive\Área de Trabalho\scripts\clis-pyproject\example\.venv\Lib\site-packages
@Jojojmo Jojojmo added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Feb 17, 2025
@dimbleby
Copy link
Contributor

code is here if you want to figure out a fix and submit a pull request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working as expected status/triage This issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

2 participants