Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <URL_DO_REPO>
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:
Expand Down
29 changes: 29 additions & 0 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <REPO_URL>
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:
Expand Down
66 changes: 66 additions & 0 deletions setup_windows.ps1
Original file line number Diff line number Diff line change
@@ -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