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

cli: Introduce new --format argument (and remove --xunit-file) #14

Merged
merged 7 commits into from
May 14, 2024

Conversation

dbaty
Copy link
Member

@dbaty dbaty commented Mar 28, 2024

Any output (text or xUnit) is now directed to the standard output. It
will be easier to add new formats (such as CSV or JSON, which I plan).

@dbaty dbaty force-pushed the dbaty/output_formats branch 8 times, most recently from 2525abb to 6517863 Compare March 28, 2024 16:54
@dbaty dbaty marked this pull request as ready for review March 28, 2024 16:55
@dbaty dbaty force-pushed the dbaty/output_formats branch 2 times, most recently from 3fc73ee to 9736311 Compare March 29, 2024 10:24
Comment on lines +68 to +80
ok_msg = err_msg = ""
if has_old_branches:
err_msg = "NOK: Some branches are too old."
print(err_msg)
else:
err_msg = ""
print("OK: All branches are fresh.")
if out:
print(out)
ok_msg = "OK: All branches are fresh."

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plutôt que d'initialiser des variables qu'on va modifier ou non, on pourrait avoir une petite fonction get_messages(has_old_branches: bool) -> tuple[str, str] ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mouais, je ne suis pas convaincu. :) Là, on a bout de code de 5 lignes, simple, clair, direct. Je trouve ça plus parlant qu'un appel à une fonction.

Comment on lines 68 to 76

# Look for orphan FUTURE tags
orphan_futures = annotations.get_orphan_futures(config)
for orphan in orphan_futures:
out.append(warn(orphan_str(orphan)))
uncolorized_out.append(orphan_str(orphan))
orphan_futures = check_oldies.annotations.get_orphan_futures(config)

out = os.linesep.join(out)
ok_msg = err_msg = ""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pareil que pour check-branches

Comment on lines +4 to +5
# we'll have to make sure that we can do that and still support 3.8
# and 3.9). or perhaps get rid of it?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3.8 and 3.9 should not be supported as they are near the end of their security cycle and close to end-of-life : https://devguide.python.org/versions/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are potential limitations regarding 3.8 and 3.9 ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not inclined to remove support of versions that have not yet reached their end of life (however old they might be).

Comment on lines +29 to +33
if error_message:
lines.append(warn(error_message))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pas de couleur spécifique aux erreurs pour les différencier des alertes ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Qu'est-ce qu'une erreur, qu'est-ce qu'une alerte ?

On a 2 sortes de lignes :

  • lignes informatives : "t'as un FIXME, il a 3 jours, je t'informe, tout va bien"
  • lignes d'erreur : "t'as un FIXME, il a 200 jours, c'est une erreur"

Les premières sont affichées dans la couleur par défaut du terminal. Les secondes sont affichées en rouge.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

J'ai peut-être mal compris mais je vois ok_message, error_message et must_warn alors j'ai pensé à 3 echelons

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

must_warn indique une ligne d'erreur : une annotation ou une branche trop vieille (ou un tag "future" orphelin).

raise ValueError(f"Unknown output format: '{format_}'")


def printer(objects: list, output_format, **options):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

objects: list, output_format: OutputFormat

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bien vu, c'est fait

return xml.etree.ElementTree.tostring(suite, encoding="utf-8").decode("utf-8")


def get_formatter(format_) -> typing.Callable:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

output_format plutôt que format_ ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c'est fait

@@ -113,17 +114,17 @@ def test_output_old_branches(capfd): # capfd is a pytest fixture
assert stdout == expected


def test_xunit_file_generation(tmp_path): # tmp_path is a pytest fixture
xunit_path = tmp_path / "xunit.xml"
def test_xunit_file_generation(capfd): # capfd is a pytest fixture

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use linting instead of comment :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c'est fait

Comment on lines +8 to +11
# `xml.etree.ElementTree.tostring()` preserves attribute order only as of
# Python 3.8. With prior versions, we cannot easily compare XML
# output, so don't bother.
HAS_UNSORTED_XML_WRITE = sys.version_info[:2] < (3, 8)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python minimal version supported is 3.8. So we can remove all logic link to that

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oui, dans une autre pull request où je supprimerai le support de Python 3.7 (entre autres modernisations).

@dbaty dbaty force-pushed the dbaty/output_formats branch 2 times, most recently from 2cf5881 to 29dbfb3 Compare April 12, 2024 17:02
Any output (text or xUnit) is now directed to the standard output. It
will be easier to add new formats (such as CSV or JSON, which I plan).

If you used the `--xunit-file`, you must now use `--format` and
redirect the standard output to a file.
@dbaty dbaty force-pushed the dbaty/output_formats branch from 29dbfb3 to e39fa46 Compare April 12, 2024 17:18
dbaty added 3 commits April 12, 2024 19:21
`check-branches`, `check-fixmes` and `check-futures` commands now
accept a `--format csv` argument. Example:
By default, all commands show all annotations, branches, etc.,
including those that are recent. When exporting to a CSV format, it's
useful to filter out the recent items and only display old ones.
It's a (relative) path, not a mere filename.
@dbaty dbaty force-pushed the dbaty/output_formats branch from e39fa46 to 2f3cdb5 Compare April 12, 2024 17:21
@dbaty
Copy link
Member Author

dbaty commented Apr 12, 2024

@sandre35 et @TiphaineLAURENT : J'ai pris en compte tous les commentaires (parmi ceux que je souhaitais prendre en compte ;) ), rebasé par rapport à master... et ai push-forcé comme un sauvageon. :) J'ai aussi corrigé divers oublis, comme la mise à jour du changelog et de la doc. La pull request m'a l'air à peu près complète, désormais, prête à être mergée.

@dbaty dbaty force-pushed the dbaty/output_formats branch from 6cb8bae to d479f31 Compare April 12, 2024 17:28
@dbaty dbaty merged commit d479f31 into master May 14, 2024
6 checks passed
@dbaty dbaty deleted the dbaty/output_formats branch May 14, 2024 16:51
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.

3 participants