Skip to content

Commit

Permalink
Fix for new tox version
Browse files Browse the repository at this point in the history
Signed-off-by: Bernát Gábor <[email protected]>
  • Loading branch information
gaborbernat committed Sep 17, 2021
1 parent cd22e89 commit cfc61a0
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 87 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,7 @@ jobs:
skip_existing: true
user: __token__
password: ${{ secrets.pypi_password }}
- uses: actions/upload-artifact@v2
with:
name: tox-gh
path: dist
37 changes: 0 additions & 37 deletions .github/workflows/packaging.yml

This file was deleted.

18 changes: 10 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ repos:
hooks:
- id: tox-ini-fmt
- repo: https://github.com/PyCQA/flake8
rev: "3.9.2"
rev: 3.9.2
hooks:
- id: flake8
additional_dependencies: [
"flake8-bugbear == 21.4.3",
"flake8-unused-arguments == 0.0.6",
"flake8-comprehensions == 3.5.0",
"flake8-spellcheck == 0.24.0",
"flake8-pytest-style == 1.4.2",
]
additional_dependencies:
- flake8-bugbear==21.9.1
- flake8-comprehensions==3.6.1
- flake8-pytest-style==1.5
- flake8-spellcheck==0.24
- flake8-unused-arguments==0.0.6
- flake8-noqa==1.1.0
- flake8-eradicate==1.1.0
- pep8-naming==0.12.1
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ project_urls =
[options]
packages = find:
install_requires =
tox@git+https://github.com/gaborbernat/tox.git@2021
tox>=4.0.0a9
python_requires = >=3.6
include_package_data = True
package_dir =
Expand Down
56 changes: 15 additions & 41 deletions src/tox_gh/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,64 +5,41 @@
from typing import Dict, List

from tox.config.loader.memory import MemoryLoader
from tox.config.loader.section import Section
from tox.config.main import Config
from tox.config.sets import ConfigSet
from tox.config.types import EnvList
from tox.plugin import impl
from virtualenv.discovery.py_info import PythonInfo


class GhActionsConfigSet(ConfigSet):
SECTION = "gh"

def __init__(self, conf: Config):
super().__init__(conf)
self.add_config("python", of_type=Dict[str, EnvList], default={}, desc="python version to mapping")


def is_running_on_actions() -> bool:
"""Returns True when running on GitHub Actions"""
""":return: True if running on Github Actions platform"""
# https://docs.github.com/en/actions/reference/environment-variables#default-environment-variables
return os.environ.get("GITHUB_ACTIONS") == "true"


def get_python_version_keys() -> List[str]:
"""Get Python version in string for getting factors from gh-action's config
Examples:
- CPython 2.7.z => [2.7, 2]
- CPython 3.8.z => [3.8, 3]
- PyPy 2.7 (v7.3.z) => [pypy-2.7, pypy-2, pypy2]
- PyPy 3.6 (v7.3.z) => [pypy-3.6, pypy-3, pypy3]
- Pyston based on Python CPython 3.8.8 (v2.2) => [pyston-3.8, pyston-3]
Support of "pypy2" and "pypy3" is for backward compatibility with
tox-gh v2.2.0 and before.
"""
""":return: python spec for the python interpreter"""
python_exe = shutil.which("python") or sys.executable
info = PythonInfo.from_exe(exe=python_exe)
major_version = str(info.version_info[0])
major_minor_version = ".".join([str(i) for i in info.version_info[:2]])
if "PyPy" == info.implementation:
return [
f"pypy-{major_minor_version}",
f"pypy-{major_version}",
f"pypy{major_version}",
]
return [f"pypy-{major_minor_version}", f"pypy-{major_version}", f"pypy{major_version}"]
elif hasattr(sys, "pyston_version_info"): # Pyston
return [
f"piston-{major_minor_version}",
f"pyston-{major_version}",
]
return [f"piston-{major_minor_version}", f"pyston-{major_version}"]
else: # Assume this is running on CPython
return [
major_minor_version,
major_version,
]
return [major_minor_version, major_version]


class GhActionsConfigSet(ConfigSet):
def register_config(self) -> None:
self.add_config("python", of_type=Dict[str, EnvList], default={}, desc="python version to mapping")


@impl
def tox_configure(config: Config) -> None:
def tox_add_core_config(core_conf: ConfigSet, config: "Config") -> None: # noqa: U100
bail_reason = None
if not is_running_on_actions():
bail_reason = "tox is not running in GitHub Actions"
Expand All @@ -71,15 +48,12 @@ def tox_configure(config: Config) -> None:
if bail_reason:
logging.warning("tox-gh won't override envlist because %s", bail_reason)
return
logging.warning("running tox-gh")

# read the configuration file - gh section in config file
gh_config = config.get_section_config(GhActionsConfigSet.SECTION, GhActionsConfigSet)
logging.warning("running tox-gh")
gh_config = config.get_section_config(Section(None, "gh"), base=[], of_type=GhActionsConfigSet, for_env=None)
python_mapping: Dict[str, EnvList] = gh_config["python"]

py_info = get_python_version_keys()

env_list = next((python_mapping[i] for i in py_info if i in python_mapping), None)
env_list = next((python_mapping[i] for i in get_python_version_keys() if i in python_mapping), None)
if env_list is not None: # override the env_list core configuration with our values
logging.warning("tox-gh set %s", ", ".join(env_list))
config.core.loaders.insert(0, MemoryLoader(env_list=env_list))

0 comments on commit cfc61a0

Please sign in to comment.