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

Detect Python 2 activities before they launch #992

Closed
wants to merge 4 commits into from

Conversation

amannaik247
Copy link

@amannaik247 amannaik247 commented Dec 25, 2024

Fixes: #991
The changes I have made:

  • Version Check: The script checks if the Python version is less than 3 and exits with a warning if it is.
  • Activity Path Check: It verifies if the activity exists.
  • Python 2 Check: It checks for the presence of the string "python2" in the activity.py file. If found, it warns the user that the activity is designed for Python 2 and exits.

This implementation ensures that users are informed about potential compatibility issues before attempting to launch an activity that may not work in a Python 3 environment.

Note: I use a black formatter , so some single quotes might have turned into double quotes , creating additional line changes.

@quozl
Copy link
Contributor

quozl commented Dec 25, 2024

Thanks. Some interesting ideas there, but change is to wrong place; bin/sugar-launch is not used, activities are started by Sugar in src/jarabe/journal/misc.py launch(), and failure is displayed when LAUNCH_FAILED is detected. Dig deeper and reproduce the problem.

@chimosky
Copy link
Member

Your opening comment is better in your commit message, see making commits.

I'm guessing the quote changes were probably done by a linter, could you review your changes before you make a commit and remove the ones that are just noise?

@amannaik247
Copy link
Author

Changes in the last commit :

  • Check for setup.py: The code checks if setup.py exists and reads its content to look for any mention of Python 2.
  • Check for activity.info: If activity.info exists, it checks for a line that specifies a Python version requirement.
  • Logging: If either check indicates that the activity is designed for Python 2, a warning is logged, and the activity is not launched.

Additional changes: Formatting and reverted my own changes to the sugar-launch file.

@chimosky
Copy link
Member

Haven't reviewed yet, but it seems you've not read my comments above, most of what's in the commit is noise and that makes it difficult to review, please review the changes your linter makes and remove the noise before making a commit.

Check for setup.py: The code checks if setup.py exists and reads its content to look for any mention of Python 2.
Check for activity.info: If activity.info exists, it checks for a line that specifies a Python version requirement.

activity.info never specifies a Python version requirement IIRC, @quozl correct me if I'm wrong.

There's no mention of Python 2 in any code, you'd know through the syntax and API changes, so checking for a mention of Python 2 isn't how you'd know what version the code is compatible with.

Copy link
Contributor

@quozl quozl left a comment

Choose a reason for hiding this comment

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

It may be more efficient to change sugar-toolkit-gtk3. I've seen no indication that you've thought of that.

You will need to rewrite the commit messages eventually, but this can wait until you've been through a few more design iterations. Please make sure all new commit messages follow our guidance. Rewrite them in the usual way, e.g. git rebase -i, reword, and git push --force.

@chimosky, yes, there is no python version metadata in the activity.info file.

@amannaik247, you might test Sugar to see what happens when a Python 2 activity is installed and started. Tools such as strace -f would make a trace of the failure, and there may be a single point or exit code that would unambiguously identify the scenario. Have you thought of preventing install or even browsing to the Python 2 app store?

@@ -93,4 +93,4 @@ if args.debug:
cmd_args.extend(act_args)

os.chdir(str(activity.get_path()))
os.execvpe(cmd_args[0], cmd_args, activityfactory.get_environment(activity))
os.execvpe(cmd_args[0], cmd_args, activityfactory.get_environment(activity))
Copy link
Contributor

Choose a reason for hiding this comment

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

Change removed newline at end of file. Did you review your change before commit?

@@ -258,20 +259,58 @@ def ready_callback(metadata, source, destination):
model.copy(metadata, '/', ready_callback=ready_callback)


def is_python2_activity(bundle):
# Path to the main activity file
activity_file_path = os.path.join(bundle.get_path(), 'activity.py')
Copy link
Contributor

Choose a reason for hiding this comment

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

Many activities do not have an activity.py file.

if activity_id is None or not activity_id:
activity_id = activityfactory.create_activity_id()

logging.debug('launch bundle_id=%s activity_id=%s object_id=%s uri=%s',
bundle.get_bundle_id(), activity_id, object_id, uri)

if isinstance(bundle, ContentBundle):
# Content bundles are a special case: we treat them as launching
# Browse with a specific URI.
Copy link
Contributor

Choose a reason for hiding this comment

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

Why remove this comment?

@@ -297,7 +336,6 @@ def launch(bundle, activity_id=None, object_id=None, uri=None, color=None,

if not shell_model.can_launch_activity_instance(bundle):
if alert_window is None:
from jarabe.desktop import homewindow
Copy link
Contributor

Choose a reason for hiding this comment

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

Why remove this import?

src/jarabe/journal/misc.py Show resolved Hide resolved
@amannaik247
Copy link
Author

@quozl @chimosky Sorry for the unwanted changes and commit issues. I have bitten more than i could chew. I will review this problem more thoroughly and get back to you with a proper PR. Thank you for the possible solution ideas!

@chimosky
Copy link
Member

chimosky commented Dec 29, 2024

There's no need to apologize, we do appreciate you trying to contribute to Sugar, from everything that's been said above, you could start by actually using Sugar and an activity to know how they work before trying to make a change to them.

You could also look at the code in the activity and try to understand what does what, and change things if you have to and test your changes to see if the activity behave as you expected or just to learn how that change affects the activity.

We do want you to contribute. Hope this helps!

Looking forward to you PR.

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.

Detect Python 2 activities
3 participants