From c7c36f2cd2fb6cb3c0ba4f8131ac49a9bb369675 Mon Sep 17 00:00:00 2001 From: Aarif Date: Sat, 28 Nov 2020 15:16:54 +0500 Subject: [PATCH] Added a github workflow to run tests for CI --- .github/workflows/ci.yml | 28 ++++++++++++++++++++++++++++ .travis.yml | 10 ---------- Makefile | 2 +- README.md | 2 +- codemod/base.py | 14 ++++++++------ codemod/helpers.py | 1 + codemod/patch.py | 1 + codemod/query.py | 11 +++++------ codemod/terminal_helper.py | 20 +++++++++----------- 9 files changed, 54 insertions(+), 35 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..6285874 --- /dev/null +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 12ef4ad..0000000 --- a/.travis.yml +++ /dev/null @@ -1,10 +0,0 @@ -language: python - -python: - - "2.7" - - "3.6" - -install: - - "pip install -r dev-requirements.txt" -script: make test - diff --git a/Makefile b/Makefile index c0a0063..fe73bd0 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/README.md b/README.md index dbee93a..47d5911 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/codemod/base.py b/codemod/base.py index 7ddd456..41a2139 100755 --- a/codemod/base.py +++ b/codemod/base.py @@ -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): @@ -116,6 +117,7 @@ def suggestor(lines): yield Patch(line_number) else: yield Patch(line_number, new_lines=[candidate]) + return suggestor @@ -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) @@ -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.') @@ -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 ' diff --git a/codemod/helpers.py b/codemod/helpers.py index f0070c4..d004d20 100644 --- a/codemod/helpers.py +++ b/codemod/helpers.py @@ -89,4 +89,5 @@ def the_filter(path): fnmatch.fnmatch(path, excluded)): return False return True + return the_filter diff --git a/codemod/patch.py b/codemod/patch.py index 35664db..1b17760 100644 --- a/codemod/patch.py +++ b/codemod/patch.py @@ -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) diff --git a/codemod/query.py b/codemod/query.py index 71129c3..e09fd88 100644 --- a/codemod/query.py +++ b/codemod/query.py @@ -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, @@ -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 @@ -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 @@ -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')) diff --git a/codemod/terminal_helper.py b/codemod/terminal_helper.py index 3443dc8..525f91c 100644 --- a/codemod/terminal_helper.py +++ b/codemod/terminal_helper.py @@ -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)): @@ -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)