Skip to content
This repository has been archived by the owner on Jun 10, 2021. It is now read-only.

Use GitHub Actions instead #120

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: CodeQL

on:
pull_request:
push:
schedule:
- cron: 0 0 * * 0

jobs:
codeql:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 2

- name: Checkout the head of the pull request instead
run: git checkout HEAD^2
if: ${{ github.event_name == 'pull_request' }}

- name: Initialize CodeQL
uses: github/codeql-action/init@v1

- name: Autobuild
uses: github/codeql-action/autobuild@v1

- name: Perform CodeQL analysis
uses: github/codeql-action/analyze@v1
32 changes: 32 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Main workflow

on:
- pull_request
- push

jobs:
build:
strategy:
matrix:
os:
- ubuntu-latest
python-version:
- 2.7
- 3.9

runs-on: ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Use Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install packages
run: pip install -r dev-requirements.txt

- name: Run tests
run: make test
10 changes: 0 additions & 10 deletions .travis.yml

This file was deleted.

8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ install:
python setup.py develop

pep8:
@flake8 codemod --ignore=F403
# W503: Line break occurred before a binary operator
# W504: Line break occurred after a binary operator
#
# W503 conflicts with W504, but since W504 is now the recommended style, we
# intentionally ignore it.
# https://www.python.org/dev/peps/pep-0008/#should-a-line-break-before-or-after-a-binary-operator
@flake8 codemod --ignore=W503

release: test
@python setup.py sdist upload
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ codemod

[![PyPI](https://img.shields.io/pypi/v/codemod.svg)](https://pypi.python.org/pypi/codemod)
[![downloads](https://img.shields.io/pypi/dw/codemod.svg)](https://pypi.python.org/pypi/codemod)
[![Travis CI](http://img.shields.io/travis/facebook/codemod.svg)](https://travis-ci.org/facebook/codemod)
[![Main workflow](https://github.com/facebook/codemod/workflows/Main%20workflow/badge.svg?branch=master)](https://github.com/facebook/codemod/actions)
[![CodeQL](https://github.com/facebook/codemod/workflows/CodeQL/badge.svg?branch=master)](https://github.com/facebook/codemod/actions)
[![Code Health](https://landscape.io/github/rochacbruno/codemod/master/landscape.svg?style=flat)](https://landscape.io/github/rochacbruno/codemod/master)


Expand Down
8 changes: 4 additions & 4 deletions codemod/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,11 @@ def _ask_about_patch(patch, editor, default_no):
if patch.new_lines is not None:
if not yes_to_all:
if default_no:
print('Accept change (y = yes, n = no [default], e = edit, ' +
'A = yes to all, E = yes+edit, q = quit)? '),
print('Accept change (y = yes, n = no [default], e = edit, '
+ 'A = yes to all, E = yes+edit, q = quit)? '),
else:
print('Accept change (y = yes [default], n = no, e = edit, ' +
'A = yes to all, E = yes+edit, q = quit)? '),
print('Accept change (y = yes [default], n = no, e = edit, '
+ 'A = yes to all, E = yes+edit, q = quit)? '),
p = _prompt('yneEAq', default=default_action)
else:
p = 'y'
Expand Down
6 changes: 3 additions & 3 deletions codemod/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ def the_filter(path):
return False
if exclude_paths:
for excluded in exclude_paths:
if (path.startswith(excluded) or
path.startswith('./' + excluded) or
fnmatch.fnmatch(path, excluded)):
if (path.startswith(excluded)
or path.startswith('./' + excluded)
or fnmatch.fnmatch(path, excluded)):
return False
return True
return the_filter
23 changes: 11 additions & 12 deletions codemod/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Query(object):
>>> Query(lambda x: None, start='profile.php:20').start_position
Position('profile.php', 20)
"""

def __init__(self,
suggestor,
start=None,
Expand All @@ -22,7 +23,6 @@ def __init__(self,
extensions=['php', 'phpt', 'js', 'css', 'rb', 'erb']
),
inc_extensionless=False):

"""
@param suggestor A function that takes a list of lines and
generates instances of Patch to suggest.
Expand Down Expand Up @@ -138,9 +138,9 @@ def generate_patches(self):
path_list = Query._sublist(path_list, start_pos.path, end_pos.path)
path_list = (
path for path in path_list if
Query._path_looks_like_code(path) and
(self.path_filter(path)) or
(self.inc_extensionless and helpers.is_extensionless(path))
Query._path_looks_like_code(path)
and (self.path_filter(path))
or (self.inc_extensionless and helpers.is_extensionless(path))
)
for path in path_list:
try:
Expand Down Expand Up @@ -173,10 +173,9 @@ def _walk_directory(root_directory):
of `root_directory`.
"""

paths = [os.path.join(root, name)
for root, dirs, files in os.walk(root_directory) # noqa
for name in files]
paths.sort()
paths = sorted([os.path.join(root, name)
for root, dirs, files in os.walk(root_directory)
for name in files])
return paths

@staticmethod
Expand Down Expand Up @@ -208,8 +207,8 @@ def _path_looks_like_code(path):
False
"""
return (
'/.' not in path and
path[-1] != '~' and
not path.endswith('tags') and
not path.endswith('TAGS')
'/.' not in path
and path[-1] != '~'
and not path.endswith('tags')
and not path.endswith('TAGS')
)
8 changes: 4 additions & 4 deletions codemod/terminal_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@


def _unicode(s, encoding='utf-8'):
if type(s) == bytes:
return s.decode(encoding, 'ignore')
else:
return str(s)
if isinstance(s, bytes):
return s.decode(encoding, 'ignore')
else:
return str(s)


def terminal_get_size(default_size=(25, 80)):
Expand Down