-
Notifications
You must be signed in to change notification settings - Fork 61
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
[WIP] refactor, bug fix, optimization #60
Conversation
I'll convert to draft, because I forgot to fix the color-scheme for non- |
Cinnamon was deliberately using a dark theme with a light Gtk theme, but these issues are rendered more or less moot by linuxmint/cinnamon@791ee48, where you'll now be able to quickly choose a light/dark/mixed theme. It looks like a commit related to that Cinnamon work is blocking this from being merged - if you want to rebase (and leave the Cinnamon theme as is in Thanks |
I realized there's some more refactoring to do. Please don't merge (yet) I don't have much time right now, but I'll probably finish it this week (or the next) |
`LAYOUT_STYLE_*`
Also converted a comment into a doc-comment, and removed useless comments. Manually sorted imports, declarations, and definitions
I think it's admirable the effort you're putting in here and don't want to be discouraging, but this is completely overboard. I was ok merging what you had done minus the theme changes, but I don't want the thing rewritten, sorry. It's a simple program that works fine for its intended use, and has the potential to change greatly from one Mint release to the next. All this is doing is increasing the potential for new regressions. I think it's actually making the code more difficult to read as well. We have a lot of repos and I wouldn't mind seeing more contributions and bugfixes, but before attempting something like a major rewrite, I would suggest opening a discussion about it first. |
@mtwebster , ok, so, should I open a discussion now? Which changes were "too much"? I could revert them |
You originally were cleaning up repeated calls to get the desktop environment, and other cleanup. That's fine - if you want to pare it down to those again, we can reopen this.
I'm not saying I'm against optimizations, but for nearly all of our gui programs (mintwelcome, mintsources, etc..) readability counts far more than efficiency or making use of python's latest features. We also have to be careful to maintain compatibility with our debian-based distro - LMDE, which I mentioned only has python 3.9. This is pretty much always going to be the case, as we don't control the parent distros' releases and package versions, so we keep mostly to vanilla code as far as python goes. Last, smaller PRs are better. They're easier to test - here, you changed so much, I dreaded having to review and test it (and I'd have to do it on all three desktops). Your initial PR was easy to review, as it was focused. It's easy to get carried away (I'm as guilty as anyone). You're also a new contributor and I'm much more careful and critical than with people who've been contributing for months and years. As for discussion - I guess that's not the right thing to say, you definitely don't need to 'ask' to work on something - doing what's enjoyable for you is the most important thing. |
I agree 👍
oh... I forgot about that. I'm sorry
Ok, I'll keep the names 1-to-1 (
Yep, I think the enums were unnecessary.
For most vars, yes. But stuff like It also helps with semantics. Instead of being a hardcoded "green", it's whatever
That's what I did with the var I mentioned. But I agree that other vars (such as
ok, I'll try to maximize readability
I agree and "resonate" with this, lol. I understand
I'm sorry (again)
That's reasonable
ok, thanks |
I currently don't have access to my IDE. I'll revert all other changes later
`apt_Cache` seems readable enough. IDK what to do about it
`Final` is no longer an impediment, but this may increase cognitive load
from os import path as os_path, getenv as os_get_env, system as os_system | ||
from subprocess import call as subprocess_call, check_output as subprocess_check_output, Popen as subprocess_Popen |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like I said, I do not want imports renamed - how is os_get_env
an improvement over os.getenv
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did that for 2 reasons:
- Importing a specific module, rather than a collection of modules is (usually) good practice
- The prefix is useful to remember the "parent module" (I'm not sure if this is the correct terminology)
Should I import the parent module (original), or remove the prefix (no as
rename)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Importing a specific module, rather than a collection of modules is (usually) good practice
This is meant to discourage using something like from foo import *
, so you don't up with unexpected global namespace collisions. It's not intended to be used the way you're using it.
There's no reason to use 'os_get_env' over 'os.getenv', or anything in the os module, for that matter. I'll do it if I'm using just a single function from ridiculously_long_module_name
, or if I'm repeatedly using math.pi
, it looks cleaner to maybe from math import pi as PI
.
You should just import modules and use them normally for the most part.
A bit of info:
https://google.github.io/styleguide/pyguide.html#22-imports
https://peps.python.org/pep-0008/#imports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is meant to discourage using something like
from foo import *
, so you don't up with unexpected global namespace collisions. It's not intended to be used the way you're using it.There's no reason to use 'os_get_env' over 'os.getenv', or anything in the os module, for that matter. I'll do it if I'm using just a single function from
ridiculously_long_module_name
, or if I'm repeatedly usingmath.pi
, it looks cleaner to maybefrom math import pi as PI
.You should just import modules and use them normally for the most part.
Fair enough 👍. Since readability is more important than performance, and the Py runtime is very likely to optimize it, and import
ing 1 parent module pollutes less the global namespace than multiple modules, then it's safe to conclude that it's better not to use my "prefix approach".
A bit of info: https://google.github.io/styleguide/pyguide.html#22-imports https://peps.python.org/pep-0008/#imports
Thanks for the links! I'll read them later. I'm busy IRL
from gettext import install as get_text_install | ||
from gi import require_version as gi_require_version |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same - we're using these methods once, why rename them?
locale.bindtextdomain("mintwelcome", "/usr/share/linuxmint/locale") | ||
locale.textdomain("mintwelcome") | ||
get_text_install("mintwelcome", "/usr/share/linuxmint/locale") | ||
from locale import gettext as _, bindtextdomain as locale_bind_text_domain, textdomain as locale_text_domain |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same...
from platform import machine as platform_machine | ||
from apt import Cache as apt_Cache |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
Closing as stale. My temporal bandwidth is very thin now. And I'm no longer a Mint user since many months ago. So I no longer have personal motivation to contribute to these projects. I'm sorry for letting the community down :( I hope other people continue contributing to these projects, since LM is a decent OS, NGL |
raise
clearly understandableException
if DE is unrecognizedWhat I mean by "race condition", is because of
os.getenv("XDG_CURRENT_DESKTOP")
. Each call toos.getenv
makes a system call, which is slow by itself, and prevents auto-optimization by CPython. Each system call has enough latency, that if a process mutatesXDG_CURRENT_DESKTOP
at the right time, it can prevent all conditional branches in theif ... elif
s from being executed