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

Use Github actions to replace Travis for CI #123

Open
wants to merge 1 commit 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
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: build

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-18.04
strategy:
matrix:
python-version: ['2.7','3.6']

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

- name: Install Dependencies
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.

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

pep8:
@flake8 codemod --ignore=F403
@flake8 codemod --ignore=F403,W503,W504

release: test
@python setup.py sdist upload
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ 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)
[![build](https://github.com/facebook/codemod/workflows/build/badge.svg?branch=master)](https://github.com/facebook/codemod/actions?query=workflow%3Abuild)
[![Code Health](https://landscape.io/github/rochacbruno/codemod/master/landscape.svg?style=flat)](https://landscape.io/github/rochacbruno/codemod/master)


Expand Down
14 changes: 8 additions & 6 deletions codemod/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def line_transformation_suggestor(line_transformation, line_filter=None):
a line is ignored (as if line_transformation
returned the line itself for that line).
"""

def suggestor(lines):
for line_number, line in enumerate(lines):
if line_filter and not line_filter(line):
Expand All @@ -116,6 +117,7 @@ def suggestor(lines):
yield Patch(line_number)
else:
yield Patch(line_number, new_lines=[candidate])

return suggestor


Expand Down Expand Up @@ -228,8 +230,8 @@ def print_patch(patch, lines_to_print, file_lines=None):

def print_file_line(line_number): # noqa
# Why line_number is passed here?
print(' %s' % file_lines[i], end='') if (
0 <= i < len(file_lines)) else '~\n',
print(' %s' % file_lines[i], end='') if (0 <= i < len(file_lines))\
else '~\n',

for i in range(start_context_line_number, patch.start_line_number):
print_file_line(i)
Expand Down Expand Up @@ -427,8 +429,8 @@ def _parse_command_line():
'matching.')
parser.add_argument('--include-extensionless', action='store_true',
help='If set, this will check files without '
'an extension, along with any matching file '
'extensions passed in --extensions')
'an extension, along with any matching file '
'extensions passed in --extensions')
parser.add_argument('--exclude-paths', action='store', type=str,
help='A comma-delimited list of paths to exclude.')

Expand All @@ -442,8 +444,8 @@ def _parse_command_line():

parser.add_argument('--editor', action='store', type=str,
help='Specify an editor, e.g. "vim" or emacs". '
'If omitted, defaults to $EDITOR environment '
'variable.')
'If omitted, defaults to $EDITOR environment '
'variable.')
parser.add_argument('--count', action='store_true',
help='Don\'t run normally. Instead, just print '
'out number of times places in the codebase '
Expand Down
1 change: 1 addition & 0 deletions codemod/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,5 @@ def the_filter(path):
fnmatch.fnmatch(path, excluded)):
return False
return True

return the_filter
1 change: 1 addition & 0 deletions codemod/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,5 @@ def render_range(self):

def get_start_position(self):
return Position(self.path, self.start_line_number)

start_position = property(get_start_position)
11 changes: 5 additions & 6 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 Down Expand Up @@ -76,6 +77,7 @@ def _get_position(self, attr_name):

def get_start_position(self):
return self._get_position('_start')

start_position = property(get_start_position)

@start_position.setter
Expand All @@ -84,6 +86,7 @@ def start_position(self, value):

def get_end_position(self):
return self._get_position('_end')

end_position = property(get_end_position)

@end_position.setter
Expand Down Expand Up @@ -207,9 +210,5 @@ def _path_looks_like_code(path):
>>> Query._path_looks_like_code('/home/jrosenstein/www/.git/HEAD')
False
"""
return (
'/.' not in path and
path[-1] != '~' and
not path.endswith('tags') and
not path.endswith('TAGS')
)
return ('/.' not in path and path[-1] != '~' and not
path.endswith('tags') and not path.endswith('TAGS'))
20 changes: 9 additions & 11 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 type(s) == bytes:
return s.decode(encoding, 'ignore')
else:
return str(s)


def terminal_get_size(default_size=(25, 80)):
Expand Down Expand Up @@ -100,13 +100,11 @@ def color_code(set_capability, possible_colors):
if not set_code:
return None
return curses.tparm(set_code, color_index)
code = (
color_code(
'setaf', 'BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE'
) or color_code(
'setf', 'BLACK BLUE GREEN CYAN RED MAGENTA YELLOW WHITE'
)
)

code = (color_code('setaf', 'BLACK RED GREEN YELLOW BLUE MAGENTA CYAN'
' WHITE') or
color_code('setf', 'BLACK BLUE GREEN CYAN RED MAGENTA YELLOW'
' WHITE'))
if code:
code = _unicode(code)
sys.stdout.write(code)
Expand Down