Skip to content

Commit

Permalink
Add Github Actions and derive version from git tags (Instagram#471)
Browse files Browse the repository at this point in the history
* Use setuptools-scm to derive the current version from git metadata

* Add Github Action equivalent to the current circleci tasks

* Run pyre integration test in GH action / tox
  • Loading branch information
lpetre committed Aug 10, 2021
1 parent ce6174a commit b30d3d2
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 52 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/.pyre_configuration
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"source_directories": [
"."
],
"search_path": [
"stubs", "~/cache/tox/pyre/lib/python3.8/site-packages/"
],
"strict": true
}
88 changes: 88 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Python CI

on: [push, pull_request]

env:
PIP_CACHE_DIR: ~/cache/pip

jobs:
tox:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
python-version: [3.6, 3.7, 3.8]
environment: [test]
include:
- os: ubuntu-latest
python-version: 3.8
environment: lint
- os: ubuntu-latest
python-version: 3.8
environment: docs
- os: ubuntu-latest
python-version: 3.8
environment: coverage
- os: ubuntu-latest
python-version: 3.8
environment: pyre
steps:
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: pip cache
uses: actions/cache@v2
id: cache
with:
path: '~/cache'
key: pip-${{ matrix.os }}-${{ matrix.python-version }}-${{ matrix.environment }}-${{ hashFiles('tox.ini', 'requirements.txt', 'requirements-dev.txt', 'setup.py') }}
restore-keys: |
pip-${{ matrix.os }}-${{ matrix.python-version }}-${{ matrix.environment }}-
pip-${{ matrix.os }}-${{ matrix.python-version }}-
pip-${{ matrix.os }}-
- name: install tox
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions -r requirements.txt -r requirements-dev.txt
- name: run tox
run: tox --workdir ~/cache/tox -e ${{ matrix.environment }}
- name: Archive Docs
if: matrix.environment == 'docs'
uses: actions/upload-artifact@v2
with:
name: sphinx-docs
path: docs/build
- name: Archive Coverage
if: matrix.environment == 'coverage'
uses: actions/upload-artifact@v2
with:
name: coverage
path: coverage.xml

# Build python package
build:
needs: tox
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install pypa/build
run: >-
python -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
*.pyc
*.pyo
*.egg-info/
.eggs/
.pyre/
__pycache__/
.tox/
docs/build/
dist/
docs/source/.ipynb_checkpoints/
build/
libcst/_version.py
.coverage
.hypothesis/
.pyre_configuration
Expand Down
7 changes: 6 additions & 1 deletion libcst/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,13 @@
PartialParserConfig,
)
from libcst._removal_sentinel import RemovalSentinel, RemoveFromParent
from libcst._version import LIBCST_VERSION
from libcst._visitors import CSTNodeT, CSTTransformer, CSTVisitor, CSTVisitorT


try:
from libcst._version import version as LIBCST_VERSION
except ImportError:
LIBCST_VERSION = "unknown"
from libcst.helpers import ( # from libcst import ensure_type is deprecated, will be removed in 0.4.0
ensure_type,
)
Expand Down
7 changes: 0 additions & 7 deletions libcst/_version.py

This file was deleted.

2 changes: 1 addition & 1 deletion libcst/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ def main(proc_name: str, cli_args: List[str]) -> int:
"--version",
help="Print current version of LibCST toolset.",
action="version",
version=f"LibCST version {LIBCST_VERSION}",
version=f"LibCST version {LIBCST_VERSION}", # pyre-ignore[16] pyre bug?
)
parser.add_argument(
"action",
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ pyre-check==0.0.41
sphinx-rtd-theme>=0.4.3
prompt-toolkit>=2.0.9
tox>=3.18.1
setuptools_scm>=6.0.1
27 changes: 9 additions & 18 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,24 @@
# LICENSE file in the root directory of this source tree.


import importlib.util
from os import path
from typing import TYPE_CHECKING

import setuptools


if TYPE_CHECKING:
from importlib.machinery import ModuleSpec
from types import ModuleType

# Grab the readme so that our package stays in sync with github.
this_directory: str = path.abspath(path.dirname(__file__))
with open(path.join(this_directory, "README.rst"), encoding="utf-8") as f:
long_description = f.read()

# Grab the version constant so that libcst.tool stays in sync with this package.
spec: "ModuleSpec" = importlib.util.spec_from_file_location(
"version", path.join(this_directory, "libcst/_version.py")
)
version: "ModuleType" = importlib.util.module_from_spec(spec)
# pyre-ignore Pyre doesn't know about importlib entirely.
spec.loader.exec_module(version)
# pyre-ignore Pyre has no way of knowing that this constant exists.
LIBCST_VERSION = version.LIBCST_VERSION

setuptools.setup(
use_scm_version={
"write_to": "libcst/_version.py",
},
name="libcst",
description="A concrete syntax tree with AST-like properties for Python 3.5, 3.6, 3.7 and 3.8 programs.",
long_description=long_description,
long_description_content_type="text/x-rst",
version=LIBCST_VERSION,
url="https://github.com/Instagram/LibCST",
license="MIT",
packages=setuptools.find_packages(),
Expand All @@ -46,9 +32,14 @@
},
test_suite="libcst",
python_requires=">=3.6",
setup_requires=["setuptools_scm"],
install_requires=[dep.strip() for dep in open("requirements.txt").readlines()],
extras_require={
"dev": [dep.strip() for dep in open("requirements-dev.txt").readlines() if "=" in dep],
"dev": [
dep.strip()
for dep in open("requirements-dev.txt").readlines()
if "=" in dep
],
"native": ["libcst_native==0.1.0"],
},
classifiers=[
Expand Down
47 changes: 22 additions & 25 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
[tox]
envlist = py36, py37, py38, py39, lint, docs
envlist = py36, py37, py38, lint, docs

[gh-actions]
python =
3.6: py36
3.7: py37
3.8: py38

[testenv]
deps =
Expand All @@ -8,37 +14,27 @@ deps =
commands =
python -m unittest {posargs}

[testenv:test]

[testenv:lint]
deps =
-rrequirements.txt
-rrequirements-dev.txt
commands =
flake8 {posargs}
isort --check-only {posargs:.}
black --check {posargs:libcst/}
python3 -m fixit.cli.run_rules

[testenv:docs]
deps =
-rrequirements.txt
-rrequirements-dev.txt
commands =
sphinx-build {posargs:docs/source/ docs/build/}

[testenv:autofix]
deps =
-rrequirements.txt
-rrequirements-dev.txt
commands =
flake8 {posargs}
isort -q {posargs:.}
black {posargs:libcst/}
python3 -m fixit.cli.apply_fix

[testenv:coverage]
deps =
-rrequirements.txt
-rrequirements-dev.txt
passenv =
CI
CIRCLECI
Expand All @@ -47,40 +43,41 @@ commands =
coverage run setup.py test
codecov

[testenv:pyre]
usedevelop=True
setenv = PYTHONPATH = {toxinidir}
allowlist_externals=
cp
commands =
cp .github/workflows/.pyre_configuration .
pyre --version
pyre check
python libcst/tests/test_pyre_integration.py
git diff --exit-code

[testenv:fuzz36]
basepython = python3.6
deps =
-rrequirements.txt
-rrequirements-dev.txt
setenv =
HYPOTHESIS = 1
commands =
python3.6 -m unittest libcst/tests/test_fuzz.py

[testenv:fuzz37]
basepython = python3.7
deps =
-rrequirements.txt
-rrequirements-dev.txt
setenv =
HYPOTHESIS = 1
commands =
python3.7 -m unittest libcst/tests/test_fuzz.py

[testenv:fuzz38]
basepython = python3.8
deps =
-rrequirements.txt
-rrequirements-dev.txt
setenv =
HYPOTHESIS = 1
commands =
python3.8 -m unittest libcst/tests/test_fuzz.py


[testenv:codegen]
deps =
-rrequirements.txt
-rrequirements-dev.txt
commands =
python3 -m libcst.codegen.generate visitors
python3 -m libcst.codegen.generate return_types
Expand Down

0 comments on commit b30d3d2

Please sign in to comment.