Skip to content
Snippets Groups Projects
  1. Jul 01, 2021
  2. Jun 18, 2021
    • John Snow's avatar
      python: add qmp-shell entry point · 957f3c5c
      John Snow authored
      
      now 'qmp-shell' should be available from the command line when
      installing the python package.
      
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      Message-id: 20210607200649.1840382-42-jsnow@redhat.com
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      957f3c5c
    • John Snow's avatar
      scripts/qmp-shell: move to python/qemu/qmp/qmp_shell.py · 6be7206e
      John Snow authored
      
      The script will be unavailable for a commit or two, which will help
      preserve development history attached to the new file. A forwarder will
      be added shortly afterwards.
      
      With qmp_shell in the python qemu.qmp package, now it is fully type
      checked, linted, etc. via the Python CI. It will be quite a bit harder
      to accidentally break it again in the future.
      
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      Message-id: 20210607200649.1840382-41-jsnow@redhat.com
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      6be7206e
    • John Snow's avatar
      python/qmp: return generic type from context manager · eac8aabc
      John Snow authored
      
      __enter__ can be invoked from a subclass, so it needs a more flexible
      type.
      
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      Message-id: 20210607200649.1840382-31-jsnow@redhat.com
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      eac8aabc
    • John Snow's avatar
      python/qmp: add QMPObject type alias · 1acde763
      John Snow authored
      
      This is meant to represent any generic object seen in a QMPMessage, not
      just the root object itself.
      
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      Message-id: 20210607200649.1840382-27-jsnow@redhat.com
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      1acde763
    • John Snow's avatar
      python/qemu-ga-client: add entry point · 7e7c2a0d
      John Snow authored
      
      Remove the shebang, and add a package-defined entry point instead. Now,
      it can be accessed using 'qemu-ga-client' from the command line after
      installing the package.
      
      The next commit adds a forwarder shim that allows the running of this
      script without needing to install the package again.
      
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      Message-id: 20210604155532.1499282-11-jsnow@redhat.com
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      7e7c2a0d
    • John Snow's avatar
      scripts/qemu-ga-client: move to python/qemu/qmp/qemu_ga_client.py · 1e129afc
      John Snow authored
      
      The script itself will be unavailable for a few commits before being
      restored, with no way to run it right after this commit. This helps move
      git history into the new file. To prevent linter regressions, though, we
      do need to immediately touch up the filename to remove dashes (to make
      the module importable), and remove the executable bit.
      
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      Message-id: 20210604155532.1499282-10-jsnow@redhat.com
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      1e129afc
    • John Snow's avatar
      python/qmp: Correct type of QMPReturnValue · 1f639939
      John Snow authored
      
      It's only a Dict[str, Any] most of the time. It's not actually
      guaranteed to be anything in particular. Fix this type to be
      more accurate to the reality we live in.
      
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      Message-id: 20210604155532.1499282-8-jsnow@redhat.com
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      1f639939
    • John Snow's avatar
      python/qmp: add fuse command to 'qom' tools · 176c5490
      John Snow authored
      
      The 'fuse' command will be unavailable if 'fusepy' is not installed. It
      will simply not load and subsequently be unavailable as a subcommand.
      
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      Reviewed-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      Message-id: 20210603003719.1321369-20-jsnow@redhat.com
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      176c5490
    • John Snow's avatar
      scripts/qom-fuse: move to python/qemu/qmp/qom_fuse.py · 173d185d
      John Snow authored
      
      Move qom-fuse over to the python package now that it passes the
      linter. Update the import paradigms so that it continues to pass in the
      context of the Python package.
      
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      Message-id: 20210603003719.1321369-18-jsnow@redhat.com
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      173d185d
    • John Snow's avatar
      python: add optional FUSE dependencies · c63f3b0b
      John Snow authored
      
      In preparation for moving qom-fuse over to the python package, we need
      some new dependencies to support it.
      
      Add an optional 'fusepy' dependency that users of the package can opt
      into with e.g. "pip install qemu[fuse]" which installs the requirements
      necessary to obtain the additional functionality.
      
      Add the same fusepy dependency to the 'devel' extras group --
      unfortunately I do not see a way for optional groups to imply other
      optional groups at present, so the dependency is repeated. The
      development group needs to include the full set of dependencies for the
      purpose of static analysis of all features offered by this library.
      
      Lastly, add the [fuse] extras group to tox's configuration as a
      workaround so that if a stale tox environment is found when running
      `make check-tox`, tox will know to rebuild its environments.
      
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      Message-id: 20210603003719.1321369-17-jsnow@redhat.com
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      c63f3b0b
    • John Snow's avatar
      scripts/qom-fuse: add static type hints · 30ec845c
      John Snow authored
      
      Because fusepy does not have type hints, add some targeted warning
      suppressions.
      
      Namely, we need to allow subclassing something of an unknown type (in
      qom_fuse.py), and we need to allow missing imports (recorded against
      fuse itself) because mypy will be unable to import fusepy (even when
      installed) as it has no types nor type stubs available.
      
      Note: Until now, it was possible to run invocations like 'mypy qemu/'
      from ./python and have that work. However, these targeted suppressions
      require that you run 'mypy -p qemu/' instead. The correct, canonical
      invocation is recorded in ./python/tests/mypy.sh and all of the various
      CI invocations always use this correct form.
      
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      Message-id: 20210603003719.1321369-16-jsnow@redhat.com
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      30ec845c
    • John Snow's avatar
      python: Add 'fh' to known-good variable names · d229f1c8
      John Snow authored
      
      fd and fh are fine: we often use these for "file descriptor" or "file
      handle" accordingly. It is rarely the case that you need to enforce a
      more semantically meaningful name beyond "This is the file we are using
      right now."
      
      While we're here: add comments for all of the non-standard pylint
      names. (And the underscore.)
      
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      Message-id: 20210603003719.1321369-10-jsnow@redhat.com
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      d229f1c8
    • John Snow's avatar
      python/qmp: add qom script entry points · 7c4c595f
      John Snow authored
      
      Add the 'qom', 'qom-set', 'qom-get', 'qom-list', and 'qom-tree' scripts
      to the qemu.qmp package. When you install this package, these scripts
      will become available on your command line.
      
      (e.g. when inside of a venv, `cd python && pip install .` will add
      'qom', 'qom-set', etc to your $PATH.)
      
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      Reviewed-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      Message-id: 20210603003719.1321369-6-jsnow@redhat.com
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      7c4c595f
    • John Snow's avatar
      python/qmp: Add qom script rewrites · c750c028
      John Snow authored
      
      Inspired by qom-set, qom-get, qom-tree and qom-list; combine all four of
      those scripts into a single script.
      
      A later addition of qom-fuse as an 'extension' necessitates that some
      common features are split out and shared between them.
      
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      Message-id: 20210603003719.1321369-5-jsnow@redhat.com
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      c750c028
    • John Snow's avatar
      python/qmp: add parse_address classmethod · 587adaca
      John Snow authored
      
      This takes the place of qmp-shell's __get_address function. It also
      allows other utilities to share the same parser and syntax for
      specifying QMP locations.
      
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      Message-id: 20210603003719.1321369-4-jsnow@redhat.com
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      587adaca
    • John Snow's avatar
      python/qmp: Fix type of SocketAddrT · 5d15c9b8
      John Snow authored
      
      In porting the qom tools, qmp-shell, etc; it becomes evident that this
      type is wrong.
      
      This is an integer, not a string. We didn't catch this before because
      none of QEMUMonitorProtocol's *users* happen to be checked, and the
      internal logic of this class is otherwise self-consistent. Additionally,
      mypy was not introspecting into the socket() interface to realize we
      were passing a bad type for AF_INET. Fixed now.
      
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      Reviewed-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      Message-id: 20210603003719.1321369-3-jsnow@redhat.com
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      5d15c9b8
    • John Snow's avatar
      python/pipenv: Update Pipfile.lock · 9d0ead63
      John Snow authored
      
      In a previous commit, I added tox to the development requirements of the
      Python library. I never bothered to add them to the Pipfile, because
      they aren't needed there. Here, I sync it anyway in its own commit so
      that when we add new packages later that the diffstats will not
      confusingly appear to pull in lots of extra packages.
      
      Ideally I could tell Pipenv simply not to install these, but it doesn't
      seem to support that, exactly. The alternative is removing Tox from the
      development requires, which I'd rather not do.
      
      The other alternative is re-specifying all of the dependencies of
      setup.cfg in the Pipfile, which I'd also rather not do.
      
      Picking what feels least-worst here.
      
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      Message-id: 20210603003719.1321369-2-jsnow@redhat.com
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      9d0ead63
  3. Jun 01, 2021
    • John Snow's avatar
      python: add tox support · 3c8de38c
      John Snow authored
      
      This is intended to be a manually run, non-CI script.
      
      Use tox to test the linters against all python versions from 3.6 to
      3.10. This will only work if you actually have those versions installed
      locally, but Fedora makes this easy:
      
      > sudo dnf install python3.6 python3.7 python3.8 python3.9 python3.10
      
      Unlike the pipenv tests (make venv-check), this pulls "whichever"
      versions of the python packages, so they are unpinned and may break as
      time goes on. In the case that breakages are found, setup.cfg should be
      amended accordingly to avoid the bad dependant versions, or the code
      should be amended to work around the issue.
      
      With confidence that the tests pass on 3.6 through 3.10 inclusive, add
      the appropriate classifiers to setup.cfg to indicate which versions we
      claim to support.
      
      Tox 3.18.0 or above is required to use the 'allowlist_externals' option.
      
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      Reviewed-by: default avatarCleber Rosa <crosa@redhat.com>
      Tested-by: default avatarCleber Rosa <crosa@redhat.com>
      Message-id: 20210527211715.394144-31-jsnow@redhat.com
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      3c8de38c
    • John Snow's avatar
      python: add .gitignore · f9c0600f
      John Snow authored
      
      Ignore *Python* build and package output (build, dist, qemu.egg-info);
      these files are not created as part of a QEMU build. They are created by
      running the commands 'python3 setup.py <sdist|bdist>' when preparing
      tarballs to upload to e.g. PyPI.
      
      Ignore miscellaneous cached python confetti (mypy, pylint, et al)
      
      Ignore .idea (pycharm) .vscode, and .venv (pipenv et al).
      
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Reviewed-by: default avatarCleber Rosa <crosa@redhat.com>
      Message-id: 20210527211715.394144-30-jsnow@redhat.com
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      f9c0600f
    • John Snow's avatar
      python: add Makefile for some common tasks · 6560379f
      John Snow authored
      
      Add "make venv" to create the pipenv-managed virtual environment that
      contains our explicitly pinned dependencies.
      
      Add "make check" to run the python linters [in the host execution
      environment].
      
      Add "make venv-check" which combines the above two: create/update the
      venv, then run the linters in that explicitly managed environment.
      
      Add "make develop" which canonizes the runes needed to get both the
      linting pre-requisites (the "[devel]" part), and the editable
      live-install (the "-e" part) of these python libraries.
      
      make clean: delete miscellaneous python packaging output possibly
      created by pipenv, pip, or other python packaging utilities
      
      make distclean: delete the above, the .venv, and the editable "qemu"
      package forwarder (qemu.egg-info) if there is one.
      
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      Reviewed-by: default avatarCleber Rosa <crosa@redhat.com>
      Tested-by: default avatarCleber Rosa <crosa@redhat.com>
      Message-id: 20210527211715.394144-29-jsnow@redhat.com
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      6560379f
    • John Snow's avatar
      python: add avocado-framework and tests · 31622b2a
      John Snow authored
      
      Try using avocado to manage our various tests; even though right now
      they're only invoking shell scripts and not really running any
      python-native code.
      
      Create tests/, and add shell scripts which call out to mypy, flake8,
      pylint and isort to enforce the standards in this directory.
      
      Add avocado-framework to the setup.cfg development dependencies, and add
      avocado.cfg to store some preferences for how we'd like the test output
      to look.
      
      Finally, add avocado-framework to the Pipfile environment and lock the
      new dependencies. We are using avocado >= 87.0 here to take advantage of
      some features that Cleber has helpfully added to make the test output
      here *very* friendly and easy to read for developers that might chance
      upon the output in Gitlab CI.
      
      [Note: ALL of the dependencies get updated to the most modern versions
      that exist at the time of this writing. No way around it that I have
      seen. Not ideal, but so it goes.]
      
      Provided you have the right development dependencies (mypy, flake8,
      isort, pylint, and now avocado-framework) You should be able to run
      "avocado --config avocado.cfg run tests/" from the python folder to run
      all of these linters with the correct arguments.
      
      (A forthcoming commit adds the much easier 'make check'.)
      
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      Reviewed-by: default avatarCleber Rosa <crosa@redhat.com>
      Tested-by: default avatarCleber Rosa <crosa@redhat.com>
      Message-id: 20210527211715.394144-28-jsnow@redhat.com
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      31622b2a
    • John Snow's avatar
      python: add devel package requirements to setuptools · dbe75f55
      John Snow authored
      
      setuptools doesn't have a formal understanding of development requires,
      but it has an optional feataures section. Fine; add a "devel" feature
      and add the requirements to it.
      
      To avoid duplication, we can modify pipenv to install qemu[devel]
      instead. This enables us to run invocations like "pip install -e
      .[devel]" and test the package on bleeding-edge packages beyond those
      specified in Pipfile.lock.
      
      Importantly, this also allows us to install the qemu development
      packages in a non-networked mode: `pip3 install --no-index -e .[devel]`
      will now fail if the proper development dependencies are not already
      met. This can be useful for automated build scripts where fetching
      network packages may be undesirable.
      
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      Reviewed-by: default avatarCleber Rosa <crosa@redhat.com>
      Message-id: 20210527211715.394144-27-jsnow@redhat.com
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      dbe75f55
    • John Snow's avatar
      python/qemu: add qemu package itself to pipenv · a4dd49d4
      John Snow authored
      
      This adds the python qemu packages themselves to the pipenv manifest.
      'pipenv sync' will create a virtual environment sufficient to use the SDK.
      'pipenv sync --dev' will create a virtual environment sufficient to use
      and test the SDK (with pylint, mypy, isort, flake8, etc.)
      
      The qemu packages are installed in 'editable' mode; all changes made to
      the python package inside the git tree will be reflected in the
      installed package without reinstallation. This includes changes made
      via git pull and so on.
      
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      Reviewed-by: default avatarCleber Rosa <crosa@redhat.com>
      Tested-by: default avatarCleber Rosa <crosa@redhat.com>
      Message-id: 20210527211715.394144-26-jsnow@redhat.com
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      a4dd49d4
    • John Snow's avatar
      python/qemu: add isort to pipenv · 22a973cb
      John Snow authored
      
      isort 5.0.0 through 5.0.4 has a bug that causes it to misinterpret
      certain "from ..." clauses that are not related to imports.
      
      isort < 5.1.1 has a bug where it does not handle comments near import
      statements correctly.
      
      Require 5.1.2 or greater.
      
      isort can be run (in "check" mode) with 'isort -c qemu' from the python
      root. isort can also be used to fix/rewrite import order automatically
      by using 'isort qemu'.
      
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      Reviewed-by: default avatarCleber Rosa <crosa@redhat.com>
      Message-id: 20210527211715.394144-25-jsnow@redhat.com
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      22a973cb
    • John Snow's avatar
      python: move .isort.cfg into setup.cfg · 158ac451
      John Snow authored
      
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      Reviewed-by: default avatarCleber Rosa <crosa@redhat.com>
      Message-id: 20210527211715.394144-24-jsnow@redhat.com
      Signed-off-by: default avatarJohn Snow <jsnow@redhat.com>
      158ac451
Loading