Skip to content

Commit

Permalink
Merge pull request #425 from UW-GAC/maint/pyproject-toml
Browse files Browse the repository at this point in the history
Prefer `pyproject.toml` over `setup.cfg`
  • Loading branch information
amstilp authored Oct 31, 2023
2 parents 7c372c1 + ba7cb21 commit 626ef34
Show file tree
Hide file tree
Showing 38 changed files with 2,105 additions and 6,300 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change log

## Devel

* Switch to using `pyproject.toml` where possible.

## 0.19 (2023-10-27)

* Add filtering in list views.
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ include LICENSE
include README.md
recursive-include anvil_consortium_manager/templates *
recursive-include docs *
prune docs/_build
12 changes: 3 additions & 9 deletions add_test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,9 @@
workspaces = factories.WorkspaceFactory.create_batch(5, workspace_type="example")

# Add some groups to other groups.
factories.GroupGroupMembershipFactory.create(
parent_group=groups[0], child_group=groups[1]
)
factories.GroupGroupMembershipFactory.create(
parent_group=groups[0], child_group=groups[2]
)
factories.GroupGroupMembershipFactory.create(
parent_group=groups[3], child_group=groups[2]
)
factories.GroupGroupMembershipFactory.create(parent_group=groups[0], child_group=groups[1])
factories.GroupGroupMembershipFactory.create(parent_group=groups[0], child_group=groups[2])
factories.GroupGroupMembershipFactory.create(parent_group=groups[3], child_group=groups[2])

# Add accounts to groups.
factories.GroupAccountMembershipFactory.create(group=groups[1], account=accounts[0])
Expand Down
2 changes: 1 addition & 1 deletion anvil_consortium_manager/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.19"
__version__ = "0.20dev1"
12 changes: 3 additions & 9 deletions anvil_consortium_manager/adapters/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,15 @@ def list_filterset_class(self):
def get_list_table_class(self):
"""Return the table class to use for the AccountList view."""
if not self.list_table_class:
raise ImproperlyConfigured(
"Set `list_table_class` in `{}`.".format(type(self))
)
raise ImproperlyConfigured("Set `list_table_class` in `{}`.".format(type(self)))
return self.list_table_class

def get_list_filterset_class(self):
"""Return the FilterSet subclass to use for Account filtering in the AccountList view."""
if not self.list_filterset_class:
raise ImproperlyConfigured(
"Set `list_filterset_class` in `{}`.".format(type(self))
)
raise ImproperlyConfigured("Set `list_filterset_class` in `{}`.".format(type(self)))
if not issubclass(self.list_filterset_class, FilterSet):
raise ImproperlyConfigured(
"list_filterset_class must be a subclass of FilterSet."
)
raise ImproperlyConfigured("list_filterset_class must be a subclass of FilterSet.")
# Make sure it has the correct model set.
if self.list_filterset_class.Meta.model != models.Account:
raise ImproperlyConfigured(
Expand Down
40 changes: 10 additions & 30 deletions anvil_consortium_manager/adapters/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ def get_description(self):
def get_list_table_class(self):
"""Return the table class to use for the WorkspaceListByType view."""
if not self.list_table_class:
raise ImproperlyConfigured(
"Set `list_table_class` in `{}`.".format(type(self))
)
raise ImproperlyConfigured("Set `list_table_class` in `{}`.".format(type(self)))
return self.list_table_class

def get_workspace_form_class(self):
Expand All @@ -89,9 +87,7 @@ def get_workspace_form_class(self):
raise ImproperlyConfigured("Set `workspace_data_form_class`.")
# Make sure it is a model form
if not issubclass(self.workspace_form_class, ModelForm):
raise ImproperlyConfigured(
"workspace_form_class must be a subclass of ModelForm."
)
raise ImproperlyConfigured("workspace_form_class must be a subclass of ModelForm.")
# Make sure it has the correct model set.
if self.workspace_form_class.Meta.model != models.Workspace:
raise ImproperlyConfigured(
Expand All @@ -104,9 +100,7 @@ def get_workspace_data_model(self):
if not self.workspace_data_model:
raise ImproperlyConfigured("Set `workspace_data_model`.")
elif not issubclass(self.workspace_data_model, models.BaseWorkspaceData):
raise ImproperlyConfigured(
"`workspace_data_model` must be a subclass of `BaseWorkspaceData`."
)
raise ImproperlyConfigured("`workspace_data_model` must be a subclass of `BaseWorkspaceData`.")
return self.workspace_data_model

def get_workspace_data_form_class(self):
Expand All @@ -118,9 +112,7 @@ def get_workspace_data_form_class(self):
raise ImproperlyConfigured("Set `workspace_data_form_class`.")
# Make sure it has the "workspace" field.
if "workspace" not in self.workspace_data_form_class().fields:
raise ImproperlyConfigured(
"`workspace_data_form_class` must have a field for workspace."
)
raise ImproperlyConfigured("`workspace_data_form_class` must have a field for workspace.")
return self.workspace_data_form_class

def get_workspace_detail_template_name(self):
Expand Down Expand Up @@ -159,44 +151,32 @@ def register(self, adapter_class):
"""Register an adapter class using its type."""
# Make sure the adapter has the correct subclass.
if not issubclass(adapter_class, BaseWorkspaceAdapter):
raise ImproperlyConfigured(
"`adapter_class` must inherit from `BaseWorkspaceAdapter`."
)
raise ImproperlyConfigured("`adapter_class` must inherit from `BaseWorkspaceAdapter`.")
# Make sure that an adapter for this type is not already registered.
adapter = adapter_class()
type = adapter.get_type()
if type in self._registry:
if self._registry[type] is adapter_class:
raise AdapterAlreadyRegisteredError(
"adapter {} already exists in registry.".format(adapter_class)
)
raise AdapterAlreadyRegisteredError("adapter {} already exists in registry.".format(adapter_class))
else:
raise AdapterAlreadyRegisteredError(
"type `{}` already exists in registry.".format(type)
)
raise AdapterAlreadyRegisteredError("type `{}` already exists in registry.".format(type))
# Add the adapter to the registry.
self._registry[type] = adapter_class

def unregister(self, adapter_class):
"""Unregister an adapter class."""
if not issubclass(adapter_class, BaseWorkspaceAdapter):
raise ImproperlyConfigured(
"`adapter_class` must inherit from `BaseWorkspaceAdapter`."
)
raise ImproperlyConfigured("`adapter_class` must inherit from `BaseWorkspaceAdapter`.")
type = adapter_class().type
if type in self._registry:
# Check that the registered adapter is the same class and raise an exception if not.
registered_adapter = self._registry[type]
if registered_adapter is not adapter_class:
raise AdapterNotRegisteredError(
"adapter {} has not been registered yet.".format(adapter_class)
)
raise AdapterNotRegisteredError("adapter {} has not been registered yet.".format(adapter_class))
else:
del self._registry[type]
else:
raise AdapterNotRegisteredError(
"adapter {} has not been registered yet.".format(adapter_class)
)
raise AdapterNotRegisteredError("adapter {} has not been registered yet.".format(adapter_class))

def get_adapter(self, type):
""" "Return an instance of the adapter for a given workspace ``type``."""
Expand Down
68 changes: 11 additions & 57 deletions anvil_consortium_manager/anvil_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,7 @@ def add_user_to_group(self, group_name, role, user_email):
Returns:
requests.Response
"""
url = (
self.sam_entry_point
+ "/api/groups/v1/"
+ group_name
+ "/"
+ role
+ "/"
+ user_email
)
url = self.sam_entry_point + "/api/groups/v1/" + group_name + "/" + role + "/" + user_email
return self.auth_session.put(url, 204)

def remove_user_from_group(self, group_name, role, user_email):
Expand All @@ -226,15 +218,7 @@ def remove_user_from_group(self, group_name, role, user_email):
Returns:
requests.Response
"""
url = (
self.sam_entry_point
+ "/api/groups/v1/"
+ group_name
+ "/"
+ role
+ "/"
+ user_email
)
url = self.sam_entry_point + "/api/groups/v1/" + group_name + "/" + role + "/" + user_email
return self.auth_session.delete(url, 204)

def list_workspaces(self, fields=None):
Expand Down Expand Up @@ -267,18 +251,10 @@ def get_workspace(self, workspace_namespace, workspace_name):
Returns:
requests.Response
"""
url = (
self.rawls_entry_point
+ "/api/workspaces/"
+ workspace_namespace
+ "/"
+ workspace_name
)
url = self.rawls_entry_point + "/api/workspaces/" + workspace_namespace + "/" + workspace_name
return self.auth_session.get(url, 200)

def create_workspace(
self, workspace_namespace, workspace_name, authorization_domains=[]
):
def create_workspace(self, workspace_namespace, workspace_name, authorization_domains=[]):
"""Create a workspace on AnVIL.
Calls the /api/create_workspace POST method.
Expand Down Expand Up @@ -335,12 +311,9 @@ def clone_workspace(
Returns:
requests.Response
"""
url = (
self.rawls_entry_point
+ "/api/workspaces/{namespace}/{name}/clone".format(
namespace=existing_workspace_namespace,
name=existing_workspace_name,
)
url = self.rawls_entry_point + "/api/workspaces/{namespace}/{name}/clone".format(
namespace=existing_workspace_namespace,
name=existing_workspace_name,
)
body = {
"namespace": cloned_workspace_namespace,
Expand Down Expand Up @@ -372,13 +345,7 @@ def delete_workspace(self, workspace_namespace, workspace_name):
Returns:
requests.Response
"""
url = (
self.rawls_entry_point
+ "/api/workspaces/"
+ workspace_namespace
+ "/"
+ workspace_name
)
url = self.rawls_entry_point + "/api/workspaces/" + workspace_namespace + "/" + workspace_name
return self.auth_session.delete(url, 202)

def get_workspace_acl(self, workspace_namespace, workspace_name):
Expand All @@ -395,14 +362,7 @@ def get_workspace_acl(self, workspace_namespace, workspace_name):
Returns:
requests.Response
"""
url = (
self.rawls_entry_point
+ "/api/workspaces/"
+ workspace_namespace
+ "/"
+ workspace_name
+ "/acl"
)
url = self.rawls_entry_point + "/api/workspaces/" + workspace_namespace + "/" + workspace_name + "/acl"
return self.auth_session.get(url, 200)

def update_workspace_acl(self, workspace_namespace, workspace_name, acl_updates):
Expand All @@ -421,17 +381,11 @@ def update_workspace_acl(self, workspace_namespace, workspace_name, acl_updates)
requests.Response
"""
url = self.rawls_entry_point + (
"/api/workspaces/"
+ workspace_namespace
+ "/"
+ workspace_name
+ "/acl?inviteUsersNotFound=false"
"/api/workspaces/" + workspace_namespace + "/" + workspace_name + "/acl?inviteUsersNotFound=false"
)
# False here means do not invite unregistered users.
updates = json.dumps(acl_updates)
return self.auth_session.patch(
url, 200, headers={"Content-type": "application/json"}, data=updates
)
return self.auth_session.patch(url, 200, headers={"Content-type": "application/json"}, data=updates)


class AnVILAPISession(AuthorizedSession):
Expand Down
4 changes: 1 addition & 3 deletions anvil_consortium_manager/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ def ready(self):
super().ready()
# Register adapters sepcified in settings.
# Import here because importing outside of this method raises the AppRegistryNotReady exception.
from anvil_consortium_manager.adapters.workspace import (
workspace_adapter_registry,
)
from anvil_consortium_manager.adapters.workspace import workspace_adapter_registry

workspace_adapter_registry.populate_from_settings()
Loading

0 comments on commit 626ef34

Please sign in to comment.