Skip to content

Commit

Permalink
Adiciona imagem do sistema diataxis. Modifica apresentacao para execu…
Browse files Browse the repository at this point in the history
…tar CI/CD. Adiciona codigos para CI/CD
  • Loading branch information
itepifanio committed Sep 14, 2023
1 parent f522616 commit 2a1b731
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 8 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Deploy to GitHub Pages

permissions:
contents: write
pages: write

on:
push:
branches: ["main"]
jobs:
deploy:
runs-on: ubuntu-latest
steps: [uses: fastai/workflows/quarto-ghp@master]
32 changes: 32 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Lint
on: [workflow_dispatch, pull_request, push]

jobs:
nbqa:
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
architecture: 'x64'
cache: "pip"
cache-dependency-path: settings.ini

- name: Install lib
run: |
pip install -e .[dev]
- name: Check nbs are clean
run: ./scripts/check_nbs_clean.sh
shell: bash

- name: Run flake8
run: nbqa flake8 nbs/*.ipynb

- name: Run Mypy
run: nbqa mypy nbs/*.ipynb --ignore-missing-imports
26 changes: 26 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Publish package to TestPypi

on:
release:
types: [published]
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install deps
run: |
pip install twine
pip install -e .[dev]
- name: nbdev pypi
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }}
run: nbdev_pypi --repository testpypi
31 changes: 31 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Tests
on: [workflow_dispatch, pull_request, push]

jobs:
nbdev-test:
runs-on: ubuntu-latest
strategy:
matrix:
py: ['3.8', '3.9', '3.10']
steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.py }}
architecture: 'x64'
cache: "pip"
cache-dependency-path: settings.ini

- name: Install Library
run: |
pip install --upgrade pip
pip install -e .[dev]
- name: Run Tests
run: |
nbdev_test
Binary file added presentation/images/diataxis.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 11 additions & 8 deletions presentation/index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ format:
## Olá, sou o Ítalo Epifânio {.smaller}

::: {.fragment}
- Rio Grandense da trombinha do elefante
- Norte-rio-grandense da trombinha do elefante
![](images/mapa-pau-dos-ferros.png){.absolute top=0 right=0 width=350 height=238}
:::
::: {.fragment}
Expand Down Expand Up @@ -260,7 +260,7 @@ flowchart
- Clone o repositório localmente e acesse sua raiz
- Crie seu ambiente virtual `python -m venv venv`
- Ative-o utilizando `source venv/bin/activate`
- Instale as dependências necessárias `pip install nbdev notebook`
- Instale as dependências necessárias `pip install nbdev notebook twine`
- Execute `jupyter-notebook`

::: {.callout-tip collapse="true"}
Expand Down Expand Up @@ -326,7 +326,7 @@ Melhores práticas com Jupyter notebook e nbdev

## Tipos de Jupyter notebook

![Saiba que tipo de notebook você está escrevendo (Sistema Diataxis)](https://documentation.divio.com/_images/overview.png)
![Saiba que tipo de notebook você está escrevendo (Sistema Diataxis)](images/diataxis.png)

## Bom título e subtítulo

Expand Down Expand Up @@ -533,6 +533,7 @@ Nbdev permite que publiquemos pacotes python utilizando sua CLI

- `nbdev_pypi`, `nbdev_conda`, `nbdev_release_both`
- [Menos documentado](https://github.com/fastai/nbdev/pull/1320) mas também permite publicar no Test PyPI (`nbdev_pypi --repository testpypi`)
- Vamos publicar nosso pacote `nbdev_pypi --repository testpypi`

## Chaves secretas

Expand Down Expand Up @@ -626,14 +627,16 @@ Na interface Test PyPI acesse `Account Settings >> Api Tokens >> Add Api Token`

Adicionando arquivos `.github/worflows/*.yaml`

Vá para (TODO::add link) e copie as pastas `scripts` e `.github` para seu repositório

## Publishing using CI

:::{.callout-note}
- Upgrade the version at `settings.ini`
- Update your changelog
- Commit and push your changes to Github
- Check if tests and lint are passing
- Create a new release at Github following the semantic versioning to use our CD of the package
- Atualize a versão da biblioteca `nbdev_bump_version`
- Adicione `dev_requirements = nbdev` no arquivo `setting.ini`
- Realize um commit e dê push nas suas mudanças
- Verifique se os teste e lint estão passando
- Crie uma nova release na interface do Github
:::

# Python Packaging history
Expand Down
14 changes: 14 additions & 0 deletions scripts/check_nbs_clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

#set -x

nbdev_clean --clear_all

GIT_STATUS_FAILED(){
git status -uno -s |grep '.*\.ipynb'
}

if GIT_STATUS_FAILED; then
echo "!! ::error:: Detected notebooks that are not cleaned."
false;
fi
65 changes: 65 additions & 0 deletions scripts/rename_package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import re
import os
import sys
from nbdev.config import add_init, get_config
from nbdev.doclinks import _build_modidx, nbglob, nb_export

# Renames python library

def _is_snake_case_without_symbols(s):
pattern = r'^[a-z]+(?:_[a-z]+)*$'
return bool(re.match(pattern, s))

def extract_legacy_package_name() -> str:
pattern = r'lib_name\s*=\s*(\w+)'

with open(f'settings.ini', 'r') as f:
settings = f.read()

return re.search(pattern, settings).group(1)

def rename_settings_ini(legacy_name: str, new_name: str):
with open(f'settings.ini', 'r') as f:
settings = f.read()

settings = re.sub(legacy_name, new_name, settings)

with open(f'settings.ini', 'w') as f:
f.write(settings)

def rename_lib_folder(legacy_name: str, new_name: str):
os.rename(legacy_name, new_name)

def _change_imports(file: str, legacy_name: str, new_name: str):
with open(file, 'r') as f:
code = f.read()
code = re.sub(r'(?<!\.)\b'+legacy_name+r'\b', new_name, code)

with open(file, 'w') as f:
f.write(code)

def _export(legacy_name, new_name: str):
files = nbglob(path='nbs', as_path=True).sorted('name')

for file in files:
_change_imports(file, legacy_name, new_name)

for f in files: nb_export(f, procs=None)
add_init(get_config().lib_path)
_build_modidx()

if __name__ == "__main__":
assert len(sys.argv) == 2, "missing package name"

invalid_package_name = (
"Invalid package name "
"try a singleword or snake_case"
)
new_package_name = sys.argv[1]

assert _is_snake_case_without_symbols(new_package_name), invalid_package_name

legacy_package_name = extract_legacy_package_name()
rename_settings_ini(legacy_package_name, new_package_name)
rename_lib_folder(legacy_package_name, new_package_name)
_export(legacy_package_name, new_package_name)

0 comments on commit 2a1b731

Please sign in to comment.