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

index operator interface #165

Merged
merged 12 commits into from
Oct 17, 2023
Merged

index operator interface #165

merged 12 commits into from
Oct 17, 2023

Conversation

ggpwnkthx
Copy link
Contributor

Small QOL update to the OperationIndex class that adds the __getitem__ method to enable access to operations via index operations (square brackets).

@codecov
Copy link

codecov bot commented Sep 21, 2023

Codecov Report

Merging #165 (14bee50) into master (ec8a583) will increase coverage by 0.03%.
The diff coverage is 80.89%.

@@            Coverage Diff             @@
##           master     #165      +/-   ##
==========================================
+ Coverage   92.78%   92.82%   +0.03%     
==========================================
  Files          86       86              
  Lines        6639     6703      +64     
==========================================
+ Hits         6160     6222      +62     
- Misses        479      481       +2     
Flag Coverage Δ
unittests 92.82% <80.89%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
aiopenapi3/openapi.py 92.42% <100.00%> (-0.05%) ⬇️
aiopenapi3/request.py 92.61% <100.00%> (+0.07%) ⬆️
tests/path_test.py 99.68% <100.00%> (+0.01%) ⬆️
aiopenapi3/extra.py 98.95% <95.83%> (-1.05%) ⬇️
tests/extra_test.py 70.27% <61.90%> (+6.41%) ⬆️

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@commonism
Copy link
Owner

Please consider setting up pre-commit, having the ci bot create merge commits for pre-commit changes does not allow rebaseing and requires cherry picking all commits in a new branch.

Anyway - have a look, I sneaked in some bit's I have had and added a unit test.

@ggpwnkthx
Copy link
Contributor Author

ggpwnkthx commented Sep 25, 2023

I'm not familiar with pre-commit, but it looks simple to use. Is there anything I need to do beyond the following?

pip install pre-commit
pre-commit install
pre-commit run --all-files

It seems to get stuck on the flake8 step for me.

@commonism
Copy link
Owner

It does not allow committing non-compliant changes.
If it gets stuck, it requires changes, but it does these changes as well.
Use with git gui to create commits. If you commit only segments of a file, the auto correction does not allow applying the change, commit full file, have the file corrected in the reject, commit corrected file, change last commit using amend.

FAILED tests/extra_test.py::test_reduced[Reduce] - TypeError: 'NoneType' object is not iterable
FAILED tests/extra_test.py::test_reduced[Cull] - TypeError: 'NoneType' object is not iterable

ggpwnkthx and others added 7 commits September 26, 2023 08:06
Small QOL update to the OperationIndex class that adds the __getitem__ method to enable access to operations via index operations (square brackets).
If the key is None, instead of looking based on path + method it will search for the operationId. This is slightly slower than dict comprehension, but still quick and the code is a bit more readable.

A path's non-operation objects are also kept.

(cherry picked from commit 6b58d47)
@commonism
Copy link
Owner

Never merge, always rebase.
PyCharms git integration is really lovely, it allows to do these kind of operations graphical.

I rebased this to allow merging.

@commonism
Copy link
Owner

If you want to incooperate the use of operationIds in Reduce I think it'll be better to have the Reduce.operations a List instead of a dict.

List[
    Union[
        Tuple[
            Union[Pattern,str],
            Optional[List[str]]
        ], 
        str]
]

Using a dict will do as well, it's basically

{None:["operationIdA","operationIdB"], r'/test':["get"]}

vs

["operationIdA", "operationIdB", (r"/test", ["get"])]

where the use of a tuple or a str is similar to the parameters when creating a request.

@ggpwnkthx
Copy link
Contributor Author

ggpwnkthx commented Sep 26, 2023

If you want to incooperate the use of operationIds in Reduce I think it'll be better to have the Reduce.operations a List instead of a dict.

I considered that as well as breaking it out into two separate arguments: paths and operations. I didn't like the separate argument because I felt the naming would cause confusion. I fell back to the single argument, because it would maintain the existing interfacing mechanism. I think the

List[
    Union[
        Tuple[
            Union[Pattern,str],
            Optional[
                List[
                    Union[Pattern,str]
                ]
            ]
        ], 
        str
    ]
]

is the way to go. Using a tuple also make sense, since the incoming filters should be immutable.

I'll update the PR today.

@commonism
Copy link
Owner

> List[
>     Union[
>         Tuple[
>             Union[Pattern,str],
>             Optional[
>                 List[
>                     Union[Pattern,str] <- been here as well
>                 ]
>             ]
>         ], 
>         str
>     ]
> ]

but then I thought if patterns was the right tool on the very defined and limited number of http methods, if it would improve anything but increase complexity.
On further inspection - e.g. (r'/test', [r'[a-z]+t$']) - I discarded it.

That said - I'd prefer

List[
    Union[
        Tuple[
            Union[Pattern,str],
            Optional[
                List[
                    Literal["get","put", "post", "delete","options","head","patch","trace"]
                ]
            ]
        ], 
        str
    ]
]

@ggpwnkthx
Copy link
Contributor Author

Using Literal with the limited HTTP verbs is definitely the way to go.

I'm having trouble with pre-commit. The Github app doesn't seem to ever complete the commit. It's been sitting like this for almost a full day:
image

What am I doing wrong?

@commonism
Copy link
Owner

No idea about the github app, never used it.
pre-commit install a pre-commit hook to make sure everything is fine before accepting a commit - maybe here is a problem?
Try removing the pre-commit hook from .git/…

And I can imagine it is not happy about me re-basing and force pushing your branch.
Likely in case you did not reset&pull before making changes.
In case everything fails, just push the recent changes to a new branch on your repo and I'll pick it up.

return ctx


class MSGraphCulled(MSGraph, Cull):
pass
def paths(self, ctx: "Init.Context") -> "Init.Context":
return ctx
Copy link
Owner

Choose a reason for hiding this comment

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

The Cull/Reduce paths() would set ctx.paths non and limit the initialization of schemas to schemas identified as required by tracking the schemas required for the operations.

Why avoid this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I forget specifically what I was testing for there, but I think I was investigating something to do with schemas being ignored when they shouldn't be.

ADHD moment... It can be set back to pass for now, and I'll jump back into that investigation later.

Copy link
Owner

Choose a reason for hiding this comment

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

remove - so the super() can take care.
tracking failing is a bug we'll address properly, if you find the schema/selectors required to reproduce.

ggpwnkthx and others added 3 commits September 29, 2023 08:40
Adjusted the Reduce class to handle a list of operations rather than a dict of path and methods.

A string or pattern can be used in the list to match against operationIds, or a tuple with a string or pattern as the first element representing the path and a list of strings representing HTTP verbs as the second element will match against the path/methods.

Also, in any case that a path is not culled, the non-operation keys are kept intact to maintain defaults and overrides.

The MSGraph test was updated to accommodate the annotation change as well as to handle a few validation fixes.

(cherry picked from commit 21b8dfb)
TODO: Investigate tracking failing
(cherry picked from commit d00508b)
@commonism
Copy link
Owner

I adjusted the unit tests.

Now - as we work with a list, question …

Reduce(list) or Reduce(*list)

class Reduce(Document, Init):
    def __init__(
        self,
        operations: List[
            Union[Tuple[Union[re.Pattern, str], Optional[List[Union[re.Pattern, str]]]], Union[re.Pattern, str]]
        ],
    ) 

or

class Reduce(Document, Init):
    def __init__(
        self,
        *operations: List[
            Union[Tuple[Union[re.Pattern, str], Optional[List[Union[re.Pattern, str]]]], Union[re.Pattern, str]]
        ],
    ) 

As I do not exactly know if the typing is correct for the last one, example:

Reduce([("test",None), "test2"]) 

vs

Reduce(("test",None), "test2") 

@commonism commonism merged commit 86f75e1 into commonism:master Oct 17, 2023
6 of 7 checks passed
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.

2 participants