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

Perform topic check on publish #42

Closed
wants to merge 11 commits into from
Closed

Perform topic check on publish #42

wants to merge 11 commits into from

Conversation

ntoonio
Copy link
Contributor

@ntoonio ntoonio commented Mar 15, 2021

I was asked (njouanin/hbmqtt#195 (comment), #7) to add this feature to this fork since this didn't get merged before hbmqtt was deprecated. I hope I did this in the right way.

This pull request consists of two pull requests, the latter built on top of the first;

Can be used as:

class CustomTopicPlugin(BaseTopicPlugin):
    def __init__(self, context):
        super().__init__(context)

    async def topic_filtering(self, *args, **kwargs):
        publish = kwargs.get("command") == 1
        print("This is a " + ("publish" if publish else "subscribe") + " command")
        return True

@HerrMuellerluedenscheid
Copy link
Contributor

HerrMuellerluedenscheid commented Mar 15, 2021

@ntoonio Thanks for opening the MR! Can you run black on the modified files? Should work with the defaults.

Actually the output looks a little confusing. I need split the optional and required linting stages. Everything above this line is optional:
https://github.com/Yakifo/amqtt/pull/42/checks?check_run_id=2113903658#step:5:173

Hence, it's only black that leads to the failure.

@ntoonio ntoonio changed the title Topic check publish Perform topic check on publish Mar 17, 2021
@HerrMuellerluedenscheid
Copy link
Contributor

@ntoonio Thanks for fixing the linter! Can you add a pytest that reflect the changes?

Also, I think this is quite a lot of commits with repetitive commit messages please consider an interactive rebase to squash the commits.

@ntoonio
Copy link
Contributor Author

ntoonio commented Mar 19, 2021

Will be adding more test for actually running the plugins some other time.

How should I go about merging the commits 520e7ea to c505741? Using rebase -i i have to fix merge conflicts with the current HEAD for every commit... I tried checking out to c505741 and then doing rebase which worked great, but how do i save those changes? When i went back the commits hadn't been squashed

Also... is there any way yo do the Linting with flake8 and black test locally? I'm running black on all files and pytest but the tests on github still fails.

@FlorianLudwig
Copy link
Member

@ntoonio

Here a few tips on how to use rebase -i

HOWTO: git rebase

git rebase -i is a powerful tool which can accomplish different task:

  1. rebasing
  2. linearizing the history
  3. changing history (squash, reorder, delete or alter commits)

Only do one of those at a time!
Usually, if a git rebase -i goes wrong it is because multiple of these things were done at the same time - without the user realizing it.
To avoid this always:

  1. Take a good look at your git history before using rebase
  2. Be sure what you want to accomplish
  3. Never use git rebase -i TARGET without specifying a target

rebasing

  1. Make sure there are no merge commits in your current branch
  2. Do not use -i at all

linearizing the history

  1. Find a commit before the branches diverged
  2. git rebase -i COMMIT
  3. If any commits were on both branches, delete one of them
  4. Ensure the order of your commits is as expected

changing history

Ensure:

  1. No merge commits in the history you are about to change
  2. You are not actually rebasing

One easy way to figure out if you are doing any of those two things is to run your git rebase -i TARGET command without specifying any changes.
If a conflict arises, you were actually rebasing or had a merge in the history.

@FlorianLudwig
Copy link
Member

@ntoonio if you run git rebase -i origin/master you should drop the merge commit (18aecd5). Merging and rebasing in the same workflow doesn't work well.

@FlorianLudwig
Copy link
Member

FlorianLudwig commented Mar 21, 2021

@ntoonio hey!

We moved to poetry - hope this makes it a bit easier to setup a development environment.

Could you review: https://github.com/Yakifo/amqtt/blob/master/contributing.md

And let me know if that is helpful? Or how we could improve it?

@HerrMuellerluedenscheid
Copy link
Contributor

HerrMuellerluedenscheid commented Mar 25, 2021

Will be adding more test for actually running the plugins some other time.

How should I go about merging the commits 520e7ea to c505741? Using rebase -i i have to fix merge conflicts with the current HEAD for every commit... I tried checking out to c505741 and then doing rebase which worked great, but how do i save those changes? When i went back the commits hadn't been squashed

Also... is there any way yo do the Linting with flake8 and black test locally? I'm running black on all files and pytest but the tests on github still fails.

black doesn't seem to be a problem but flake8: https://github.com/Yakifo/amqtt/pull/42/checks?check_run_id=2152892451

You can run flake8 manually:

flake8 . --count --statistics --show-source --ignore=E501,W503,W605,E722

Alternatively, you can use https://pre-commit.com/. you might have to rebase on master. We added a pre-commit-config.yaml in the meantime. To manually run the style checks:

pre-commit run --all-files

@ntoonio
Copy link
Contributor Author

ntoonio commented Apr 14, 2021

I just can't figure out how I would go about squashing those commits... I tried to drop the merge commits, but that removed to commits before that, that I wanted to squash. I think i did the merging backwards. Instead of merging the new amqtt into my branch. I cloned amqtt and merged my branch. It seemed easy at the time but not I think it's just resulting in problems. Would it be easier to redo in a new PR? Feeling kinda stuck right now

@HerrMuellerluedenscheid
Copy link
Contributor

I just can't figure out how I would go about squashing those commits... I tried to drop the merge commits, but that removed to commits before that, that I wanted to squash. I think i did the merging backwards. Instead of merging the new amqtt into my branch. I cloned amqtt and merged my branch. It seemed easy at the time but not I think it's just resulting in problems. Would it be easier to redo in a new PR? Feeling kinda stuck right now

I gave it a try running an interactive rebase on this branch. I also ran into hard to resolve merge conflicts. I'll cherry-pick or do a plain copy-paste some day.

@FlorianLudwig
Copy link
Member

closing this in favor of #66

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.

4 participants