-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from deadsnakes/yaml_action
port action to python instead of js
- Loading branch information
Showing
11 changed files
with
127 additions
and
3,767 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,34 @@ | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v3.1.0 | ||
rev: v3.2.0 | ||
hooks: | ||
- id: check-json | ||
- id: check-yaml | ||
- id: trailing-whitespace | ||
- id: end-of-file-fixer | ||
- repo: https://github.com/pre-commit/mirrors-eslint | ||
rev: v7.0.0 | ||
- repo: https://gitlab.com/pycqa/flake8 | ||
rev: 3.8.3 | ||
hooks: | ||
- id: eslint | ||
args: [--fix] | ||
- id: flake8 | ||
- repo: https://github.com/pre-commit/mirrors-autopep8 | ||
rev: v1.5.4 | ||
hooks: | ||
- id: autopep8 | ||
- repo: https://github.com/asottile/reorder_python_imports | ||
rev: v2.3.5 | ||
hooks: | ||
- id: reorder-python-imports | ||
args: [--py3-plus] | ||
- repo: https://github.com/asottile/add-trailing-comma | ||
rev: v2.0.1 | ||
hooks: | ||
- id: add-trailing-comma | ||
args: [--py36-plus] | ||
- repo: https://github.com/asottile/pyupgrade | ||
rev: v2.7.2 | ||
hooks: | ||
- id: pyupgrade | ||
args: [--py36-plus] | ||
- repo: https://github.com/pre-commit/mirrors-mypy | ||
rev: v0.782 | ||
hooks: | ||
- id: mypy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#!/usr/bin/env python3 | ||
import argparse | ||
import contextlib | ||
import os.path | ||
import shlex | ||
import subprocess | ||
from typing import Generator | ||
from typing import NamedTuple | ||
from typing import Tuple | ||
|
||
|
||
class Group(NamedTuple): | ||
section: str | ||
cmds: Tuple[Tuple[str, ...], ...] | ||
|
||
@classmethod | ||
def make(cls, section: str, *cmds: Tuple[str, ...]) -> 'Group': | ||
return cls(section, cmds) | ||
|
||
|
||
@contextlib.contextmanager | ||
def _group(s: str) -> Generator[None, None, None]: | ||
print(f'::group::{s}') | ||
try: | ||
yield | ||
finally: | ||
print('::endgroup::') | ||
|
||
|
||
def _print_call(*args: str) -> int: | ||
cmd = ' '.join(shlex.quote(arg) for arg in args) | ||
print(f'[command] {cmd}', flush=True) | ||
return subprocess.call(args) | ||
|
||
|
||
def main() -> int: | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('version') | ||
args = parser.parse_args() | ||
|
||
if args.version.endswith('-dev'): | ||
version = args.version[:-1 * len('-dev')] | ||
ppa = 'ppa:deadsnakes/nightly' | ||
else: | ||
version = args.version | ||
ppa = 'ppa:deadsnakes/ppa' | ||
|
||
py = f'python{version}' | ||
packages = [f'{py}-dev', f'{py}-venv'] | ||
if float(version) >= 3.9: | ||
packages.append(f'{py}-distutils') | ||
else: | ||
packages.append('python3-distutils') | ||
|
||
envdir = os.path.expanduser(f'~/venv-{version}') | ||
bindir = os.path.join(envdir, 'bin') | ||
pip = os.path.join(bindir, 'pip') | ||
|
||
groups = ( | ||
Group.make( | ||
f'add ppa {ppa}', | ||
('sudo', 'add-apt-repository', '--yes', ppa), | ||
), | ||
Group.make( | ||
f'install {py}', | ||
( | ||
'sudo', 'apt-get', 'install', '-y', '--no-install-recommends', | ||
*packages, | ||
), | ||
), | ||
Group.make( | ||
f'set up {py} environment', | ||
(py, '-mvenv', envdir), | ||
(pip, 'install', '--upgrade', 'pip', 'setuptools', 'wheel'), | ||
), | ||
) | ||
|
||
for group in groups: | ||
with _group(group.section): | ||
for cmd in group.cmds: | ||
if _print_call(*cmd): | ||
return 1 | ||
|
||
print(f'::add-path::{bindir}') | ||
return 0 | ||
|
||
|
||
if __name__ == '__main__': | ||
exit(main()) |
Oops, something went wrong.