Skip to content

Releases: eclipse-score/bazel-tools-python

v0.1.3

25 Nov 13:52
12217fc

Choose a tag to compare

[bazel] Align rules_python versions (#9)

Align the rules_python python versions between workspace and bzlmod
mode, in particular update the version for workspace mode to 1.4.1.

With the update a breaking change on how the python interpreter is
referenced got introduced in rules_python and required changes.

v0.1.2

24 Oct 10:17
358cc24

Choose a tag to compare

[version] Increment to version 0.1.2 (#6)

v0.1.1

28 Aug 07:22
5d85772

Choose a tag to compare

Fix compatibility_level (#3)

Eclipse infra (#2)

  • [python] Create our first python bazel quality rule

This commit:

  • create a generic python aspect that can interface multiple runners;
  • create our first python runner that runs pylint;
  • create the aspect user interface at defs.bzl;
  • create a default pylint runner config at quality/BUILD;
  • adds quality/private/python to our poetry/tox setup;
  • adds pylint aspect config to .bazelrc;
  • create a target for pyproject.toml.
  • [black] Add black aspect and runner

This commit:

  • adds a functional black aspect and runner;
  • offers the aspect though quality/defs.bzl;
  • as planned, make use of both python_tool_aspect.bzl and python_tool_common.py;
  • add a black config to .bazelrc.
  • Toolchains from rules_python and support for both bzlmod and workspace

We currently have our own python toolchain and support only bazel workspace,
even though we have bzlmod activated.

This commit removes our python toolchain in favor of rules_python toolchain.
By doing this we increase toolchain support for multiple system, add support
for both bzlmod and workspace, add support for multiple OSs, and easily
update our toolchain version when a new one is released.

Other minor changes were made:

  • change bazel labels to fit the new python toolchain;
  • add a tools availability to our README.md
  • [python] Improve LinterSubprocessError content

This modification allows the caller to have access to the actual subprocess
stdout and stderr. This is important because the caller may rely on that
information in case of a non-zero return code.

Example, isort returns 1 when it finds something, but we still want
execute_subprocess to throw so we, on the application level, may be able to
catch and evaluate it.

Each application will do its own evaluation.

  • [isort] Add isort aspect and runner

This commit:

  • adds a functional isort aspect and runner;
  • offers the aspect though quality/defs.bzl;
  • as planned, make use of both python_tool_aspect.bzl and python_tool_common.py;
  • add a isort config to .bazelrc.
  • [python] Fix how python_tool_common check for relative paths

The current approach is wrong because it relies on the string startswith
method.

This work on some cases but throws an exception on another ones, for example,
"myapp" is not relative to "myapp_lib/path/..." but "myapp_lib/path/.."
startswiuth "myapp".

To avoid this we should rely on pathlib is_relative_to. This ensures that a
path is actually relative to the other one instead of just comparing the
string.

  • [python] Add mypy aspect and runner

This commit:

  • adds a functional mypy aspect and runner;
  • offers the aspect though quality/defs.bzl;
  • as planned, make use of both python_tool_aspect.bzl and python_tool_common.py;
  • add a mypy config to .bazelrc.
  • [python] Fix mypy findings

This commit fixes every finding that doesn't come from clang-tidy or qac
targets. Later PRs can fix those as well.

  • [python] Change how we create python aspect output file name

Multiple python runners may use the same entry_point, for example, ruff. With
that in mind one might expect that, as the output file name is based on the
tool and not on the runner, a conflict will happen when both runners are
triggered.

This commit prevents that by changing how we name the output file, which will
from now on be based on the runner name.

This commit also renamed runners, for example, pylint_runner to pylint, and
also add an "_entry_point" to the py_console_script_binaries to avoid
confusion. With this, for example, the pylint output file will still be
called pylint_output_target_name.

  • [python] Add ruff aspect and runner

This commit:

  • adds two functional ruff aspects and runners, one to check files and another
    to format files;
  • offers the aspects through quality/defs.bzl;
  • as planned, make use of both python_tool_aspect.bzl and python_tool_common.py;
  • add a ruff config to .bazelrc.

Two runners were created because ruff has both a check and a formatter. Each
one of those must be invoked individually and therefore we have two output
files. Knowing that the aspect requires one output file, ruff runner was
splitted into two.

Also, as ruff python library doesn't provide a default entry point, a
ruff_entry_point.py had to be created.

  • [python] Create a support directory with a default pyproject file

The default config should not be tied to the one that we have in our root.

Also, as every python_tool_config was the same we only need to keep one of
those. With that, label_flag can now references to the same python config.

  • [python] Fix mypy nomenclature

Mypy is still using the old nomenclature style.

This happened because while other python tools were being refactored mypy
was being added to the repo.

  • [python] Add more mypy types dependencies

To ensure that mypy can type check more code we need to add type libraries.

These libraries ususally come from https://github.com/python/typeshed, and
most are daily released.

This also add those libraries to mypy entry point dependencies.

  • [python] Improve mypy configuration

With this we set mypy as no incremental mode to both our repo and our default
aspect config. The reason is that while it does speed up check, it also makes
mypy bugprone and therefore we are disabling it.

For our repo mypy config we are also fixing it to python 3.9. This means that,
if we change our python version, mypy will still check against 3.9 style.

  • [python] Make python aspect py38 compatible

As we aim to not provide our toolchains anymore, we, unfortunatelly, will need
to support python 3.8. This mostly means replacing some built-ins typehints
with typing

  • [python] Improve how python aspect collects information

There was a fundamental flaw in the python aspect design. It was not
collecting information from the whole dependency tree.

This commit fixes it by splitting the aspect into two aspects.

The python_collect_aspect parse the whole dependency tree and stores it at
the PythonCollectInfo provider.

The already existing python_tool_aspect then inherits PythonCollectInfo
and use that information to call our tool runners.

  • [python] Change python modules names that were shadowing libs

Naming files with the same name as libraries is a bad practice and can
lead some tools to undefined behaviour.

  • [python] Add common classes that will standardize every tool output

Ideally we want two outputs, a json using quality-tools Fidings format and
also a text output so we can output findings to the terminal. Diff outputs
are additional.

This commit add a Findings definition that follows what quality-tools
findings-converter expects. Also, a Findings and a FindingsJSONEncoder helps
us to interface a list of Finding with string and json methods.
Also, updates black_runner, to output their results using the updated
Finding string.

  • [python] Standardize isort output

This commit standardizes isort_runner output, which
is part of a bigger effort to standardize every
python tool output.

  • [python] Add tests for isort runner

  • [python] Create test for python black runner.

This commit will add test coverage to the current black runner.

  • [python] Standarlize mypy output

This commit standardizes mypy_runner output, which
is part of a bigger effort to standardize every
python tool output.

  • [python] Standarlize ruff output

This commit standardizes ruff_check_runner output, and
ruff_format_runner output which are part of a bigger effort
to standardize every python tool output.

  • [python] Remove DeprecatedLinterFindingAsError

This commit will be removing the DeprecatedLinterFindingAsError
function from the python_tool_common, since it should not be
used by the tools anymore.

  • [python] Stardardize pylint output

This commit standardizes pylint_runner output, which
is part of a bigger effort to standardize every
python tool output.

  • [python] Add tests for pylint_runner

  • [python] Black automated Fix

To better integrate our python aspect with our metrics tooling or even
with a normal CI usage we should enable our aspect to automatically apply fixes.
So in this commit black shall now be able to automatically fix a file
depending on the user command.

  • [python] Isort Automated Fix

To better integrate our python aspect with our metrics tooling or even
with a normal CI usage we should enable our aspect to automatically apply fixes.
So in this commit isort shall now be able to automatically fix a file
depending on the user command.

  • [python] Fix black runner test

This commit goal is to fix test_black_output_with_refactor test,
fixing the assert case to assert against the correct variable.

  • [python] Ruff Automated Fix

To better integrate our python aspect with our metrics tooling or even
with a normal CI usage we should enable our aspect to automatically apply fixes.
So in this commit ruff check and ruff format shall now be able to automatically
fix a file depending on the user command.

  • [docs] Improve our documentation

Simplify our main README.md into Offered Tools, How to use BRQ
and Contributing.

Create a CONTRIBUTING.md.

Split, and slighty refactor, each specific tool section into its own
README.md file.

  • [python] Improve compatibility across multiple versions

Minor improvements that improve compatibility for multiple versions of python.

  • [bazel] Adapt every target to the new bazel infra

With this we adapt a lot BUILD files (mainly labels) to the new bazel
infrastructure.

Also, py_version_printer was upgraded to supply more information...

Read more