Skip to content
This repository has been archived by the owner on May 20, 2022. It is now read-only.

Refactor the module to reduce the technical debt and improve tournesol's distribution #11

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

4383
Copy link

@4383 4383 commented Sep 8, 2021

Hello,

This pull request is composed of two non squashed commits.

The first one aim to reduce the technical debt by using maths. It dynamically compute the percentage by rounding the given result rather than using a result matrix.

The second one aim to refactor a bit the tournesolbot module in global manner to allow us to introduce various features like:

  • unit tests
  • tox integration
  • entry points for a better CLI integration
  • virtualenv for development sessions (example: tox -e venv -- tournesolbot)

Now it will allow a better integration with pypi and will allow us to more merely distribute tournesolbot.

These 2 commits are independent unfortunately github pull request doesn't reflect well the git history like doing by gerrit.

Hopefully these changes will help you.

Dynamically compute the percentage by rounding the given result rather
than using a result matrix.
@4383 4383 changed the title Reduce the technical debt by using maths Refactor the module to reduce the technical debt and better distribute tournesol Sep 8, 2021
@4383 4383 changed the title Refactor the module to reduce the technical debt and better distribute tournesol Refactor the module to reduce the technical debt and improve tournesol's distribution Sep 8, 2021
FROM_TOP = 70
LAST_N_DAYS = 120

def get_top_percentage(criteria_row):
Copy link
Author

@4383 4383 Sep 8, 2021

Choose a reason for hiding this comment

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

I completely refactored the function below to use math instead a result of matrix.

Please have a look to 3823c5d

This is why I wrote a sentence about gerrit vs github pull request in the description of this pull request.

Copy link
Author

@4383 4383 left a comment

Choose a reason for hiding this comment

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

In a global manner these changes will allow us to implement CI pipelines to check this repo, the code, and the changes.

@@ -1,7 +1,7 @@
import requests
import pandas as pd

from data.utils_dict import YT_2_TWITTER, already_shared_filepath
from tournesolbot.data.utils_dict import YT_2_TWITTER, already_shared_filepath
Copy link
Author

Choose a reason for hiding this comment

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

imports are now absolute.

@@ -242,7 +232,7 @@ def print_help():
print("-t\ttweet the corresponding string (e.g. 'My tweet').\n")


if __name__ == '__main__':
def main():
Copy link
Author

Choose a reason for hiding this comment

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

This is called by the entry points to launch the bot

flake8-logging-format
commands = flake8

[testenv:venv]
Copy link
Author

Choose a reason for hiding this comment

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

Allow us to run virtualenv by using tox:

tox -e venv -- virtualenv

-r{toxinidir}/requirements.txt
commands = nosetests

[testenv:pep8]
Copy link
Author

Choose a reason for hiding this comment

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

Allow us to lint the code

envlist = py36,py37,py38,pep8
ignore_basepython_conflict = true

[testenv]
Copy link
Author

Choose a reason for hiding this comment

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

Run unit tests

[testenv:venv]
commands = {posargs}

[flake8]
Copy link
Author

Choose a reason for hiding this comment

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

linter configuration

from tournesolbot import get_top_percentage


class TestGetTopPercentage(unittest.TestCase):
Copy link
Author

Choose a reason for hiding this comment

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

Adding few unit test to test our math refactor.

This refactor allow us to:
- introduce entry points for a better CLI integration
- introduce unit tests
- introduce tox environment
    - run unit tests
    - run pep8 checks and linters
    - start a virtualenv to interact with tournesolbot by using
      `tox -e venv -- tournesolbot`. Useful for development session.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant