Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hold] refactor: Merge Active and Api code together #330

Draft
wants to merge 55 commits into
base: main
Choose a base branch
from

Conversation

schloerke
Copy link
Collaborator

@schloerke schloerke commented Nov 12, 2024

Fixes #324


Goals:

  • Turn entity classes into read only dictionaries. Prevents users from updating data in place. All .update()-like methods now return a new object.
  • Minimize public parameters such as .params: ResourceParameters (Rename to ._ctx: Context
    • Inherit from Context to extend it with more information rather than expanding parameters. By doing so, the names and usage are consistent. (Hard to distinguish which GUID guid represents )
    • Leverage the ContextP[ContextT] class where possible to give ._ctx: ContextT a type.
  • Minimize the locations of API path. Resolve by placing the calling class.
    • Classes that need to fully fetch their information may provide the bare minimum information for the ActiveDict class to request the data for initialization. This reduces multiple duplications of logic to a single spot
  • Attempt to use ApiCallMixin within classes to reduce how urls are constructed and processed. Given a .ctx: Context and ._path: str, many calling methods can be handled under the hood.

Note - Classes that do not follow the read-only approach:

  • EnvVars
  • ContentItemVanityMixin

Copy link

github-actions bot commented Nov 12, 2024

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
1917 1819 95% 0% 🟢

New Files

File Coverage Status
src/posit/connect/_active.py 92% 🟢
src/posit/connect/_content_repository.py 86% 🟢
src/posit/connect/_types_content_item.py 100% 🟢
src/posit/connect/_types_context.py 86% 🟢
src/posit/connect/oauth/_types_context_integration.py 100% 🟢
TOTAL 93% 🟢

Modified Files

File Coverage Status
src/posit/connect/_api_call.py 86% 🟢
src/posit/connect/_utils.py 73% 🟢
src/posit/connect/bundles.py 99% 🟢
src/posit/connect/client.py 98% 🟢
src/posit/connect/content.py 96% 🟢
src/posit/connect/context.py 94% 🟢
src/posit/connect/env.py 100% 🟢
src/posit/connect/groups.py 59% 🟢
src/posit/connect/jobs.py 100% 🟢
src/posit/connect/me.py 100% 🟢
src/posit/connect/metrics/metrics.py 100% 🟢
src/posit/connect/metrics/shiny_usage.py 100% 🟢
src/posit/connect/metrics/usage.py 100% 🟢
src/posit/connect/metrics/visits.py 100% 🟢
src/posit/connect/oauth/associations.py 98% 🟢
src/posit/connect/oauth/integrations.py 100% 🟢
src/posit/connect/oauth/oauth.py 100% 🟢
src/posit/connect/oauth/sessions.py 100% 🟢
src/posit/connect/packages.py 94% 🟢
src/posit/connect/permissions.py 100% 🟢
src/posit/connect/tasks.py 100% 🟢
src/posit/connect/users.py 97% 🟢
src/posit/connect/vanities.py 90% 🟢
src/posit/connect/variants.py 100% 🟢
TOTAL 95% 🟢

updated for commit: 788938c by action🐍

@schloerke schloerke changed the title Refactor: Merge Active and Api code together refactor: Merge Active and Api code together Nov 12, 2024
@schloerke schloerke marked this pull request as ready for review November 14, 2024 14:25
@schloerke schloerke requested a review from tdstein as a code owner November 14, 2024 14:25
@schloerke schloerke self-assigned this Nov 14, 2024
@schloerke schloerke marked this pull request as draft November 14, 2024 15:07
Comment on lines +153 to +154
# TODO-barret-Q: Is this change correct? It use to be required, but the docs say not-required
id: NotRequired[str]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is this change correct? It use to be required, but the docs say not-required

Comment on lines +78 to +79
# TODO-barret-future-q: Should this be inherited from ActiveFinderSequence? (It would add find_by)
def find(self) -> list[Association]:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should this be inherited from ActiveFinderSequence? (It would add find_by) . We could have .find() and .find_by() be separated out into two ActiveFinder* classes.

Comment on lines +68 to +69
# TODO-barret-future-q; Should this auto retrieve? If so, it should inherit from ActiveSequence
class Integrations(ApiCallMixin, ContextP[Context]):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm really enjoying the clarity of when data is retrieved from .find() / .get() / .all() methods. And it does take the ambiguity out of when data is being retrieved.

I'd be up for dropping the "download all list-like data on initialization" in favor of the retrieval methods (e.g. .find() etc.) . This would also mean that the classes wouldn't be list-like would require the user to retrieve before calling any list like methods (ex: len(jobs.all()) and not len(jobs) which can change over time.

Comment on lines +18 to 19
# TODO-barret-q: Is this used?
self.api_key = api_key
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I couldn't see where this is used. Just wanted to be sure I didn't lose this one as it is related to auth.

Comment on lines +68 to 69
# TODO-barret-future-q: Should this be destroy?
def delete(self) -> None:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should this be .delete() or .destroy()?

Comment on lines +83 to 95
# TODO-barret-future-q: Should this be `.all()`?
@overload
def find(
self,
*,
all: Optional[bool] = ...,
) -> List[Session]: ...

# TODO-barret-future-q: Should this be `.find_by()`?
@overload
def find(self, **kwargs) -> List[Session]: ...

def find(self, **kwargs) -> List[Session]:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No. all: bool is a query parameter. Instead, it should be **kwargs: Unpack[Sessions._FindAttrs]

@schloerke schloerke changed the title refactor: Merge Active and Api code together [hold] refactor: Merge Active and Api code together Nov 20, 2024
Copy link

Hey there! 👋

We noticed that the title of your pull request doesn't follow the Conventional Commits specification. To ensure consistency, we kindly ask you to adjust the title accordingly.

Here are the details:

No release type found in pull request title "[hold] refactor: Merge Active and Api code together". Add a prefix to indicate what kind of release this pull request corresponds to. For reference, see https://www.conventionalcommits.org/

Available types:
 - build
 - chore
 - ci
 - docs
 - feat
 - fix
 - perf
 - style
 - refactor
 - test

@schloerke
Copy link
Collaborator Author

After conversations with Taylor, we are not going to merge this PR. However, there are good ideas within it.

Will keep the PR open until issues are made and/or components pulled out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Merge _api.py and resource.py in code
1 participant