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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(env_manager): split out python detection #9050

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

Conversation

finswimmer
Copy link
Member

At the moment the env_manager is more or less a big ball of mud, mainly due to violating the single responsible principle. Beside the original purpose - handling environments - it also includes lot of logic to find the desired python interpreter.

This PR tries to refactor the env_manager by split out the logic for finding the path to the desired python interpreter.

For now it's far from production ready, but I like to hear from people if I already broke something 馃槃

Copy link
Member

@Secrus Secrus left a comment

Choose a reason for hiding this comment

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

Looks fine initially. What I thought about, accounting for the future plans, maybe we could make some kind of "backends" for python detection. Current way would be one backend and future pythonfinder/findpython solution would be another one. That way we could transition the ways for python detection similar to how we handle package installation with "modern installer" and pip-based.

from poetry.poetry import Poetry


class Python:
Copy link
Member

Choose a reason for hiding this comment

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

PythonManager

Copy link
Member Author

Choose a reason for hiding this comment

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

Not really, because objects of this class don't "manage" python. It's a value object represented by the path to the executable and its version.

def get_system_python() -> Python:
return Python(executable=sys.executable)

@staticmethod
Copy link
Member

Choose a reason for hiding this comment

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

Looks more like @classmethod to me. Same goes for get_system_python and probably _detect_active_python.

Copy link
Member Author

Choose a reason for hiding this comment

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

馃 I'm more used to @staticmethod for methods that serves as a factory. But it looks like @classmethod is more common and we are doing so in other place. So I'm fine with changing it.

@finswimmer finswimmer force-pushed the rework-python-detection-2 branch 7 times, most recently from bfaa7db to abb4d65 Compare March 4, 2024 18:44

from cleo.io.null_io import NullIO
from cleo.io.outputs.output import Verbosity
from poetry.core.constraints.version import Version
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure if we should use this as a version in the long run. We had some reports that it doesn't allow proper Python versions to be used. I am not sure if it's better to change it now or wait for the next stage of changes.

@finswimmer finswimmer force-pushed the rework-python-detection-2 branch 5 times, most recently from 30cb460 to 3b70164 Compare March 12, 2024 20:36
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.

None yet

2 participants