From 3fb563dfaab3e9298f80380e884a53091749c2a7 Mon Sep 17 00:00:00 2001 From: Hui Chen Date: Wed, 22 Sep 2021 14:38:17 -0400 Subject: [PATCH 01/11] added the newline parameter to PatchSet::from_filename and a test case and test diff file --- tests/samples/git_cr.diff | 9 +++++++++ tests/test_parser.py | 11 +++++++++++ unidiff/patch.py | 4 ++-- 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 tests/samples/git_cr.diff diff --git a/tests/samples/git_cr.diff b/tests/samples/git_cr.diff new file mode 100644 index 0000000..c7e39a4 --- /dev/null +++ b/tests/samples/git_cr.diff @@ -0,0 +1,9 @@ +diff --git a/src/test/org/apache/commons/math/util/ExpandableDoubleArrayTest.java b/src/test/org/apache/commons/math/util/ExpandableDoubleArrayTest.java +new file mode 100644 +index 000000000..2b38fa232 +--- /dev/null ++++ b/a.txt +@@ -0,0 +1,3 @@ ++ "This line is broken into two lines by CR. " + "but it should be treated as one line in the text diff file" ++ "This has no CR" ++ "This line also has CR. " + "but it should also be treated as one line in the text diff file". diff --git a/tests/test_parser.py b/tests/test_parser.py index 964dbc6..c9515b8 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -231,6 +231,17 @@ def test_parse_malformed_diff_shorter_than_expected(self): with open(utf8_file, 'r') as diff_file: self.assertRaises(UnidiffParseError, PatchSet, diff_file) + def test_from_filename_with_cr_in_diff_text_files(self): + """Parse git diff text files that contain CR""" + utf8_file = os.path.join(self.samples_dir, 'samples/git_cr.diff') + self.assertRaises(UnidiffParseError, PatchSet.from_filename, utf8_file) + + ps1 = PatchSet.from_filename(utf8_file, newline='\n') + with open(utf8_file, 'r', newline='\n') as diff_file: + ps2 = PatchSet(diff_file) + + self.assertEqual(ps1, ps2) + def test_parse_diff_with_new_and_modified_binary_files(self): """Parse git diff file with newly added and modified binaries files.""" utf8_file = os.path.join(self.samples_dir, 'samples/sample8.diff') diff --git a/unidiff/patch.py b/unidiff/patch.py index 16834d2..d332615 100644 --- a/unidiff/patch.py +++ b/unidiff/patch.py @@ -557,10 +557,10 @@ def _parse(self, diff, encoding, metadata_only): patch_info.append(line) @classmethod - def from_filename(cls, filename, encoding=DEFAULT_ENCODING, errors=None): + def from_filename(cls, filename, encoding=DEFAULT_ENCODING, errors=None, newline=None): # type: (str, str, Optional[str]) -> PatchSet """Return a PatchSet instance given a diff filename.""" - with open_file(filename, 'r', encoding=encoding, errors=errors) as f: + with open_file(filename, 'r', encoding=encoding, errors=errors, newline=newline) as f: instance = cls(f) return instance From abdeb52c549ea9317bed2bdbb8830304992bb79a Mon Sep 17 00:00:00 2001 From: huichen-cs Date: Wed, 6 Oct 2021 15:45:32 -0400 Subject: [PATCH 02/11] Create main.yml --- .github/workflows/main.yml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..bdef057 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,36 @@ +# This is a basic workflow to help you get started with Actions + +name: CI + +# Controls when the workflow will run +on: + # Triggers the workflow on push or pull request events but only for the master branch + push: + branches: [ master ] + pull_request: + branches: [ master ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: self-hosted + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + + # Runs a single command using the runners shell + - name: Run a one-line script + run: echo Hello, world! + + # Runs a set of commands using the runners shell + - name: Run a multi-line script + run: | + echo Add other actions to build, + echo test, and deploy your project. From 349a61f38b5fa450bfe304b698cda119e32fe538 Mon Sep 17 00:00:00 2001 From: huichen-cs Date: Wed, 6 Oct 2021 16:39:01 -0400 Subject: [PATCH 03/11] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bdef057..8c554fd 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -27,7 +27,7 @@ jobs: # Runs a single command using the runners shell - name: Run a one-line script - run: echo Hello, world! + run: ./run_tests.sh # Runs a set of commands using the runners shell - name: Run a multi-line script From 05ea04ba8c7422f4d10840d4639d7582e4fcc53b Mon Sep 17 00:00:00 2001 From: huichen-cs Date: Wed, 6 Oct 2021 16:45:42 -0400 Subject: [PATCH 04/11] Update main.yml --- .github/workflows/main.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8c554fd..1f029d2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -27,7 +27,8 @@ jobs: # Runs a single command using the runners shell - name: Run a one-line script - run: ./run_tests.sh + run: $GITHUB_WORKSPACE/run_tests.sh + shell: bash # Runs a set of commands using the runners shell - name: Run a multi-line script From 9411f2fcbc7d8af90c5622dabe02ff1864c48ea1 Mon Sep 17 00:00:00 2001 From: huichen-cs Date: Wed, 6 Oct 2021 16:51:41 -0400 Subject: [PATCH 05/11] Update main.yml --- .github/workflows/main.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1f029d2..cac951e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -24,7 +24,10 @@ jobs: steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v2 - + - uses: actions/setup-python@v2 + with: + python-version: '3.x' # Version range or exact version of a Python version to use, using SemVer's version range syntax + architecture: 'x64' # optional x64 or x86. Defaults to x64 if not specified # Runs a single command using the runners shell - name: Run a one-line script run: $GITHUB_WORKSPACE/run_tests.sh From 014a03ea9285e268ffbe9341c3e3758b6147c73b Mon Sep 17 00:00:00 2001 From: huichen-cs Date: Wed, 6 Oct 2021 17:02:48 -0400 Subject: [PATCH 06/11] Update main.yml --- .github/workflows/main.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cac951e..6b1377d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -19,14 +19,17 @@ jobs: build: # The type of runner that the job will run on runs-on: self-hosted - + strategy: + matrix: + python-version: [ '2.x', '3.x'] + # Steps represent a sequence of tasks that will be executed as part of the job steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v2 - uses: actions/setup-python@v2 with: - python-version: '3.x' # Version range or exact version of a Python version to use, using SemVer's version range syntax + python-version: ${{ matrix.python-version }} architecture: 'x64' # optional x64 or x86. Defaults to x64 if not specified # Runs a single command using the runners shell - name: Run a one-line script From 6926d016ab2b9ff70559bba1f16a03b1c62701ba Mon Sep 17 00:00:00 2001 From: huichen-cs Date: Wed, 6 Oct 2021 17:06:45 -0400 Subject: [PATCH 07/11] Update main.yml --- .github/workflows/main.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6b1377d..53901c3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,7 +22,8 @@ jobs: strategy: matrix: python-version: [ '2.x', '3.x'] - + fail-fast: false + # Steps represent a sequence of tasks that will be executed as part of the job steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it From 7d57e859f0d740c1c8eb70518627abf0231006b6 Mon Sep 17 00:00:00 2001 From: huichen-cs Date: Wed, 6 Oct 2021 17:08:08 -0400 Subject: [PATCH 08/11] Update patch.py --- unidiff/patch.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/unidiff/patch.py b/unidiff/patch.py index d332615..4dfb42d 100644 --- a/unidiff/patch.py +++ b/unidiff/patch.py @@ -52,8 +52,10 @@ PY2 = sys.version_info[0] == 2 if PY2: + import io from StringIO import StringIO - open_file = codecs.open + # open_file = codecs.open + open_file = io.open make_str = lambda x: x.encode(DEFAULT_ENCODING) def implements_to_string(cls): From 2631cb0930900663d142739ebc6db7b044ac8bdb Mon Sep 17 00:00:00 2001 From: huichen-cs Date: Wed, 6 Oct 2021 17:11:03 -0400 Subject: [PATCH 09/11] Update test_parser.py --- tests/test_parser.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_parser.py b/tests/test_parser.py index c9515b8..e078c33 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -237,7 +237,8 @@ def test_from_filename_with_cr_in_diff_text_files(self): self.assertRaises(UnidiffParseError, PatchSet.from_filename, utf8_file) ps1 = PatchSet.from_filename(utf8_file, newline='\n') - with open(utf8_file, 'r', newline='\n') as diff_file: + import io + with io.open(utf8_file, 'r', newline='\n') as diff_file: ps2 = PatchSet(diff_file) self.assertEqual(ps1, ps2) From 40adadca489d2f22cf2f6077dddc0d6a97b7c2f9 Mon Sep 17 00:00:00 2001 From: Hui Chen Date: Wed, 27 Oct 2021 12:57:29 -0400 Subject: [PATCH 10/11] removed a useless runner command from the Github Actions --- .github/workflows/main.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 53901c3..cdd2323 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -37,8 +37,3 @@ jobs: run: $GITHUB_WORKSPACE/run_tests.sh shell: bash - # Runs a set of commands using the runners shell - - name: Run a multi-line script - run: | - echo Add other actions to build, - echo test, and deploy your project. From 57f14e107e10166da23bec13fda8b684991e3710 Mon Sep 17 00:00:00 2001 From: Hui Chen Date: Wed, 27 Oct 2021 16:22:59 -0400 Subject: [PATCH 11/11] specify python version 2.7 and 3.6-3.9 and cleaned configuration file for github actions --- .github/workflows/main.yml | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cdd2323..67911ee 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,39 +1,28 @@ -# This is a basic workflow to help you get started with Actions - name: CI -# Controls when the workflow will run on: - # Triggers the workflow on push or pull request events but only for the master branch push: branches: [ master ] pull_request: branches: [ master ] - # Allows you to run this workflow manually from the Actions tab workflow_dispatch: -# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - # This workflow contains a single job called "build" build: - # The type of runner that the job will run on runs-on: self-hosted strategy: matrix: - python-version: [ '2.x', '3.x'] + python-version: [ '2.7', '3.6', '3.7', '3.8', '3.9' ] fail-fast: false - # Steps represent a sequence of tasks that will be executed as part of the job steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v2 - uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - architecture: 'x64' # optional x64 or x86. Defaults to x64 if not specified - # Runs a single command using the runners shell - - name: Run a one-line script + architecture: 'x64' + - name: 'Run Tests' run: $GITHUB_WORKSPACE/run_tests.sh shell: bash