diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml new file mode 100644 index 0000000..dc89fe4 --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -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] diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000..30fe158 --- /dev/null +++ b/.github/workflows/lint.yaml @@ -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 diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 0000000..51f5124 --- /dev/null +++ b/.github/workflows/publish.yaml @@ -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 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..215c89e --- /dev/null +++ b/.github/workflows/test.yaml @@ -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 + + diff --git a/presentation/images/diataxis.png b/presentation/images/diataxis.png new file mode 100644 index 0000000..64e6a64 Binary files /dev/null and b/presentation/images/diataxis.png differ diff --git a/presentation/index.qmd b/presentation/index.qmd index b524d43..f26bb44 100644 --- a/presentation/index.qmd +++ b/presentation/index.qmd @@ -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} @@ -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"} @@ -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 @@ -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 @@ -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 diff --git a/scripts/check_nbs_clean.sh b/scripts/check_nbs_clean.sh new file mode 100755 index 0000000..5ffd72b --- /dev/null +++ b/scripts/check_nbs_clean.sh @@ -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 diff --git a/scripts/rename_package.py b/scripts/rename_package.py new file mode 100644 index 0000000..cf12885 --- /dev/null +++ b/scripts/rename_package.py @@ -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'(?