diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a6d24f..83c5480 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added - +- Script PowerShell `setup_windows.ps1` que instala automaticamente o Poetry e configura as dependências no Windows. [#639](https://github.com/brazilian-utils/python/issues/639) - Utilitário `convert_name_to_uf` - Utilitário `is_valid_legal_nature` [#641](https://github.com/brazilian-utils/python/issues/641) - Utilitário `get_legal_nature_description` [#641](https://github.com/brazilian-utils/python/issues/641) diff --git a/README.md b/README.md index a24fffa..3bd218a 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,33 @@ desenvolvimento de aplicações para o business Brasileiro. pip install brutils ``` +## Instalação para Usuários Windows 🪟 + +Atualmente, o **Brazilian Utils** não possui suporte nativo completo para Windows. Para simplificar a instalação e execução do projeto, criamos um **script PowerShell (`setup_windows.ps1`)** que cuida de toda a configuração necessária. + +### Requisitos + +Antes de rodar o script, o usuário precisa ter: + +- **Sistema Operacional:** Windows 11 +- **Python 3.9 ou superior** + - Pode ser a versão instalada via Microsoft Store ou a versão tradicional baixada do site oficial +- **Poetry:** será instalado automaticamente pelo script, caso ainda não esteja presente + +> Não é necessário instalar Makefile, Chocolatey ou usar WSL. O script faz toda a detecção, instalação e configuração automaticamente. + +### Passos para Instalação e Configuração + +1. Clone o repositório: + ```bash + git clone + cd brazilian-utils + ``` +2. Execute o script PowerShell: +```powershell + .\setup_windows.ps1 +``` + # Utilização Para usar um de nossos utilitários, basta importar a função necessária, como no exemplo abaixo: diff --git a/README_EN.md b/README_EN.md index aa784da..85cf123 100644 --- a/README_EN.md +++ b/README_EN.md @@ -29,6 +29,35 @@ the development of applications for the Brazilian business. pip install brutils ``` +## Installation for Windows Users 🪟 + +Currently, **Brazilian Utils** does not have full native support for Windows. +To simplify the setup and execution of the project, we created a **PowerShell script (`setup_windows.ps1`)** that handles all the required configuration automatically. + +### Requirements + +Before running the script, make sure you have: + +- **Operating System:** Windows 11 +- **Python 3.9 or higher** + - You can use either the version installed via Microsoft Store or the standard one downloaded from the official website +- **Poetry:** it will be automatically installed by the script if not already present + +> There’s no need to install Makefile, Chocolatey, or use WSL. +> The script automatically detects your environment, installs the required dependencies, and sets up everything for you. + +### Installation and Setup Steps + +1. Clone the repository: + ```bash + git clone + cd brazilian-utils + ``` +2. Run the PowerShell script: +```powershell + .\setup_windows.ps1 +``` + # Usage To use one of our utilities you just need to import the required function as in the example below: diff --git a/setup_windows.ps1 b/setup_windows.ps1 new file mode 100644 index 0000000..98ff215 --- /dev/null +++ b/setup_windows.ps1 @@ -0,0 +1,66 @@ +Write-Host "Verificando Python disponivel..." -ForegroundColor Cyan + +# - Procura todos os executáveis python no PATH +$pythonPaths = Get-Command python* -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Source + +# - Filtra versões >= 3.9 +$pythonPaths = $pythonPaths | ForEach-Object { + $versionOutput = & $_ --version 2>&1 + if ($versionOutput -match "Python (\d+)\.(\d+)\.(\d+)") { + $major = [int]$matches[1] + $minor = [int]$matches[2] + if ($major -eq 3 -and $minor -ge 9) { $_ } + } +} + +# Pega a versão mais alta disponível +$pythonPath = $pythonPaths | Sort-Object -Descending | Select-Object -First 1 + +if (-not $pythonPath) { + Write-Host " Nenhum Python 3.9+ encontrado. Instale o Python e tente novamente." -ForegroundColor Red + exit 1 +} + +Write-Host " Python encontrado em $pythonPath" -ForegroundColor Green + +# - Verifica se o Poetry já está instalado +$possiblePoetryPaths = @( + "$env:APPDATA\Python\Scripts\poetry.exe", + "$env:APPDATA\Roaming\Python\Scripts\poetry.exe", + "$env:LOCALAPPDATA\pypoetry\venv\Scripts\poetry.exe" +) + +$poetryPath = $possiblePoetryPaths | Where-Object { Test-Path $_ } | Select-Object -First 1 + +# - Instala o Poetry se não encontrado +if (-not $poetryPath) { + Write-Host " Poetry nao encontrado. Instalando..." -ForegroundColor Yellow + try { + (Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | & $pythonPath - + Start-Sleep -Seconds 5 + + # tenta localizar após instalação + $poetryPath = $possiblePoetryPaths | Where-Object { Test-Path $_ } | Select-Object -First 1 + + if ($poetryPath) { + Write-Host " Poetry instalado com sucesso em $poetryPath" -ForegroundColor Green + } else { + Write-Host " Erro: instalacao do Poetry parece ter falhado." -ForegroundColor Red + exit 1 + } + } catch { + Write-Host " Erro durante a instalacao do Poetry: $_" -ForegroundColor Red + exit 1 + } +} else { + Write-Host " Poetry ja esta instalado em $poetryPath" -ForegroundColor Green +} + +# - Adiciona ao PATH temporariamente +$env:PATH += ";" + (Split-Path $poetryPath) + +# - Instala dependências e roda projeto +Write-Host " Instalando dependencias do projeto..." -ForegroundColor Cyan +& $poetryPath install + +Write-Host " instalacao finalizada!" -ForegroundColor Green