Hello community, here is the log from the commit of package python-shellingham for openSUSE:Factory checked in at 2020-03-19 19:49:53 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-shellingham (Old) and /work/SRC/openSUSE:Factory/.python-shellingham.new.3160 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-shellingham" Thu Mar 19 19:49:53 2020 rev:3 rq:786237 version:1.3.2 Changes: -------- --- /work/SRC/openSUSE:Factory/python-shellingham/python-shellingham.changes 2019-04-30 13:01:30.838153836 +0200 +++ /work/SRC/openSUSE:Factory/.python-shellingham.new.3160/python-shellingham.changes 2020-03-19 19:53:52.076276767 +0100 @@ -1,0 +2,6 @@ +Wed Mar 18 12:00:31 UTC 2020 - [email protected] + +- version update to 1.3.2 + - Parse argument list to detect shells run via an interpreter, e.g. xonsh via Python. + +------------------------------------------------------------------- Old: ---- shellingham-1.3.1.tar.gz New: ---- shellingham-1.3.2.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-shellingham.spec ++++++ --- /var/tmp/diff_new_pack.Wz4zbR/_old 2020-03-19 19:53:53.328276812 +0100 +++ /var/tmp/diff_new_pack.Wz4zbR/_new 2020-03-19 19:53:53.332276811 +0100 @@ -1,7 +1,7 @@ # # spec file for package python-shellingham # -# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2020 SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -18,7 +18,7 @@ %{?!python_module:%define python_module() python-%{**} python3-%{**}} Name: python-shellingham -Version: 1.3.1 +Version: 1.3.2 Release: 0 Summary: Library to detect surrounding shell License: ISC @@ -38,9 +38,17 @@ %prep %setup -q -n shellingham-%{version} -rm -r tasks %build +if [ -f setup.py ]; then + echo 'remove setup.py creation in %%build' + exit 1 +fi +# https://github.com/sarugaku/shellingham/blob/master/setup.py +cat << EOF > setup.py +from setuptools import setup +setup() +EOF %python_build %install @@ -48,7 +56,7 @@ %python_expand %fdupes %{buildroot}%{$python_sitelib} %check -%python_expand PYTHONPATH=%{buildroot}%{$python_sitelib} $python -m pytest +%pytest %files %{python_files} %doc README.rst ++++++ shellingham-1.3.1.tar.gz -> shellingham-1.3.2.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/shellingham-1.3.1/CHANGELOG.rst new/shellingham-1.3.2/CHANGELOG.rst --- old/shellingham-1.3.1/CHANGELOG.rst 2019-04-10 09:28:34.000000000 +0200 +++ new/shellingham-1.3.2/CHANGELOG.rst 2020-02-12 10:23:51.000000000 +0100 @@ -1,3 +1,12 @@ +1.3.2 (2020-02-12) +================== + +Bug Fixes +--------- + +- Parse argument list to detect shells run via an interpreter, e.g. xonsh via Python. `#27 <https://github.com/sarugaku/shellingham/issues/27>`_ + + 1.3.1 (2019-04-10) ================== diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/shellingham-1.3.1/MANIFEST.in new/shellingham-1.3.2/MANIFEST.in --- old/shellingham-1.3.1/MANIFEST.in 2019-04-10 09:28:34.000000000 +0200 +++ new/shellingham-1.3.2/MANIFEST.in 2020-02-12 10:23:51.000000000 +0100 @@ -1 +1,2 @@ include LICENSE* README* +include pyproject.toml diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/shellingham-1.3.1/setup.cfg new/shellingham-1.3.2/setup.cfg --- old/shellingham-1.3.1/setup.cfg 2019-04-10 09:28:34.000000000 +0200 +++ new/shellingham-1.3.2/setup.cfg 2020-02-12 10:23:51.000000000 +0100 @@ -1,10 +1,12 @@ [metadata] name = shellingham +version = attr: shellingham.__version__ description = Tool to Detect Surrounding Shell url = https://github.com/sarugaku/shellingham author = Tzu-ping Chung author_email = [email protected] long_description = file: README.rst +long_description_content_type = text/x-rst license = ISC License keywords = shell @@ -24,9 +26,15 @@ Topic :: Software Development :: Libraries :: Python Modules [options] -zip_safe = true +package_dir = + = src +packages = find: python_requires = >=2.6,!=3.0,!=3.1,!=3.2,!=3.3 install_requires = +zip_safe = true + +[options.packages.find] +where = src [bdist_wheel] universal = 1 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/shellingham-1.3.1/setup.py new/shellingham-1.3.2/setup.py --- old/shellingham-1.3.1/setup.py 2019-04-10 09:28:34.000000000 +0200 +++ new/shellingham-1.3.2/setup.py 1970-01-01 01:00:00.000000000 +0100 @@ -1,32 +0,0 @@ -import ast -import os - -from setuptools import find_packages, setup - - -ROOT = os.path.dirname(__file__) -VERSION = None - -with open(os.path.join(ROOT, 'src', 'shellingham', '__init__.py')) as f: - for line in f: - if line.startswith('__version__ = '): - VERSION = ast.literal_eval(line[len('__version__ = '):].strip()) - break -if VERSION is None: - raise EnvironmentError('failed to read version') - - -# Put everything in setup.cfg, except those that don't actually work? -setup( - # These really don't work. - package_dir={'': 'src'}, - packages=find_packages('src'), - - # I don't know how to specify an empty key in setup.cfg. - package_data={ - '': ['LICENSE*', 'README*'], - }, - - # I need this to be dynamic. - version=VERSION, -) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/shellingham-1.3.1/src/shellingham/__init__.py new/shellingham-1.3.2/src/shellingham/__init__.py --- old/shellingham-1.3.1/src/shellingham/__init__.py 2019-04-10 09:28:34.000000000 +0200 +++ new/shellingham-1.3.2/src/shellingham/__init__.py 2020-02-12 10:23:51.000000000 +0100 @@ -4,7 +4,7 @@ from ._core import ShellDetectionFailure -__version__ = '1.3.1' +__version__ = '1.3.2' def detect_shell(pid=None, max_depth=6): diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/shellingham-1.3.1/src/shellingham/posix/__init__.py new/shellingham-1.3.2/src/shellingham/posix/__init__.py --- old/shellingham-1.3.1/src/shellingham/posix/__init__.py 2019-04-10 09:28:34.000000000 +0200 +++ new/shellingham-1.3.2/src/shellingham/posix/__init__.py 2020-02-12 10:23:51.000000000 +0100 @@ -1,4 +1,5 @@ import os +import re from .._core import SHELL_NAMES, ShellDetectionFailure from . import proc, ps @@ -19,20 +20,16 @@ raise ShellDetectionFailure('compatible proc fs or ps utility is required') -def _iter_process_command(mapping, pid, max_depth): - """Iterator to traverse up the tree, yielding `argv[0]` of each process. +def _iter_process_args(mapping, pid, max_depth): + """Iterator to traverse up the tree, yielding each process's argument list. """ for _ in range(max_depth): try: proc = mapping[pid] except KeyError: # We've reached the root process. Give up. break - try: - cmd = proc.args[0] - except IndexError: # Process has no name? Whatever, ignore it. - pass - else: - yield cmd + if proc.args: # Persumably the process should always have a name? + yield proc.args pid = proc.ppid # Go up one level. @@ -47,15 +44,50 @@ return (os.path.basename(proc_cmd).lower(), proc_cmd) +_INTERPRETER_SHELL_NAMES = [ + (re.compile(r'^python(\d+(\.\d+)?)?$'), {'xonsh'}), +] + + +def _get_interpreter_shell(proc_name, proc_args): + """Get shell invoked via an interpreter. + + Some shells are implemented on, and invoked with an interpreter, e.g. xonsh + is commonly executed with an executable Python script. This detects what + script the interpreter is actually running, and check whether that looks + like a shell. + + See sarugaku/shellingham#26 for rational. + """ + for pattern, shell_names in _INTERPRETER_SHELL_NAMES: + if not pattern.match(proc_name): + continue + for arg in proc_args: + name = os.path.basename(arg).lower() + if os.path.isfile(arg) and name in shell_names: + return (name, arg) + return None + + +def _get_shell(cmd, *args): + if cmd.startswith('-'): # Login shell! Let's use this. + return _get_login_shell(cmd) + name = os.path.basename(cmd).lower() + if name in SHELL_NAMES: # Command looks like a shell. + return (name, cmd) + shell = _get_interpreter_shell(name, args) + if shell: + return shell + return None + + def get_shell(pid=None, max_depth=6): """Get the shell that the supplied pid or os.getpid() is running in. """ pid = str(pid or os.getpid()) mapping = _get_process_mapping() - for proc_cmd in _iter_process_command(mapping, pid, max_depth): - if proc_cmd.startswith('-'): # Login shell! Let's use this. - return _get_login_shell(proc_cmd) - name = os.path.basename(proc_cmd).lower() - if name in SHELL_NAMES: # The inner-most (non-login) shell. - return (name, proc_cmd) + for proc_args in _iter_process_args(mapping, pid, max_depth): + shell = _get_shell(*proc_args) + if shell: + return shell return None
