You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2021/02/02 23:02:59 UTC

[airavata-django-portal-sdk] branch master updated: adding linting, import sorting

This is an automated email from the ASF dual-hosted git repository.

machristie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airavata-django-portal-sdk.git


The following commit(s) were added to refs/heads/master by this push:
     new 015dff5  adding linting, import sorting
015dff5 is described below

commit 015dff55088ef9d230f6c66556e23c5e29421abc
Author: Marcus Christie <ma...@iu.edu>
AuthorDate: Tue Feb 2 18:00:25 2021 -0500

    adding linting, import sorting
---
 .travis.yml                                | 10 ++++++++++
 README.md                                  | 28 ++++++++++++++++++++++++++++
 airavata_django_portal_sdk/models.py       |  1 +
 airavata_django_portal_sdk/user_storage.py | 30 ++++++++++++++++--------------
 requirements-dev.txt                       |  3 +++
 setup.cfg                                  | 15 +++++++++++++++
 setup.py                                   |  3 ---
 tests/test_user_storage.py                 |  8 ++++----
 8 files changed, 77 insertions(+), 21 deletions(-)

diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..d1ca6cf
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,10 @@
+language: python
+python:
+  - "3.6"
+  - "3.7"
+  - "3.8"
+install:
+  - pip install -r requirements-dev.txt
+script:
+  - flake8 .
+  - ./runtests.py
diff --git a/README.md b/README.md
index fc77f06..50cc3ab 100644
--- a/README.md
+++ b/README.md
@@ -46,3 +46,31 @@ then:
 pip install -r requirements-dev.txt
 mkdocs serve
 ```
+
+## Developing
+
+### Setting up dev environment
+
+```
+source venv/bin/activate
+pip install -r requirements-dev.txt
+```
+
+### Running tests
+
+```
+./runtests.py
+```
+
+### Running flake8
+
+```
+flake8 .
+```
+
+### Automatically formatting Python code
+
+```
+autopep8 -i -aaa -r .
+isort .
+```
diff --git a/airavata_django_portal_sdk/models.py b/airavata_django_portal_sdk/models.py
index 5490b57..a39f5dd 100644
--- a/airavata_django_portal_sdk/models.py
+++ b/airavata_django_portal_sdk/models.py
@@ -1,5 +1,6 @@
 from django.db import models
 
+
 class UserFiles(models.Model):
     """Base model that should be implemented in Airavata Django Portal."""
     username = models.CharField(max_length=64)
diff --git a/airavata_django_portal_sdk/user_storage.py b/airavata_django_portal_sdk/user_storage.py
index f3ea8a7..de94264 100644
--- a/airavata_django_portal_sdk/user_storage.py
+++ b/airavata_django_portal_sdk/user_storage.py
@@ -9,11 +9,13 @@ from http import HTTPStatus
 from urllib.parse import quote, unquote, urlparse
 
 import requests
-from airavata.model.data.replica.ttypes import (DataProductModel,
-                                                DataProductType,
-                                                DataReplicaLocationModel,
-                                                ReplicaLocationCategory,
-                                                ReplicaPersistentType)
+from airavata.model.data.replica.ttypes import (
+    DataProductModel,
+    DataProductType,
+    DataReplicaLocationModel,
+    ReplicaLocationCategory,
+    ReplicaPersistentType
+)
 from django.conf import settings
 from django.core.exceptions import ObjectDoesNotExist, SuspiciousFileOperation
 from django.core.files import File
@@ -251,12 +253,12 @@ def delete_user_file(request, path):
 
 def update_file_content(request, path, fileContentText):
     if _is_remote_api():
-        resp = _call_remote_api(request,
-                                "/user-storage/~/{path}",
-                                path_params={"path": path},
-                                method="put",
-                                data={"fileContentText": fileContentText}
-                                )
+        _call_remote_api(request,
+                         "/user-storage/~/{path}",
+                         path_params={"path": path},
+                         method="put",
+                         data={"fileContentText": fileContentText}
+                         )
         return
     else:
         full_path = _Datastore().path(request.user.username, path)
@@ -332,7 +334,7 @@ def delete(request, data_product):
         try:
             _Datastore().delete(data_product.ownerName, path)
             _delete_data_product(data_product.ownerName, path)
-        except Exception as e:
+        except Exception:
             logger.exception(
                 "Unable to delete file {} for data product uri {}".format(
                     path, data_product.productUri
@@ -425,7 +427,7 @@ def list_experiment_dir(request, experiment_id, path=""):
         raise NotImplementedError()
 
     experiment = request.airavata_client.getExperiment(
-            request.authz_token, experiment_id)
+        request.authz_token, experiment_id)
     datastore = _Datastore()
     exp_data_path = experiment.userConfigurationData.experimentDataDir
     exp_data_path = os.path.join(exp_data_path, path)
@@ -489,7 +491,7 @@ def experiment_dir_exists(request, experiment_id, path=""):
     if _is_remote_api():
         raise NotImplementedError()
     experiment = request.airavata_client.getExperiment(
-            request.authz_token, experiment_id)
+        request.authz_token, experiment_id)
     datastore = _Datastore()
     exp_data_path = experiment.userConfigurationData.experimentDataDir
     exp_data_path = os.path.join(exp_data_path, path)
diff --git a/requirements-dev.txt b/requirements-dev.txt
index 50964dd..6853c7e 100644
--- a/requirements-dev.txt
+++ b/requirements-dev.txt
@@ -1,4 +1,7 @@
 -r requirements.txt
 -e .
+autopep8==1.5.4
+flake8==3.8.4
+flake8-isort-4.0.0
 mkdocs==1.1.2
 mkautodoc==0.1.0
diff --git a/setup.cfg b/setup.cfg
new file mode 100644
index 0000000..38975e9
--- /dev/null
+++ b/setup.cfg
@@ -0,0 +1,15 @@
+[flake8]
+exclude = venv
+ignore = E501, W504
+
+[isort]
+# Set multi_line_output to option 3 - Vertical Hanging Indent
+
+# from third_party import (
+#     lib1,
+#     lib2,
+#     lib3,
+#     lib4,
+# )
+multi_line_output = 3
+skip_gitignore = true
diff --git a/setup.py b/setup.py
index 4b2df3a..c99e431 100644
--- a/setup.py
+++ b/setup.py
@@ -36,8 +36,5 @@ setup(
         "Programming Language :: Python :: 3.6",
         "Topic :: Internet :: WWW/HTTP",
         "Topic :: Internet :: WWW/HTTP :: WSGI :: Application",
-    ],
-    dependency_links = [
-        # "git+https://github.com/apache/airavata.git@develop#egg=airavata-python-sdk&subdirectory=airavata-api/airavata-client-sdks/airavata-python-sdk",
     ]
 )
diff --git a/tests/test_user_storage.py b/tests/test_user_storage.py
index 30aacf3..a53922c 100644
--- a/tests/test_user_storage.py
+++ b/tests/test_user_storage.py
@@ -5,15 +5,15 @@ import uuid
 from unittest.mock import MagicMock
 from urllib.parse import urlparse
 
-from django.contrib.auth.models import User
-from django.test import RequestFactory, TestCase, override_settings
-
 from airavata.model.data.replica.ttypes import (
     DataProductModel,
     DataProductType,
     DataReplicaLocationModel,
     ReplicaLocationCategory
 )
+from django.contrib.auth.models import User
+from django.test import RequestFactory, TestCase, override_settings
+
 from airavata_django_portal_sdk import user_storage
 
 GATEWAY_ID = 'test-gateway'
@@ -202,7 +202,7 @@ class ListDirTests(BaseTestCase):
             self.assertEqual("testdir", dirs[0]["name"])
             self.assertEqual(len(files), 1)
             self.assertEqual("foo.ext", files[0]["name"])
-            
+
     def test_listdir_broken_symlink(self):
         "Test that broken symlinks are ignored"
         with tempfile.TemporaryDirectory() as tmpdirname, \