Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UPD][WIP] Atualização Biblioteca, incluído o arquivo pyproject.toml #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mbcosta
Copy link
Contributor

@mbcosta mbcosta commented Feb 9, 2024

Atualização Biblioteca para o padrão atual do Python, incluído o arquivo pyproject.toml

PR é um WIP "Trabalho em Andamento" achei melhor subir ainda em Rascunho para validar, debater e analisar junto aos outros desenvolvedores se essa atualização está sendo feita de acordo com o que o projeto busca.

Ao testar o PR #46 e rodar o comando tox localmente vi algumas mensagens de erro

Erros existentes hoje ao rodar o comando tox localmente

Erro namespace https://peps.python.org/pep-0420/

erpbrasil.base-UPD_FIX-pre_commit_libs/.tox/check/lib64/python3.9/site-packages/setuptools/dist.py:674: SetuptoolsDeprecationWarning: The namespace_packages parameter is deprecated.
!!

    ********************************************************************************
    Please replace its usage with implicit namespaces (PEP 420).

    See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages for details.
    ********************************************************************************

!!
ep.load()(self, ep.name, value)

erpbrasil.base-UPD_FIX-pre_commit_libs/.tox/check/lib64/python3.9/site-packages/isort/settings.py:500: UserWarning: W0503: Deprecated config options were used: not_skip.Please see the 5.0.0 upgrade guide: https://pycqa.github.io/isort/docs/upgrade_guides/5.0.0.html
warn(

erpbrasil.base-UPD_FIX-pre_commit_libs/.tox/check/lib64/python3.9/site-packages/isort/main.py:1276: UserWarning: W0501: The following deprecated CLI flags were used and ignored: --recursive!
warn(
erpbrasil.base-UPD_FIX-pre_commit_libs/.tox/check/lib64/python3.9/site-packages/isort/main.py:1280: UserWarning: W0500: Please see the 5.0.0 Upgrade guide: https://pycqa.github.io/isort/docs/upgrade_guides/5.0.0.html
warn(

Atualização da biblioteca

Olhando de corrigir achei melhor partir para atualizar a biblioteca, seguem algumas referencias:

PEP 518 – Specifying Minimum Build System Requirements for Python Projects

https://peps.python.org/pep-0518/

Abstract

This PEP specifies how Python software packages should specify what build dependencies they have in order to execute their chosen build system. As part of this specification, a new configuration file is introduced for software packages to use to specify their build dependencies (with the expectation that the same configuration file will be used for future configuration details).

Specification

The build system dependencies will be stored in a file named pyproject.toml that is written in the TOML format

PEP 621 – Storing project metadata in pyproject.toml

https://peps.python.org/pep-0621/

This PEP specifies how to write a project’s core metadata in a pyproject.toml file for packaging-related tools to consume.

https://snarky.ca/what-the-heck-is-pyproject-toml/

And so now projects like Black, coverage.py, towncrier, and tox (in a way) allow you to specify their configurations in pyproject.toml instead of in a separate file.

With that you get to participate in thePEP 517 world of standards! 😉 And as I said, you can now rely on a specific version of setuptools and get build isolation as well (which is why the current directory is not put on sys.path automatically; you will need sys.path.insert(0, os.path.dirname(file)) or equivalent if you're importing local files).

But there's a bonus if you use a pyproject.toml file with a setup.cfg configuration for setuptools: you don't need a setup.py file anymore! Since tools like pip are going to call setuptools using the PEP 517 API instead of setup.py it means you can delete that setup.py file (although if you use editable installs make sure you are using pip 21.3 or newer)!

Apagar ou não o arquivo setup.py?

https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages

When using declarative configs via pyproject.toml with setuptools<64.0.0, users can still keep a very simple setup.py just to ensure editable installs are supported, for example:

from setuptools import setup

setup()
Versions of setuptools >=64.0.0 do not require this extra minimal setup.py file.

https://packaging.python.org/en/latest/flow/

The document aims to outline the flow involved in publishing/distributing a distribution package, usually to the Python Package Index (PyPI). It is written for package publishers, who are assumed to be the package author.

Na alteração dos arquivos usei como referencia um projeto que está sendo usado pela OCA a partir da v17

https://github.com/sbidoul/whool/tree/main

A standards-compliant Python build backend to package individual Odoo addons.

Com isso acabei incluindo algumas novas Libs que estão sendo usadas por esse projeto

Ambiente

https://pypi.org/project/hatchling/
Modern, extensible Python build backend

https://pypi.org/project/hatch-vcs/
This provides a plugin for Hatch that uses your preferred version control system (like Git) to determine project versions.

Linter

https://github.com/astral-sh/ruff
An extremely fast Python linter and code formatter, written in Rust.

Deixei comentado no arquivo tox.ini:

  • mypy devido a quantidade de erros que precisam ser analisado o que deve ser parametrazado para validar ou não
  • doc por retornar erro make: *** Nenhum alvo indicado e nenhum arquivo make encontrado. Pare.
  • twine que é um publicador de versões https://pypi.org/project/twine/ para evitar algum erro antes deixar tudo certo achei melhor deixar comentado

Ao rodar localmente o ruff já está alterando diversos arquivos, eu deixei nas opções além do --fix o --unsafe-fixes para testar e ver o que ele está fazendo, basicamente e o tratamento de string que foi simplificado, importações repetidas ( isso acredito já pode ser alterado na versão atual ), remoção da linha do enconding utf-8 ( já está depreciado junto com a versão 2.7 importante dizer que nesse PR a versão mínima do python está sendo alterada para 3.7 ) e outras pequenas alterações que deveram aparecer, deixei isso de fora desse PR para não "poluir" o PR com muitas alterações, bom como escrevi acima é apenas um rascunho para saber se tem outras pessoas vendo essa questão e debater qual o melhor caminho a seguir.

cc @rvalyi @renatonlima @marcelsavegnago @mileo

@mileo
Copy link
Member

mileo commented Dec 10, 2024

@mbcosta pode fazer um rebase?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants