Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

genematx
Copy link
Contributor

@genematx genematx commented Apr 16, 2024

Vendor a copy of Super State Machine into the Bluesky Repository

Description

This PR adds a copy of Super State Machine source code, into the Bluesky repository and removes the external dependency. The automated vendoring tool was used for this purpose.

Motivation and Context

The Super State Machine repo has been updated for more than 7 years, and we would like to use dependencies with good maintenance status. This PR address Issue #1679 .

How Has This Been Tested?

Comment on lines 253 to 262
@property
def actual_state(self):
"""Actual state as `None` or `enum` instance."""
attr = self._meta["state_attribute_name"]
return getattr(self, attr)

@property
def as_enum(self):
"""Return actual state as enum."""
return self.actual_state
Copy link
Contributor Author

@genematx genematx Apr 16, 2024

Choose a reason for hiding this comment

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

Moved these methods here from utils.py and removed the following from _generate_standard_methods:

cls.context.new_methods['actual_state'] = utils.actual_state
cls.context.new_methods['as_enum'] = utils.as_enum

since @property decorators outside of class definitions didn't pass linting checks. (This might cause unnoticed name collisions, but within our restricted usage in Bluesky, it is extremely unlikely.)

@genematx genematx requested review from tacaswell and stan-dot April 16, 2024 18:51
@genematx genematx marked this pull request as ready for review April 16, 2024 18:52
@tacaswell
Copy link
Contributor

We should make the vendored version private, we definitly want to be able to switch this out with a different implementation without having to go through a deprecation cycle.

https://github.com/pypa/pip/tree/main/src/pip/_vendor is a good reference for how to do this and we probably should follow it here.

@tacaswell
Copy link
Contributor

It might be worth to make a LICENSE directory and copying the SSM license into a file called LICENSE_SUPER_STATE_MACHINE following something like https://github.com/matplotlib/matplotlib/tree/main/LICENSE

Copy link
Contributor

@stan-dot stan-dot left a comment

Choose a reason for hiding this comment

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

half done, stopped at utils

@tacaswell
Copy link
Contributor

I am very wary of making any changes to the vendored code in this move. The current state runs, any moderization or changes, particularly stylistic ones, run the risk of adding bugs without a huge upside.

@tacaswell
Copy link
Contributor

I would also prefer that we sush the linters / type checkers rather than fix SSM.

@genematx
Copy link
Contributor Author

genematx commented Apr 17, 2024

I agree with @tacaswell regarding not making changes to the vendored code in order to appease the linter. There were only a couple of bits related to the compatibility with Python 2 that I removed (and the @property methods mentioned above), but otherwise I tried to keep the original super-state-machine code intact; definitely, lots of opportunities for improvement though -- thank you @stan-dot for going through it and making notes.

Also, I might have misunderstood the meaning of vendoring in this context. I will make the version private and let you know once it's done.

@genematx genematx force-pushed the 1679-state-machine branch from 2b1146a to 0362cdc Compare April 17, 2024 18:59
@genematx
Copy link
Contributor Author

Thank you for the suggestions regarding vendoring, @tacaswell! I've used the pip's vendoring tool, and the result looks more standardized and definitely easier to manage (the code is copied with absolutely no modifications). Does this look like something you had in mind?

@genematx genematx requested a review from stan-dot April 18, 2024 03:34
Copy link
Contributor

@stan-dot stan-dot left a comment

Choose a reason for hiding this comment

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

for vendoring option all looks good

@stan-dot
Copy link
Contributor

Still the library did not have its own testing. Unit testing for the core of bluesky is ideally something exhaustive.

I don't feel 100% convinced that vendoring is the optimal long term choice, pip does it for very specific reasons, and the vendored-in repos they reference change often upstream. That is not the case with super_state_machine repo. https://github.com/beregond/super_state_machine . It is a stale 'last update 7 years ago' package.

I am not aware if right now we are running into any limitations with this library. If are not and we can accept the lack of test or write our own that would be not in the library itself, this PR could be merged and the vendored in library code left alone. Should that not be the case, alternatives to 'non-modify-vendoring' in the order of least to most work are:

  • refactor the existing vendored code and add tests
  • choose some library
  • writing a state machine from scratch ourselves

@genematx
Copy link
Contributor Author

genematx commented Apr 18, 2024

Thank you, @stan-dot, for your comments. Yes, I agree that our case for vendoring differs from that of pip's, and actually the use of their vendoring tool is discouraged. As far as I understand, an please correct me if I'm missing something, the main reasons for us to vendor super-state-machine is (1) to reduce the risk of the package being removed from pypi -- not sure if this happens very often if at all, and (2) major breaking changes being suddenly introduced.

I didn't know what to do with the tests. I can certainly just keep their existing tests, but this approach seems to be rather formal -- it would be better to have some sort of integration tests that specifically address the functionality of SSM used in bluesky (and I think we already have a couple). One reason in favour of keeping the existing tests that I can see is checking that SSM works with newer versions of Python. Happy to add them if this makes sense.

I personally would be keen to explore options 2, and especially 3, but this definitely would fall out of scope for this sprint/hackathon.

@genematx
Copy link
Contributor Author

Just looping you in, @danielballan, in case you're interested.

@stan-dot
Copy link
Contributor

@genematx option 2 (a rewrite) is only 3k lines, so a refactored and tested MVP could be theoretically done with 2 weeks of engineering time

@danielballan
Copy link
Member

My two cents: Vendor for right now, but prioritize a rewrite in the medium term. I agree @stan-dot that this should not be a heavy lift.

@tacaswell
Copy link
Contributor

Can we squash this to one commit?

@genematx
Copy link
Contributor Author

Sure, one commit is easy. Should I just merge it?

@tacaswell tacaswell merged commit e0a230c into bluesky:main Apr 18, 2024
joeshannon added a commit to DiamondLightSource/blueapi that referenced this pull request Jul 10, 2024
This was previously available as a transitive dependency from bluesky
but has now been removed (bluesky/bluesky#1708).

This is a temporary workaround to make the build work again and may be
reverted if the types are made available from bluesky in future.

See #553.
joeshannon added a commit to DiamondLightSource/blueapi that referenced this pull request Jul 10, 2024
This was previously available as a transitive dependency from bluesky
but has now been removed (bluesky/bluesky#1708).

This is a temporary workaround to make the build work again and may be
reverted if the types are made available from bluesky in future.

See #553.
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