Opened 3 years ago
Closed 3 years ago
#6918 closed defect (not a bug)
Read argv in a Pythonic way in ChimeraX_main.py
Reported by: | Zach Pearson | Owned by: | Zach Pearson |
---|---|---|---|
Priority: | moderate | Milestone: | |
Component: | Core | Version: | |
Keywords: | Cc: | chimerax-programmers | |
Blocked By: | Blocking: | ||
Notify when closed: | Platform: | all | |
Project: | ChimeraX |
Description
This line in ChimeraX_main.py implies that we read argv like a C program, but we actually don't need to pass argv around at all on the way to initializing ChimeraX.
If you make a Python virutal environment and install a few packages, then look at its bin
directory, no executable modules have main functions that take arguments. All arguments are parsed from sys.argv, which is first accessed inside the initializing function, since the Python interpreter itself -- and thus all code executed therein which imports sys -- has the arguments.
Note:
See TracTickets
for help on using tickets.
This argument makes no sense. init() is called with sys.argv. That is very Pythonic. What is important is that "python3 -m" works. So in this case "python3 -m ChimeraX_main". And that works just fine. Again, very Pythonic. If ChimeraX_main is used when it is not
__main__
, that is if ChimeraX were to be embedded in another application, then it is important that init() not use sys.argv. Because sys.argv would be for that application. And changing globals to change the behavior of a function is not ideal. In general, functions should not affect or be affected by global state, only their arguments. That is one reason why we have a session object. It is much easier to reason about functions that don't have global side effects. Read up on functional programming. We aren't purists, but it is very helpful.