Skip to content

Commit

Permalink
Merge 885330d into 1758343
Browse files Browse the repository at this point in the history
  • Loading branch information
mstuttgart committed Apr 30, 2023
2 parents 1758343 + 885330d commit 09e5b6d
Show file tree
Hide file tree
Showing 29 changed files with 1,947 additions and 183 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
on: pull_request

name: Github CI Coverage

jobs:

build:
name: Build
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Run image
uses: abatilo/actions-poetry@v2
with:
poetry-version: "1.4.2"

- name: Install poetry packages
run: poetry install --with coverage

- name: Generate coverage report
run: poetry run pytest --cov=brazilcep

- name: Coveralls
uses: coverallsapp/github-action@v2
38 changes: 0 additions & 38 deletions .github/workflows/coveralls.yml

This file was deleted.

30 changes: 0 additions & 30 deletions .github/workflows/flake8.yml

This file was deleted.

32 changes: 32 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

on: pull_request

name: Github CI Lint

jobs:

build:
name: Build
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Run image
uses: abatilo/actions-poetry@v2
with:
poetry-version: "1.4.2"

- name: Check lock file
run: poetry lock --check

- name: Install poetry packages
run: poetry install --with lint

- name: Lint with flake8
run: |
poetry run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
poetry run flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
42 changes: 23 additions & 19 deletions .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Github CI
name: Github CI PyTest

on: push

jobs:
build:

runs-on: ubuntu-latest
ci:
strategy:
fail-fast: false

matrix:
python-version: [3.5, 3.6, 3.7, 3.8]
python-version: ["3.8", "3.9", "3.10", "3.11"]
poetry-version: ["1.4.2"]
os: [ubuntu-22.04, macos-latest, windows-latest]

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
- name: Test with pytest
run: |
pytest
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Run image
uses: abatilo/actions-poetry@v2
with:
poetry-version: ${{ matrix.poetry-version }}

- name: Install dependencies
run: poetry install --with github-actions

- name: Run tests
run: poetry run pytest
Binary file removed .img/logo.jpg
Binary file not shown.
43 changes: 27 additions & 16 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Você pode contribuir de várias maneiras:

### Reportando erros

Informe erros em https://github.com/mstuttgart/pycep-correios/issues.
Informe erros [aqui](https://github.com/mstuttgart/pycep-correios/issues).

Se você está reportando um *bug*, por favor inclua:

Expand All @@ -28,7 +28,7 @@ Qualquer *issue* marcada com esses *tags* está aberta para quem quiser implemen

### Enviando Sugestões e Dúvidas

A melhor maneira de enviar sugestões e dúvidas é abrir uma *issue* em https://github.com/mstuttgart/pycep-correios/issues.
A melhor maneira de enviar sugestões e dúvidas é abrir uma *issue* [aqui](https://github.com/mstuttgart/pycep-correios/issues).

## Comece a contribuir!

Expand All @@ -37,36 +37,45 @@ Pronto para contribuir? Veja como configurar `pycep_correios` para desenvolvimen
1. Fork o repositório `pycep_correios` no GitHub.
2. Clone sua *branch* localmente::

> $ git clone git@github.com:your_name_here/pycep-correios.git
```sh
git clone git@github.com:your_name_here/pycep-correios.git`
```

3. Instale sua cópia local em um *virtualenv*. Supondo que você tenha instalado o *virtualenv*, é assim que você configura a seu *fork* para o desenvolvimento local::
3. A PyCEPCorreios é desenvolvidade usando a biblioteca [Poetry](https://python-poetry.org/) para gerenciamento de dependências.
Veja a [aqui](https://python-poetry.org/docs/) como instalá-la em seu ambiente de desenvolvimento.

> cd pycep-correios
Para instalar as depedências, uso o comando abaixo:

> virtualenv env -p python3
```sh
poetry shell
poetry install
> source env/bin/activate
> pip install -r requirements-dev.txt
```

4. Crie uma *branch* para desenvolvimento::

> git checkout -b nome-da-sua-branch
```sh
git checkout -b nome-da-sua-branch
```

   Agora você pode fazer suas mudanças localmente.
Agora você pode fazer suas mudanças localmente.

1. Quando terminar de fazer alterações, verifique se suas alterações passam nos testes::

> pytest
```sh
pytest
```

1. Confirme as suas alterações e as envie para o GitHub::

> git add .
```sh
git add .
> git commit -m "Descricao detalhada das sua alteracoes. (de preferencia em ingles)"
git commit -m "Descricao detalhada das sua alteracoes. (de preferencia em ingles)"
> git push origin nome-da-sua-branch
git push origin nome-da-sua-branch
```
7. Envie um *Pull Request* para o repositório oficial da PyCEPCorreios no GitHub.

## Como criar um Pull Request
Expand All @@ -75,4 +84,6 @@ Após enviar um pedido de *Pull Request*, verifique se ele atende a essas diretr

1. O pedido de *Pull Request* deve incluir testes, quando for uma nova *feature*.
2. Se o *Pull Request* adicionar funcionalidades, a documentação deve ser atualizada adicionado detalhes de uso da nova funcionalidade.
3. O pedido de *Pull Request* deve funcionar para o 3.5+.
3. O *Pull Request* pode ser em português (preferencial) ou inglês.
4. O pedido de *Pull Request* deve funcionar para as seguintes versões do Python.
<img src="https://img.shields.io/pypi/pyversions/pycep-correios.svg?style=for-the-badge" alt="Version">
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@

<p align="center">
<a href="https://github.com/mstuttgart/pycep-correios/actions?query=workflow%3A%22Github+CI%22">
<img src="https://img.shields.io/github/workflow/status/mstuttgart/pycep-correios/Github%20CI/develop?label=Github%20CI&logo=Github&style=flat-square" alt="Version">
<img src="https://img.shields.io/github/workflow/status/mstuttgart/pycep-correios/Github%20CI/main?label=Github%20CI&logo=Github&style=flat-square" alt="Build">
</a>
<a href="https://coveralls.io/github/mstuttgart/pycep-correios">
<a href="https://coveralls.io/github/mstuttgart/pycep-correios">
<img alt="Coveralls github" src="https://img.shields.io/coveralls/github/mstuttgart/pycep-correios?style=flat-square">
</a>
<a href="https://codeclimate.com/github/mstuttgart/pycep-correios">
<img alt="Code Climate maintainability" src="https://img.shields.io/codeclimate/maintainability/mstuttgart/pycep-correios.svg?style=flat-square">
<a href="https://coveralls.io/github/mstuttgart/pycep-correios">
<img alt="Status" src="https://img.shields.io/pypi/status/pycep-correios?style=flat-square">
</a>
<a href="https://pypi.org/project/pycep-correios">
<img src="https://img.shields.io/pypi/dm/pycep-correios?style=flat-square" alt="Downloads">
</a>
<a href="https://pypi.org/project/pycep-correios">
<img src="https://img.shields.io/pypi/v/pycep-correios.svg?style=flat-square" alt="Ratings">
Expand All @@ -35,6 +38,9 @@

## Instalação

[![Download Stats](https://img.shields.io/pypi/dm/pycep-correios)](https://pypistats.org/packages/pycep-correios)


A PyCEPCorreios pode ser facilmente instalada com o comando a seguir:

```
Expand Down
File renamed without changes.
8 changes: 8 additions & 0 deletions pycep_correios/apicep.py → brazilcep/apicep.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@


def fetch_address(cep):
"""Fetch VIACEP webservice for CEP address. VIACEP provide
a REST API to query CEO requests.
Args:
cep (str):CEP to be searched.
Returns:
address (dict): respective address data from CEP.
"""
try:
response = requests.get(URL.format(cep))

Expand Down
69 changes: 69 additions & 0 deletions brazilcep/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import enum
import re

from . import apicep, correios, viacep

NUMBERS = re.compile(r'[^0-9]')


class WebService(enum.Enum):
"""Enum with the webservices available for consultation.
Note: These values are passed as an argument to
CEP query method.
"""
CORREIOS = 0
VIACEP = 1
APICEP = 2


services = {
WebService.CORREIOS: correios.fetch_address,
WebService.VIACEP: viacep.fetch_address,
WebService.APICEP: apicep.fetch_address,
}


def get_address_from_cep(cep, webservice=WebService.APICEP):
"""Returns the address corresponding to the zip (cep) code entered.
Args:
cep (str): CEP to be queried.
Raises:
ConnectionError: When connection error occurs in CEP query
Timeout: When occurs timeout of webservice response
HTTPError: Invalid HTTP format query
CEPNotFund: CEP not exist in API
BaseException: When any error occurs in the CEP query
returns:
address (dict): Address data of the queried CEP.
"""

if webservice not in (value for attribute, value in WebService.__dict__.items()): # noqa
raise KeyError("""Invalid webservice. Please use this options:
WebService.CORREIOS, WebService.VIACEP, WebService.APICEP
""")

cep = _format_cep(cep)

return services[webservice](_format_cep(cep))

def _format_cep(cep):
"""Format CEP, removing any non-numeric characters.
Args:
cep (str): CEP to be formatted.
Raises:
ValueError: When the string is empty or does not contain numbers.
returns:
cep (str): string containing the formatted CEP.
"""
if not isinstance(cep, str) or not cep:
raise ValueError('CEP must be a non-empty string containing only numbers') # noqa

return NUMBERS.sub('', cep)

0 comments on commit 09e5b6d

Please sign in to comment.