From 90bb901f2e0ba06a232a9d5ec55d2366fbe834c1 Mon Sep 17 00:00:00 2001 From: vitusalis Date: Mon, 3 Oct 2022 12:52:58 -0300 Subject: [PATCH] Update README with development instructions --- README.md | 52 ++++++++++++++++++- bothub/api/v2/internal/connect_rest_client.py | 2 +- bothub/api/v2/versionning/serializers.py | 16 +++--- bothub/celery.py | 16 +++--- 4 files changed, 68 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index ec0d064bb..6cee3c25f 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,8 @@ ## Development Use ```make``` commands to ```check_environment```, ```install_requirements```, ```lint```, ```test```, ```migrate```, ```start```, ```migrations``` and ```collectstatic```. - + + ### Commands | Command | Description | |--|--| | make help | Show make commands help @@ -78,6 +79,55 @@ Run ```poetry run python ./manage.py start_all_repository_train``` | admin | admin@bothub.it | admin | yes | | user | user@bothub.it | user | no | +## Development environment setup +A step by step guide on how to run the project locally. +This guide expects that you to: + - Have installed and activated [pyenv](https://github.com/pyenv/pyenv) with the correct Python version for the project; + - Installed [poetry](https://python-poetry.org/) in that environment; + - Installed [redis](https://redis.io/docs/getting-started/installation/) database and it is running; + - Installed and configured [docker](https://docs.docker.com/get-docker/); + - Installed [make](https://gnuwin32.sourceforge.net/packages/make.htm) if you are on Windows. + +> All the commands must be executed at the project root. + + +1. Set up your `.env` file. You can find the expected and default values below or ask a collaborator for the development file in case you don't have one. + +2. Create the *bothub* network inside docker: + + ```docker network create bothub``` + +3. Run the project's database with docker: + + ```docker compose up database``` + +4. Run redis locally: + + ``` sudo service redis-server restart ``` + +5. Run engine locally: + + ```poetry run python manage.py runserver``` + +6. Run migrations and populate script: + + ``` poetry run python manage.py migrate ``` + + ``` poetry run python manage.py fill_db_using_fake_data ``` + +7. Run celery locally: + + ``` make start_celery ``` + +8. Run elasticsearch with docker: + + ``` docker compose up es ``` + +9. Run elasticsearch indexing: + + ``` make search_index ``` +--- + ## Production diff --git a/bothub/api/v2/internal/connect_rest_client.py b/bothub/api/v2/internal/connect_rest_client.py index df2409d09..c2575274e 100644 --- a/bothub/api/v2/internal/connect_rest_client.py +++ b/bothub/api/v2/internal/connect_rest_client.py @@ -33,7 +33,7 @@ def list_classifiers( params={"project_uuid": project_uuid, "user_email": user_email}, ) - return request.json()["data"] + return request.json().get("data", []) def list_authorizations(self, project_uuid: str, user_email: str) -> List[str]: classifiers = self.list_classifiers( diff --git a/bothub/api/v2/versionning/serializers.py b/bothub/api/v2/versionning/serializers.py index 17155f4f2..60836937a 100644 --- a/bothub/api/v2/versionning/serializers.py +++ b/bothub/api/v2/versionning/serializers.py @@ -54,22 +54,22 @@ def update(self, instance, validated_data): return super().update(instance, validated_data) def create(self, validated_data): # pragma: no cover - id_clone = validated_data.pop("id") + original_id = validated_data.pop("id") repository = validated_data.get("repository") name = validated_data.get("name") - clone = get_object_or_404(RepositoryVersion, pk=id_clone, repository=repository) + original_instance = get_object_or_404(RepositoryVersion, pk=original_id, repository=repository) - instance = self.Meta.model( + clone = self.Meta.model( name=name, - last_update=clone.last_update, + last_update=original_instance.last_update, is_default=False, - repository=clone.repository, + repository=original_instance.repository, created_by=self.context["request"].user, is_deleted=True, ) - instance.save() + clone.save() answer_task = celery_app.send_task( - "clone_version", args=[repository.pk, id_clone, instance.pk] + "clone_version", args=[repository.pk, original_id, clone.pk] ) answer_task.wait() - return instance + return clone diff --git a/bothub/celery.py b/bothub/celery.py index f2fa9a986..9e9cebcaa 100644 --- a/bothub/celery.py +++ b/bothub/celery.py @@ -12,10 +12,10 @@ app.autodiscover_tasks(lambda: settings.INSTALLED_APPS) app.conf.beat_schedule = { - "check-training-status": { - "task": "bothub.common.tasks.trainings_check_task", - "schedule": 5.0, - }, + # "check-training-status": { + # "task": "bothub.common.tasks.trainings_check_task", + # "schedule": 5.0, + # }, "delete-nlp-logs": { "task": "bothub.common.tasks.delete_nlp_logs", "schedule": schedules.crontab(hour="22", minute=0), @@ -24,10 +24,10 @@ "task": "bothub.common.tasks.repositories_count_authorizations", "schedule": schedules.crontab(hour="8", minute=0), }, - "repository-score": { - "task": "bothub.common.tasks.repository_score", - "schedule": schedules.crontab(minute="*/5"), - }, + # "repository-score": { + # "task": "bothub.common.tasks.repository_score", + # "schedule": schedules.crontab(minute="*/5"), + # }, }