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

refactoring shortcut.py script #391

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ jobs:
python3-dev
python3-setuptools
python3-numpy
python3-pil
python3-pytest
python3-pip

- name: Install collada2gltf
Expand All @@ -45,13 +43,14 @@ jobs:
- name: Build
run: |
pip install --upgrade pip
pip install -v --config-settings testing=True .
pip install -v --config-settings testing=True '.[dev]'
env:
DEBUG: 1

- name: Test
run: |
pymol -ckqy testing/testing.py --run all
python -m pytest tests -vv

build-Windows:

Expand All @@ -74,7 +73,7 @@ jobs:
shell: cmd
run: |-
CALL %CONDA_ROOT%\\Scripts\\activate.bat
conda install -y -c conda-forge -c schrodinger python cmake libpng freetype pyside6 glew libxml2 numpy=1.26.4 catch2=2.13.3 glm libnetcdf collada2gltf biopython pillow msgpack-python pytest pip python-build
conda install -y -c conda-forge -c schrodinger python cmake libpng freetype pyside6 glew libxml2 numpy=1.26.4 catch2=2.13.3 glm libnetcdf collada2gltf biopython msgpack-python pip python-build

- name: Conda info
shell: cmd
Expand All @@ -94,13 +93,14 @@ jobs:
shell: cmd
run: |
CALL %CONDA_ROOT%\\Scripts\\activate.bat
pip install -v --config-settings testing=True .
pip install -v --config-settings testing=True .[dev]

- name: Test
shell: cmd
run: |
CALL %CONDA_ROOT%\\Scripts\\activate.bat
pymol -ckqy testing\\testing.py --run all
python -m pytest tests -vv

build-MacOS:

Expand All @@ -117,7 +117,7 @@ jobs:
bash $CONDA_ROOT.sh -b -p $CONDA_ROOT
export PATH="$CONDA_ROOT/bin:$PATH"
conda config --set quiet yes
conda install -y -c conda-forge -c schrodinger python cmake libpng freetype pyside6 glew libxml2 numpy=1.26.4 catch2=2.13.3 glm libnetcdf collada2gltf biopython pillow msgpack-python pytest pip python-build
conda install -y -c conda-forge -c schrodinger python cmake libpng freetype pyside6 glew libxml2 numpy=1.26.4 catch2=2.13.3 glm libnetcdf collada2gltf biopython msgpack-python pip python-build
conda info

- name: Get additional sources
Expand All @@ -131,9 +131,10 @@ jobs:
run: |-
export MACOSX_DEPLOYMENT_TARGET=12.0
export PATH="$CONDA_ROOT/bin:$PATH"
pip install -v --config-settings testing=True .
pip install -v --config-settings testing=True '.[dev]'

- name: Test
run: |-
export PATH="$CONDA_ROOT/bin:$PATH"
pymol -ckqy testing/testing.py --run all
python -m pytest tests -vv
4 changes: 2 additions & 2 deletions modules/pymol/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#
# In rare cases, certain nonserious error or warning output should
# also be suppressed. Set "quiet" to 2 for this behavior.
from pymol.shortcut import Shortcut

def _deferred_init_pymol_internals(_pymol):
# set up some global session tasks
Expand All @@ -54,7 +55,7 @@ def _deferred_init_pymol_internals(_pymol):

# take care of some deferred initialization

_pymol._view_dict_sc = Shortcut({})
_pymol._view_dict_sc = Shortcut()

#
if True:
Expand All @@ -78,7 +79,6 @@ def _deferred_init_pymol_internals(_pymol):

_pymol = pymol

from .shortcut import Shortcut

from chempy import io

Expand Down
4 changes: 3 additions & 1 deletion modules/pymol/commanding.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#-*
#Z* -------------------------------------------------------------------

from pymol.shortcut import Shortcut

if True:

import sys
Expand Down Expand Up @@ -39,7 +41,7 @@
cmd = sys.modules["pymol.cmd"]
import pymol

from .cmd import _cmd, Shortcut, QuietException, \
from .cmd import _cmd, QuietException, \
fb_module, fb_mask, is_list, \
DEFAULT_ERROR, DEFAULT_SUCCESS, is_ok, is_error, is_string

Expand Down
30 changes: 16 additions & 14 deletions modules/pymol/completing.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from pymol.shortcut import Shortcut

cmd = __import__("sys").modules["pymol.cmd"]

class ExprShortcut(cmd.Shortcut):
class ExprShortcut(Shortcut):
'''
Expression shortcut for iterate/alter/label with "s." prefix
setting autocompletion.
'''
def interpret(self, kee, mode=0):
if not kee.startswith('s.'):
return cmd.Shortcut.interpret(self, kee, mode)
v = cmd.setting.setting_sc.interpret(kee[2:])
def interpret(self, keyword, mode=False):
if not keyword.startswith('s.'):
return super().interpret(keyword, mode)
v = cmd.setting.setting_sc.interpret(keyword[2:])
if isinstance(v, str):
return 's.' + v
if isinstance(v, list):
Expand All @@ -32,17 +34,17 @@ def interpret(self, kee, mode=0):
def fragments_sc():
import os
import chempy
return cmd.Shortcut([
return Shortcut([
f[:-4] for f in os.listdir(chempy.path + 'fragments')
if f.endswith('.pkl')
])


def vol_ramp_sc():
from . import colorramping
return cmd.Shortcut(colorramping.namedramps)
return Shortcut(colorramping.namedramps)

names_sc = lambda: cmd.Shortcut(cmd.get_names('public'))
names_sc = lambda: Shortcut(cmd.get_names('public'))

aa_nam_e = [ names_sc , 'name' , '' ]
aa_nam_s = [ names_sc , 'name' , ' ' ]
Expand All @@ -58,24 +60,24 @@ def vol_ramp_sc():
aa_rep_c = [ cmd.repres_sc , 'representation' , ', ' ]
aa_rem_c = [ cmd.repmasks_sc , 'representation' , ', ' ]
aa_v_r_c = [ vol_ramp_sc , 'volume ramp' , ', ' ]
aa_ali_e = [ cmd.Shortcut(['align', 'super', 'cealign']), 'alignment method', '']
aa_ali_e = [ Shortcut(['align', 'super', 'cealign']), 'alignment method', '']

def wizard_sc():
import os, pymol.wizard
names_glob = [name[:-3] for p in pymol.wizard.__path__
for name in os.listdir(p) if name.endswith('.py')]
return cmd.Shortcut(names_glob)
return Shortcut(names_glob)

def get_auto_arg_list(self_cmd=cmd):
self_cmd = self_cmd._weakrefproxy

aa_vol_c = [ lambda:
cmd.Shortcut(self_cmd.get_names_of_type('object:volume')),
Shortcut(self_cmd.get_names_of_type('object:volume')),
'volume', '' ]
aa_ramp_c = [ lambda:
cmd.Shortcut(self_cmd.get_names_of_type('object:ramp')),
Shortcut(self_cmd.get_names_of_type('object:ramp')),
'ramp', '' ]
aa_scene_e = [lambda: cmd.Shortcut(cmd.get_scene_list()), 'scene', '']
aa_scene_e = [lambda: Shortcut(cmd.get_scene_list()), 'scene', '']

return [
# 1st
Expand Down Expand Up @@ -168,7 +170,7 @@ def get_auto_arg_list(self_cmd=cmd):
'sculpt_iterate' : aa_obj_c,
'set' : aa_set_c,
'set_bond' : aa_set_c,
'set_key' : [ lambda: cmd.Shortcut(cmd.key_mappings), 'key' , ', ' ],
'set_key' : [ lambda: Shortcut(cmd.key_mappings), 'key' , ', ' ],
'set_name' : aa_nam_c,
'set_title' : aa_obj_c,
'show' : aa_rem_c,
Expand Down
2 changes: 1 addition & 1 deletion modules/pymol/constants.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

# constant objects

from pymol.shortcut import Shortcut
from .parsing import QuietException
from .shortcut import Shortcut
from .constants_palette import palette_dict
import re

Expand Down
4 changes: 2 additions & 2 deletions modules/pymol/controlling.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
#-*
#Z* -------------------------------------------------------------------

from pymol.shortcut import Shortcut

if True:
try:
from . import selector, internal
from .shortcut import Shortcut
cmd = __import__("sys").modules["pymol.cmd"]
from .cmd import _cmd, QuietException, is_string, \
boolean_dict, boolean_sc, \
DEFAULT_ERROR, DEFAULT_SUCCESS, is_ok, is_error, \
location_code, location_sc
import pymol
except:
from shortcut import Shortcut
cmd = None


Expand Down
3 changes: 2 additions & 1 deletion modules/pymol/creating.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#-*
#Z* -------------------------------------------------------------------

from pymol.shortcut import Shortcut
from .constants import CURRENT_STATE, ALL_STATES

if True:
Expand All @@ -23,7 +24,7 @@
import re
import gzip
import os
from .cmd import _cmd, Shortcut, is_list, is_string, \
from .cmd import _cmd, is_list, is_string, \
safe_list_eval, safe_alpha_list_eval, \
DEFAULT_ERROR, DEFAULT_SUCCESS, is_ok, is_error, \
is_tuple
Expand Down
3 changes: 2 additions & 1 deletion modules/pymol/editing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#Z* -------------------------------------------------------------------

import pymol
from pymol.shortcut import Shortcut
from .constants import CURRENT_STATE, ALL_STATES


Expand Down Expand Up @@ -67,7 +68,7 @@ def _iterate_prepare_args(expression, space, _self):
import math
from . import selector
cmd = __import__("sys").modules["pymol.cmd"]
from .cmd import _cmd,lock,unlock,Shortcut,is_string, \
from .cmd import _cmd,lock,unlock,is_string, \
boolean_sc,boolean_dict,safe_list_eval, is_sequence, \
DEFAULT_ERROR, DEFAULT_SUCCESS, _raising, is_ok, is_error
from chempy import cpv
Expand Down
2 changes: 1 addition & 1 deletion modules/pymol/experimenting.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
if True:

from . import selector
from .cmd import _cmd,lock,unlock,Shortcut,QuietException, \
from .cmd import _cmd,lock,unlock,QuietException, \
DEFAULT_ERROR, DEFAULT_SUCCESS, _raising, is_ok, is_error
cmd = __import__("sys").modules["pymol.cmd"]
import threading
Expand Down
3 changes: 2 additions & 1 deletion modules/pymol/exporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#-*
#Z* -------------------------------------------------------------------

from pymol.shortcut import Shortcut
from . import colorprinting

if True:
Expand All @@ -24,7 +25,7 @@

import pymol
cmd = sys.modules["pymol.cmd"]
from .cmd import _cmd,Shortcut,QuietException
from .cmd import _cmd,QuietException
from chempy import io
from chempy.pkl import cPickle
from .cmd import _feedback,fb_module,fb_mask, \
Expand Down
2 changes: 1 addition & 1 deletion modules/pymol/externing.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import traceback

from glob import glob
from .cmd import _cmd,lock,unlock,Shortcut,QuietException, \
from .cmd import _cmd,lock,unlock,QuietException, \
_feedback,fb_module,fb_mask, exp_path, \
DEFAULT_ERROR, DEFAULT_SUCCESS, _raising, is_ok, is_error

Expand Down
3 changes: 2 additions & 1 deletion modules/pymol/feedingback.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
from pymol.shortcut import Shortcut
cmd = __import__("sys").modules["pymol.cmd"]
from .cmd import Shortcut, is_string, QuietException
from .cmd import is_string, QuietException
from .cmd import fb_module, fb_mask, fb_action,_raising
import copy

Expand Down
2 changes: 1 addition & 1 deletion modules/pymol/fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import os
import pymol

from .cmd import _cmd,lock,unlock,Shortcut, \
from .cmd import _cmd,lock,unlock, \
DEFAULT_ERROR, DEFAULT_SUCCESS, _raising, is_ok, is_error


Expand Down
3 changes: 2 additions & 1 deletion modules/pymol/internal.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import sys
cmd = sys.modules["pymol.cmd"]
from pymol.shortcut import Shortcut
from pymol import _cmd
import threading
import traceback
Expand All @@ -14,7 +15,7 @@

import chempy.io

from .cmd import DEFAULT_ERROR, DEFAULT_SUCCESS, loadable, _load2str, Shortcut, \
from .cmd import DEFAULT_ERROR, DEFAULT_SUCCESS, loadable, _load2str, \
is_string, is_ok

# cache management:
Expand Down
3 changes: 2 additions & 1 deletion modules/pymol/movie.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import threading
import time
from . import colorprinting
from pymol.shortcut import Shortcut

def get_movie_fps(_self):
r = _self.get_setting_float('movie_fps')
Expand Down Expand Up @@ -817,7 +818,7 @@ def _encode(filename,first,last,preserve,
'ray' : 2,
}

produce_mode_sc = cmd.Shortcut(produce_mode_dict.keys())
produce_mode_sc = Shortcut(produce_mode_dict.keys())


def find_exe(exe):
Expand Down
3 changes: 2 additions & 1 deletion modules/pymol/moving.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#-*
#-*
#Z* -------------------------------------------------------------------
from pymol.shortcut import Shortcut

if True:

Expand All @@ -21,7 +22,7 @@
import pymol
import re
cmd = sys.modules["pymol.cmd"]
from .cmd import _cmd,Shortcut, \
from .cmd import _cmd, \
toggle_dict,toggle_sc, \
DEFAULT_ERROR, DEFAULT_SUCCESS, _raising, is_ok, is_error

Expand Down
3 changes: 2 additions & 1 deletion modules/pymol/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import pymol
from pymol import cmd
from pymol import colorprinting
from pymol.shortcut import Shortcut
from .legacysupport import *

# variables
Expand Down Expand Up @@ -434,6 +435,6 @@ def initialize(pmgapp=-1):
cmd.extend('plugin_pref_save', pref_save)

# autocompletion
cmd.auto_arg[0]['plugin_load'] = [ lambda: cmd.Shortcut(plugins), 'plugin', '' ]
cmd.auto_arg[0]['plugin_load'] = [ lambda: Shortcut(plugins), 'plugin', '' ]

# vi:expandtab:smarttab:sw=4
2 changes: 1 addition & 1 deletion modules/pymol/querying.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from . import selector
import pymol
cmd = __import__("sys").modules["pymol.cmd"]
from .cmd import _cmd,lock,unlock,Shortcut, \
from .cmd import _cmd,lock,unlock, \
_feedback,fb_module,fb_mask,is_list, \
DEFAULT_ERROR, DEFAULT_SUCCESS, _raising, is_ok, is_error

Expand Down
Loading