Skip to content

Commit 3254e81

Browse files
authored
Merge pull request #765 from CitrineInformatics/cleanup-teams-deprecation-warnings
Cleanup Teams deprecation warning.
2 parents c3543d4 + ec510b7 commit 3254e81

File tree

5 files changed

+23
-52
lines changed

5 files changed

+23
-52
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ language: python
22
dist: bionic
33
python:
44
- '3.6'
5-
- '3.7'
6-
- '3.8'
5+
- '3.7.13'
6+
- '3.8.13'
77
- '3.9'
88
- '3.10.0'
99
- '3.10.1'

src/citrine/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.33.1'
1+
__version__ = '1.33.2'

src/citrine/_utils/functions.py

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def format_escaped_url(
215215
)
216216

217217

218-
def use_teams(alt, negate=False):
218+
def use_teams(alt, negate=False, deprecated=False):
219219
"""
220220
Raises error with a redirect message if method is unavailable with(out) teams support.
221221
@@ -235,34 +235,19 @@ def wrapper(self, *args, **kwargs):
235235
if not self.session._accounts_service_v3:
236236
raise NotImplementedError(f"Not available, you may be looking for {alt}")
237237
else:
238-
if self.session._accounts_service_v3:
238+
if deprecated:
239+
# If the method is just deprecated, print a warning even once they're on Teams.
240+
warn(f"This method is deprecated. Use {alt} instead.", DeprecationWarning)
241+
elif self.session._accounts_service_v3:
242+
# If deprecated is false, that means it's unavailable on Teams, so error.
239243
raise NotImplementedError(f"Not available, you may be looking for {alt}")
244+
else:
245+
# If this user isn't on Teams, but it will be unavailable once they are, treat
246+
# it like a deprecation warning but specify it will be unavailable.
247+
warn("This method will be unavailable once Teams are released, and you will "
248+
"need to use {alt}.", DeprecationWarning)
240249
return f(self, *args, **kwargs)
241250

242251
return wrapper
243252

244253
return decorator
245-
246-
247-
def v1_deprecation_warn(
248-
msg="This method will be deprecated once teams are released", warn_with_teams=False):
249-
"""
250-
Raises deprecation warning for methods that will be unavailable with teams release.
251-
252-
Parameters
253-
----------
254-
msg: str
255-
The deprecation message that will be printed in the warning.
256-
warn_with_teams: bool
257-
Whether or not to keep the deprecation warning once teams are released.
258-
259-
"""
260-
def decorator(f):
261-
@wraps(f)
262-
def wrapper(self, *args, **kwargs):
263-
if not self.session._accounts_service_v3 or warn_with_teams:
264-
warn(msg, DeprecationWarning)
265-
return f(self, *args, **kwargs)
266-
return wrapper
267-
268-
return decorator

src/citrine/resources/project.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from citrine._rest.resource import Resource, ResourceTypeEnum
1212
from citrine._serialization import properties
1313
from citrine._session import Session
14-
from citrine._utils.functions import format_escaped_url, use_teams, v1_deprecation_warn
14+
from citrine._utils.functions import format_escaped_url, use_teams
1515
from citrine.exceptions import NonRetryableException, ModuleRegistrationFailedException
1616
from citrine.resources.api_error import ApiError
1717
from citrine.resources.branch import BranchCollection
@@ -317,8 +317,6 @@ def pull_in_resource(self, *, resource: Resource):
317317
return True
318318

319319
@use_teams("team.share")
320-
@v1_deprecation_warn("This method will be deprecated with the Team's release. \
321-
Once Teams are released, use team.share")
322320
def share(self, *,
323321
resource: Optional[Resource] = None,
324322
project_id: Optional[Union[str, UUID]] = None,
@@ -360,7 +358,6 @@ def share(self, *,
360358
})
361359

362360
@use_teams("project.publish")
363-
@v1_deprecation_warn()
364361
def transfer_resource(self, *, resource: Resource,
365362
receiving_project_uid: Union[str, UUID]) -> bool:
366363
"""
@@ -394,8 +391,6 @@ def transfer_resource(self, *, resource: Resource,
394391
return True
395392

396393
@use_teams("project.publish")
397-
@v1_deprecation_warn("This method will be deprecated with the Team's release. \
398-
Once Teams are released, use project.publish")
399394
def make_public(self, resource: Resource) -> bool:
400395
"""
401396
Grant public access to a resource owned by this project.
@@ -421,8 +416,6 @@ def make_public(self, resource: Resource) -> bool:
421416
return True
422417

423418
@use_teams("project.un_publish")
424-
@v1_deprecation_warn("This method will be deprecated with the Team's release. \
425-
Once Teams are released, use project.un_publish")
426419
def make_private(self, resource: Resource) -> bool:
427420
"""
428421
Remove public access for a resource owned by this project.
@@ -511,8 +504,7 @@ def owned_table_config_ids(self) -> List[str]:
511504
result = self.session.get_resource(f"{self._path()}/table_definition_ids")
512505
return result["table_definition_ids"]
513506

514-
@v1_deprecation_warn("This method will be deprecated with the Team's release. \
515-
Once Teams are released, use team.list_members", True)
507+
@use_teams("team.list_members", deprecated=True)
516508
def list_members(self) -> Union[List[ProjectMember], List["TeamMember"]]:
517509
"""
518510
List all of the members in the current project.
@@ -538,8 +530,6 @@ def list_members(self) -> Union[List[ProjectMember], List["TeamMember"]]:
538530
for m in members]
539531

540532
@use_teams("team.update_user_action")
541-
@v1_deprecation_warn("This method will be deprecated with the Team's release. \
542-
Once Teams are released, use team.update_user_action")
543533
def update_user_role(self, *, user_uid: Union[str, UUID], role: ROLES, actions: ACTIONS = []):
544534
"""
545535
Update a User's role and action permissions in the Project.
@@ -559,8 +549,6 @@ def update_user_role(self, *, user_uid: Union[str, UUID], role: ROLES, actions:
559549
return True
560550

561551
@use_teams("team.add_user")
562-
@v1_deprecation_warn("This method will be deprecated with the Team's release. \
563-
Once Teams are released, use team.add_user")
564552
def add_user(self, user_uid: Union[str, UUID]):
565553
"""
566554
Add a User to a Project.
@@ -579,8 +567,6 @@ def add_user(self, user_uid: Union[str, UUID]):
579567
return True
580568

581569
@use_teams("team.remove_user")
582-
@v1_deprecation_warn("This method will be deprecated with the Team's release. \
583-
Once Teams are released, use team.remove_user")
584570
def remove_user(self, user_uid: Union[str, UUID]) -> bool:
585571
"""
586572
Remove a User from a Project.
@@ -697,8 +683,7 @@ def _register_in_team(self, name: str, *, description: Optional[str] = None):
697683
except NonRetryableException as e:
698684
raise ModuleRegistrationFailedException(project.__class__.__name__, e)
699685

700-
@v1_deprecation_warn("This method will be deprecated with the Team's release. \
701-
Once Teams are released, use team.projects.register", True)
686+
@use_teams("team.projects.register", deprecated=True)
702687
def register(self, name: str, *, description: Optional[str] = None) -> Project:
703688
"""
704689
Create and upload new project.

src/citrine/seeding/find_or_create.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
from copy import deepcopy
2+
3+
from deprecation import deprecated
4+
15
from citrine.exceptions import NotFound
26
from citrine.resources import ProjectCollection
37
from citrine.resources.dataset import Dataset
48
from citrine.informatics.workflows.design_workflow import DesignWorkflow
59
from citrine._rest.collection import CreationType, Collection
6-
from copy import deepcopy
7-
from warnings import warn
810

911

1012
def find_collection(*, collection, name):
@@ -68,15 +70,14 @@ def get_by_name_or_raise_error(*, collection, name):
6870
raise ValueError("Did not find resource with the given name: {}".format(name))
6971

7072

73+
@deprecated(deprecated_in="1.33.1", removed_in="2.0.0", details="This method will be unreliable "
74+
"once Teams are released, at which point you should use find_or_create_team.")
7175
def find_or_create_project(*, project_collection, project_name, raise_error=False):
7276
"""
7377
Tries to find a project by name (returns first hit).
7478
7579
If not found, creates a new project with the given name
7680
"""
77-
warn("This method will be deprecated with the Team's release. \
78-
Once Teams are released, use find_or_create_team", DeprecationWarning)
79-
8081
if raise_error:
8182
project = get_by_name_or_raise_error(collection=project_collection, name=project_name)
8283
else:

0 commit comments

Comments
 (0)