From 927d6a34fb9240b47622c0403d20b6f84bc094b5 Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Fri, 26 May 2023 14:25:40 -0400 Subject: [PATCH 01/37] Added git diff --- src/pkgmt/cli.py | 27 +++++++++++++++++++++- src/pkgmt/modified.py | 21 +++++++++++++++++ tests/test_modified.py | 52 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 src/pkgmt/modified.py create mode 100644 tests/test_modified.py diff --git a/src/pkgmt/cli.py b/src/pkgmt/cli.py index 964c6a2..f832ecd 100644 --- a/src/pkgmt/cli.py +++ b/src/pkgmt/cli.py @@ -9,7 +9,7 @@ from pkgmt import new as new_ from pkgmt import dev from pkgmt import formatting - +from pkgmt import modified @click.group() def cli(): @@ -174,3 +174,28 @@ def lint(): if returncode: raise SystemExit("Error linting") + +@cli.command() +@click.option( + "-b", + "--base-branch", + default="main", + help="Base branch to compare against", +) +@click.option( + "-ex", + "--exclude-path", + default=["doc"], + multiple=True, + help="Path to exclude from git diff. Can be used multiple times eg: -p p1 -p p2", +) +@click.option( + "--debug", + is_flag=True, + default=False, + help="Print debug info", +) +def ensure_modified(base_branch, exclude_path,debug): + """Check if a branch has modified anything excluding some path/dir""" + returncode = modified.check_modified(base_branch, exclude_path, debug=debug) + print(returncode) \ No newline at end of file diff --git a/src/pkgmt/modified.py b/src/pkgmt/modified.py new file mode 100644 index 0000000..0628059 --- /dev/null +++ b/src/pkgmt/modified.py @@ -0,0 +1,21 @@ +import subprocess + +def check_modified(base_branch, exclude_path, debug=False): + # https://stackoverflow.com/questions/4380945 + cmd = f"git diff --exit-code {base_branch}... -- ." + + for path in exclude_path: + cmd += f" :^{path}" + + if debug: + print(f'cmd: {cmd}') + try: + subprocess.check_output(cmd, shell=True) + return 0 + except subprocess.CalledProcessError as err: + if debug: + print(f"Path has been modified with respect to '{base_branch}'\n" + f"Excluding paths: {exclude_path}") + print(f"Return code: {err.returncode}") + print(f"Output: {err.output}") + return 1 \ No newline at end of file diff --git a/tests/test_modified.py b/tests/test_modified.py new file mode 100644 index 0000000..4a05314 --- /dev/null +++ b/tests/test_modified.py @@ -0,0 +1,52 @@ +import pytest +import subprocess + +from pkgmt import modified + +@pytest.fixture(scope="session", autouse=True) +def setup(): + # fixture setup code + # Creates a git branch, adds a file and commits it + cmd = """ + git checkout main; + git checkout -b test_modified_doc; + mkdir -p test_doc1; + touch test_doc1/test_modified.txt; + mkdir -p test_doc2; + touch test_doc2/test_modified.txt; + git add .; + git commit -m "test_modified"; + """ + subprocess.run(cmd, shell=True) + + yield + + # fixture teardown code + # Deletes the git branch + cmd = """ + git checkout main; + git branch -D test_modified; + """ + subprocess.run(cmd, shell=True) + + + +@pytest.mark.parametrize( + "base_branch, exclude_path, returncode", + [ + [ + "main", + ["doc1"], + 1, + ], + [ + "main", + ["doc1","doc2"], + 0, + ] + ] +) +def test_check_modified( base_branch, exclude_path, returncode): + + assert modified.check_modified(base_branch, exclude_path, debug=True) == returncode + # subprocess.run(clean, shell=True) \ No newline at end of file From 43758d895743ac09e332462e42ecb2eb7c4747c8 Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Fri, 26 May 2023 14:30:15 -0400 Subject: [PATCH 02/37] test modified --- tests/test_modified.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_modified.py b/tests/test_modified.py index 4a05314..d0104c2 100644 --- a/tests/test_modified.py +++ b/tests/test_modified.py @@ -36,12 +36,12 @@ def setup(): [ [ "main", - ["doc1"], + ["test_doc1"], 1, ], [ "main", - ["doc1","doc2"], + ["test_doc1","test_doc2"], 0, ] ] From f9977da42faad7fa7273df53fca960a439aaceac Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Fri, 26 May 2023 14:33:20 -0400 Subject: [PATCH 03/37] Fix --- tests/test_modified.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_modified.py b/tests/test_modified.py index d0104c2..3da9646 100644 --- a/tests/test_modified.py +++ b/tests/test_modified.py @@ -25,7 +25,7 @@ def setup(): # Deletes the git branch cmd = """ git checkout main; - git branch -D test_modified; + git branch -D test_modified_doc; """ subprocess.run(cmd, shell=True) From 3a8f70afcaa5a8526ff67317f587dbd0160f5cfb Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Fri, 26 May 2023 14:57:26 -0400 Subject: [PATCH 04/37] Format --- src/pkgmt/cli.py | 6 ++++-- src/pkgmt/modified.py | 11 +++++++---- tests/test_modified.py | 13 ++++++------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/pkgmt/cli.py b/src/pkgmt/cli.py index f832ecd..1e22a83 100644 --- a/src/pkgmt/cli.py +++ b/src/pkgmt/cli.py @@ -11,6 +11,7 @@ from pkgmt import formatting from pkgmt import modified + @click.group() def cli(): pass @@ -175,6 +176,7 @@ def lint(): if returncode: raise SystemExit("Error linting") + @cli.command() @click.option( "-b", @@ -195,7 +197,7 @@ def lint(): default=False, help="Print debug info", ) -def ensure_modified(base_branch, exclude_path,debug): +def ensure_modified(base_branch, exclude_path, debug): """Check if a branch has modified anything excluding some path/dir""" returncode = modified.check_modified(base_branch, exclude_path, debug=debug) - print(returncode) \ No newline at end of file + print(returncode) diff --git a/src/pkgmt/modified.py b/src/pkgmt/modified.py index 0628059..dd80b29 100644 --- a/src/pkgmt/modified.py +++ b/src/pkgmt/modified.py @@ -1,5 +1,6 @@ import subprocess + def check_modified(base_branch, exclude_path, debug=False): # https://stackoverflow.com/questions/4380945 cmd = f"git diff --exit-code {base_branch}... -- ." @@ -8,14 +9,16 @@ def check_modified(base_branch, exclude_path, debug=False): cmd += f" :^{path}" if debug: - print(f'cmd: {cmd}') + print(f"cmd: {cmd}") try: subprocess.check_output(cmd, shell=True) return 0 except subprocess.CalledProcessError as err: if debug: - print(f"Path has been modified with respect to '{base_branch}'\n" - f"Excluding paths: {exclude_path}") + print( + f"Path has been modified with respect to '{base_branch}'\n" + f"Excluding paths: {exclude_path}" + ) print(f"Return code: {err.returncode}") print(f"Output: {err.output}") - return 1 \ No newline at end of file + return 1 diff --git a/tests/test_modified.py b/tests/test_modified.py index 3da9646..483dcbd 100644 --- a/tests/test_modified.py +++ b/tests/test_modified.py @@ -3,6 +3,7 @@ from pkgmt import modified + @pytest.fixture(scope="session", autouse=True) def setup(): # fixture setup code @@ -30,7 +31,6 @@ def setup(): subprocess.run(cmd, shell=True) - @pytest.mark.parametrize( "base_branch, exclude_path, returncode", [ @@ -41,12 +41,11 @@ def setup(): ], [ "main", - ["test_doc1","test_doc2"], + ["test_doc1", "test_doc2"], 0, - ] - ] + ], + ], ) -def test_check_modified( base_branch, exclude_path, returncode): - +def test_check_modified(base_branch, exclude_path, returncode): assert modified.check_modified(base_branch, exclude_path, debug=True) == returncode - # subprocess.run(clean, shell=True) \ No newline at end of file + # subprocess.run(clean, shell=True) From 8f0a8256bb75d9d3788f446c5e07130915d521dc Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Tue, 30 May 2023 10:37:48 -0400 Subject: [PATCH 05/37] Changed API --- src/pkgmt/modified.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/pkgmt/modified.py b/src/pkgmt/modified.py index dd80b29..93b7ef0 100644 --- a/src/pkgmt/modified.py +++ b/src/pkgmt/modified.py @@ -1,4 +1,5 @@ import subprocess +import argparse def check_modified(base_branch, exclude_path, debug=False): @@ -22,3 +23,25 @@ def check_modified(base_branch, exclude_path, debug=False): print(f"Return code: {err.returncode}") print(f"Output: {err.output}") return 1 + + +if __name__ == "__main__": + parser = argparse.ArgumentParser( + description="Check if a branch has modified" "anything excluding some path/dir" + ) + parser.add_argument( + "-b", "--base-branch", default="main", help="Base branch to compare against" + ) + parser.add_argument( + "-ex", + "--exclude-path", + default=["doc"], + nargs="+", + help="Path to exclude from git diff." + "Can be used multiple times eg: -ex p1 -ex p2", + ) + parser.add_argument("--debug", action="store_true", help="Print debug info") + + args = parser.parse_args() + returncode = check_modified(args.base_branch, args.exclude_path, debug=args.debug) + print(returncode) From ce8a4f9a3f08770d945f88b18431244d6be867d4 Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Tue, 30 May 2023 10:38:26 -0400 Subject: [PATCH 06/37] Fix --- src/pkgmt/cli.py | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/src/pkgmt/cli.py b/src/pkgmt/cli.py index 1e22a83..964c6a2 100644 --- a/src/pkgmt/cli.py +++ b/src/pkgmt/cli.py @@ -9,7 +9,6 @@ from pkgmt import new as new_ from pkgmt import dev from pkgmt import formatting -from pkgmt import modified @click.group() @@ -175,29 +174,3 @@ def lint(): if returncode: raise SystemExit("Error linting") - - -@cli.command() -@click.option( - "-b", - "--base-branch", - default="main", - help="Base branch to compare against", -) -@click.option( - "-ex", - "--exclude-path", - default=["doc"], - multiple=True, - help="Path to exclude from git diff. Can be used multiple times eg: -p p1 -p p2", -) -@click.option( - "--debug", - is_flag=True, - default=False, - help="Print debug info", -) -def ensure_modified(base_branch, exclude_path, debug): - """Check if a branch has modified anything excluding some path/dir""" - returncode = modified.check_modified(base_branch, exclude_path, debug=debug) - print(returncode) From 8e8e4098b088405b7a64ec4ab6cfd02aacafffac Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Tue, 30 May 2023 11:26:58 -0400 Subject: [PATCH 07/37] tmp package --- tests/test_modified.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_modified.py b/tests/test_modified.py index 483dcbd..7ba6a24 100644 --- a/tests/test_modified.py +++ b/tests/test_modified.py @@ -46,6 +46,7 @@ def setup(): ], ], ) -def test_check_modified(base_branch, exclude_path, returncode): +def test_check_modified(tmp_package_name,base_branch, exclude_path, returncode): + assert modified.check_modified(base_branch, exclude_path, debug=True) == returncode # subprocess.run(clean, shell=True) From 18a1814f0aff6eb44ce3500c515c17fd17b1b8ec Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Tue, 30 May 2023 11:37:19 -0400 Subject: [PATCH 08/37] Fix tests --- tests/conftest.py | 27 +++++++++++++++++++++++++++ tests/test_modified.py | 33 +-------------------------------- 2 files changed, 28 insertions(+), 32 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 584ffd5..e0e6020 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -57,3 +57,30 @@ def tmp_another_package(root, tmp_empty): yield tmp_empty os.chdir(old) + + +@pytest.fixture +def tmp_package_modi(root, tmp_empty): + old = os.getcwd() + path_to_templates = root / "tests" / "assets" / "package_name" + shutil.copytree(str(path_to_templates), "copy") + os.chdir("copy") + + subprocess.run(["git", "init"]) + subprocess.check_call(["git", "config", "commit.gpgsign", "false"]) + subprocess.check_call(["git", "config", "user.email", "ci@ploomberio"]) + subprocess.check_call(["git", "config", "user.name", "Ploomber"]) + subprocess.run(["git", "add", "--all"]) + subprocess.run(["git", "commit", "-m", "init-commit-message"]) + + subprocess.run(["git", "checkout", "-b", "test_modified_doc"]) + subprocess.run(["mkdir", "-p", "test_doc1"]) + subprocess.run(["touch", "test_doc1/test_modified.txt"]) + subprocess.run(["mkdir", "-p", "test_doc2"]) + subprocess.run(["touch", "test_doc2/test_modified.txt"]) + subprocess.run(["git", "add", "."]) + subprocess.run(["git", "commit", "-m", "test_modified"]) + + yield tmp_empty + + os.chdir(old) diff --git a/tests/test_modified.py b/tests/test_modified.py index 7ba6a24..e5f43fb 100644 --- a/tests/test_modified.py +++ b/tests/test_modified.py @@ -1,36 +1,7 @@ import pytest -import subprocess - from pkgmt import modified -@pytest.fixture(scope="session", autouse=True) -def setup(): - # fixture setup code - # Creates a git branch, adds a file and commits it - cmd = """ - git checkout main; - git checkout -b test_modified_doc; - mkdir -p test_doc1; - touch test_doc1/test_modified.txt; - mkdir -p test_doc2; - touch test_doc2/test_modified.txt; - git add .; - git commit -m "test_modified"; - """ - subprocess.run(cmd, shell=True) - - yield - - # fixture teardown code - # Deletes the git branch - cmd = """ - git checkout main; - git branch -D test_modified_doc; - """ - subprocess.run(cmd, shell=True) - - @pytest.mark.parametrize( "base_branch, exclude_path, returncode", [ @@ -46,7 +17,5 @@ def setup(): ], ], ) -def test_check_modified(tmp_package_name,base_branch, exclude_path, returncode): - +def test_check_modified(tmp_package_modi, base_branch, exclude_path, returncode): assert modified.check_modified(base_branch, exclude_path, debug=True) == returncode - # subprocess.run(clean, shell=True) From 242cf1ac14e4caa74980f60192d278c8f2e782f1 Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Tue, 30 May 2023 11:42:46 -0400 Subject: [PATCH 09/37] Fix test --- tests/conftest.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/conftest.py b/tests/conftest.py index e0e6020..2d8078c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -70,6 +70,7 @@ def tmp_package_modi(root, tmp_empty): subprocess.check_call(["git", "config", "commit.gpgsign", "false"]) subprocess.check_call(["git", "config", "user.email", "ci@ploomberio"]) subprocess.check_call(["git", "config", "user.name", "Ploomber"]) + subprocess.run(["git", "checkout", "-b", "main"]) subprocess.run(["git", "add", "--all"]) subprocess.run(["git", "commit", "-m", "init-commit-message"]) From 92533ded40f99ffeef67369730f282c785b466d0 Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Wed, 31 May 2023 10:45:54 -0400 Subject: [PATCH 10/37] Changed args --- src/pkgmt/modified.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pkgmt/modified.py b/src/pkgmt/modified.py index 93b7ef0..adc28aa 100644 --- a/src/pkgmt/modified.py +++ b/src/pkgmt/modified.py @@ -33,12 +33,12 @@ def check_modified(base_branch, exclude_path, debug=False): "-b", "--base-branch", default="main", help="Base branch to compare against" ) parser.add_argument( - "-ex", + "-e", "--exclude-path", default=["doc"], nargs="+", help="Path to exclude from git diff." - "Can be used multiple times eg: -ex p1 -ex p2", + "Can be used multiple times eg: -e p1 -e p2", ) parser.add_argument("--debug", action="store_true", help="Print debug info") From f4de4d433d7c0bc83c710a92b029a1655f3e0f40 Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Wed, 31 May 2023 10:49:47 -0400 Subject: [PATCH 11/37] Added sys exit --- src/pkgmt/modified.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pkgmt/modified.py b/src/pkgmt/modified.py index adc28aa..d1c32ca 100644 --- a/src/pkgmt/modified.py +++ b/src/pkgmt/modified.py @@ -1,5 +1,6 @@ import subprocess import argparse +import sys def check_modified(base_branch, exclude_path, debug=False): @@ -44,4 +45,4 @@ def check_modified(base_branch, exclude_path, debug=False): args = parser.parse_args() returncode = check_modified(args.base_branch, args.exclude_path, debug=args.debug) - print(returncode) + sys.exit(returncode) From c928988a09d2cdbb30614104826d319f79288ca4 Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Wed, 31 May 2023 12:47:20 -0400 Subject: [PATCH 12/37] Revert sys.exit --- src/pkgmt/modified.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pkgmt/modified.py b/src/pkgmt/modified.py index d1c32ca..2c8430c 100644 --- a/src/pkgmt/modified.py +++ b/src/pkgmt/modified.py @@ -45,4 +45,4 @@ def check_modified(base_branch, exclude_path, debug=False): args = parser.parse_args() returncode = check_modified(args.base_branch, args.exclude_path, debug=args.debug) - sys.exit(returncode) + print(returncode) From 99dc484f1e7377fa9ac308b3622075fae3091206 Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Wed, 31 May 2023 13:13:29 -0400 Subject: [PATCH 13/37] Lint --- src/pkgmt/modified.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pkgmt/modified.py b/src/pkgmt/modified.py index 2c8430c..adc28aa 100644 --- a/src/pkgmt/modified.py +++ b/src/pkgmt/modified.py @@ -1,6 +1,5 @@ import subprocess import argparse -import sys def check_modified(base_branch, exclude_path, debug=False): From 8f880a8334e0c506e751dbcface26c636f806f89 Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Thu, 1 Jun 2023 11:58:35 -0400 Subject: [PATCH 14/37] Added test case --- tests/conftest.py | 40 ++++++++++++++++++++++++++++++++++++++++ tests/test_modified.py | 4 ++++ 2 files changed, 44 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index 2d8078c..aeb8d88 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -85,3 +85,43 @@ def tmp_package_modi(root, tmp_empty): yield tmp_empty os.chdir(old) + + +@pytest.fixture +def tmp_package_modi_2(root, tmp_empty): + old = os.getcwd() + path_to_templates = root / "tests" / "assets" / "package_name" + shutil.copytree(str(path_to_templates), "copy") + os.chdir("copy") + + subprocess.run(["git", "init"]) + subprocess.check_call(["git", "config", "commit.gpgsign", "false"]) + subprocess.check_call(["git", "config", "user.email", "ci@ploomberio"]) + subprocess.check_call(["git", "config", "user.name", "Ploomber"]) + subprocess.run(["git", "checkout", "-b", "main"]) + subprocess.run(["git", "add", "--all"]) + subprocess.run(["git", "commit", "-m", "init-commit-message"]) + + # main branch: create doc/file.txt, commit + subprocess.run(["mkdir", "-p", "doc"]) + subprocess.run(["touch", "doc/file.txt"]) + subprocess.run(["git", "add", "."]) + subprocess.run(["git", "commit", "-m", "added doc/file.txt"]) + + # checkout to test branch, create doc/another.txt, commit + subprocess.run(["git", "checkout", "-b", "test_modified_doc"]) + subprocess.run(["mkdir", "-p", "doc"]) + subprocess.run(["touch", "doc/another.txt"]) + subprocess.run(["git", "add", "."]) + subprocess.run(["git", "commit", "-m", "add doc/another.txt"]) + + # checkout main again, create something/file.txt, commit + subprocess.run(["git", "checkout", "main"]) + subprocess.run(["mkdir", "-p", "something"]) + subprocess.run(["touch", "something/file.txt"]) + subprocess.run(["git", "add", "."]) + subprocess.run(["git", "commit", "-m", "added something/file.txt"]) + + yield tmp_empty + + os.chdir(old) diff --git a/tests/test_modified.py b/tests/test_modified.py index e5f43fb..f28f141 100644 --- a/tests/test_modified.py +++ b/tests/test_modified.py @@ -19,3 +19,7 @@ ) def test_check_modified(tmp_package_modi, base_branch, exclude_path, returncode): assert modified.check_modified(base_branch, exclude_path, debug=True) == returncode + + +def test_check_modified_2(tmp_package_modi_2): + assert modified.check_modified("main", ["doc"], debug=True) == 0 From b2667bb7f46e54b86b3023720200eed4d9fb4c22 Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Thu, 1 Jun 2023 12:00:46 -0400 Subject: [PATCH 15/37] Renaming --- src/pkgmt/{modified.py => fail_if_modified.py} | 0 tests/test_modified.py | 9 ++++++--- 2 files changed, 6 insertions(+), 3 deletions(-) rename src/pkgmt/{modified.py => fail_if_modified.py} (100%) diff --git a/src/pkgmt/modified.py b/src/pkgmt/fail_if_modified.py similarity index 100% rename from src/pkgmt/modified.py rename to src/pkgmt/fail_if_modified.py diff --git a/tests/test_modified.py b/tests/test_modified.py index f28f141..aa2f14a 100644 --- a/tests/test_modified.py +++ b/tests/test_modified.py @@ -1,5 +1,5 @@ import pytest -from pkgmt import modified +from pkgmt import fail_if_modified @pytest.mark.parametrize( @@ -18,8 +18,11 @@ ], ) def test_check_modified(tmp_package_modi, base_branch, exclude_path, returncode): - assert modified.check_modified(base_branch, exclude_path, debug=True) == returncode + assert ( + fail_if_modified.check_modified(base_branch, exclude_path, debug=True) + == returncode + ) def test_check_modified_2(tmp_package_modi_2): - assert modified.check_modified("main", ["doc"], debug=True) == 0 + assert fail_if_modified.check_modified("main", ["doc"], debug=True) == 0 From 8c09d1b35e510e12952fd3829dec40ab713c5df9 Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Thu, 1 Jun 2023 12:11:38 -0400 Subject: [PATCH 16/37] Added Pathlib implementation --- .github/workflows/ci.yaml | 4 ++-- tests/conftest.py | 35 ++++++++++++++++------------------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 04cb046..2362c1b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -5,7 +5,7 @@ on: [push, pull_request] jobs: unit-tests: - runs-on: ubuntu-latest + runs-on: [ubuntu-latest, windows-latest, macos-latest] strategy: matrix: python-version: [3.7, 3.8, 3.9, '3.10'] @@ -33,7 +33,7 @@ jobs: check: - runs-on: ubuntu-latest + runs-on: [ubuntu-latest, windows-latest, macos-latest] steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} diff --git a/tests/conftest.py b/tests/conftest.py index aeb8d88..50ae70e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -61,10 +61,10 @@ def tmp_another_package(root, tmp_empty): @pytest.fixture def tmp_package_modi(root, tmp_empty): - old = os.getcwd() + old = Path.cwd() path_to_templates = root / "tests" / "assets" / "package_name" shutil.copytree(str(path_to_templates), "copy") - os.chdir("copy") + Path.cwd().joinpath("copy") subprocess.run(["git", "init"]) subprocess.check_call(["git", "config", "commit.gpgsign", "false"]) @@ -75,24 +75,24 @@ def tmp_package_modi(root, tmp_empty): subprocess.run(["git", "commit", "-m", "init-commit-message"]) subprocess.run(["git", "checkout", "-b", "test_modified_doc"]) - subprocess.run(["mkdir", "-p", "test_doc1"]) - subprocess.run(["touch", "test_doc1/test_modified.txt"]) - subprocess.run(["mkdir", "-p", "test_doc2"]) - subprocess.run(["touch", "test_doc2/test_modified.txt"]) + Path("test_doc1").mkdir(parents=True, exist_ok=True) + Path("test_doc1/test_modified.txt").touch() + Path("test_doc2").mkdir(parents=True, exist_ok=True) + Path("test_doc2/test_modified.txt").touch() subprocess.run(["git", "add", "."]) subprocess.run(["git", "commit", "-m", "test_modified"]) yield tmp_empty - os.chdir(old) + Path.cwd().joinpath(old) @pytest.fixture def tmp_package_modi_2(root, tmp_empty): - old = os.getcwd() + old = Path.cwd() path_to_templates = root / "tests" / "assets" / "package_name" shutil.copytree(str(path_to_templates), "copy") - os.chdir("copy") + Path.cwd().joinpath("copy") subprocess.run(["git", "init"]) subprocess.check_call(["git", "config", "commit.gpgsign", "false"]) @@ -102,26 +102,23 @@ def tmp_package_modi_2(root, tmp_empty): subprocess.run(["git", "add", "--all"]) subprocess.run(["git", "commit", "-m", "init-commit-message"]) - # main branch: create doc/file.txt, commit - subprocess.run(["mkdir", "-p", "doc"]) - subprocess.run(["touch", "doc/file.txt"]) + Path.cwd().joinpath("doc").mkdir(parents=True, exist_ok=True) + Path.cwd().joinpath("doc", "file.txt").touch() subprocess.run(["git", "add", "."]) subprocess.run(["git", "commit", "-m", "added doc/file.txt"]) - # checkout to test branch, create doc/another.txt, commit subprocess.run(["git", "checkout", "-b", "test_modified_doc"]) - subprocess.run(["mkdir", "-p", "doc"]) - subprocess.run(["touch", "doc/another.txt"]) + Path.cwd().joinpath("doc").mkdir(parents=True, exist_ok=True) + Path.cwd().joinpath("doc", "another.txt").touch() subprocess.run(["git", "add", "."]) subprocess.run(["git", "commit", "-m", "add doc/another.txt"]) - # checkout main again, create something/file.txt, commit subprocess.run(["git", "checkout", "main"]) - subprocess.run(["mkdir", "-p", "something"]) - subprocess.run(["touch", "something/file.txt"]) + Path.cwd().joinpath("something").mkdir(parents=True, exist_ok=True) + Path.cwd().joinpath("something", "file.txt").touch() subprocess.run(["git", "add", "."]) subprocess.run(["git", "commit", "-m", "added something/file.txt"]) yield tmp_empty - os.chdir(old) + Path.cwd().joinpath(old) From 34853e52baf2a677c9cd2b832092935197d16580 Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Thu, 1 Jun 2023 12:13:55 -0400 Subject: [PATCH 17/37] tmp deleted workdlow tag check --- .github/workflows/workflow-edits.yml | 34 ---------------------------- 1 file changed, 34 deletions(-) delete mode 100644 .github/workflows/workflow-edits.yml diff --git a/.github/workflows/workflow-edits.yml b/.github/workflows/workflow-edits.yml deleted file mode 100644 index 2f9906a..0000000 --- a/.github/workflows/workflow-edits.yml +++ /dev/null @@ -1,34 +0,0 @@ -# NOTE: we need this as a security measure so PRs from forks cannot submit a PR and -# modify this file. The only way for this test to pass is to add the -# 'allow-workflow-edits' label and push again. -name: workflow-edited - - -# note that this triggers on 'pull_request_target' instead of 'pull_request'. -# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target -# https://docs.boostsecurity.io/rules/cicd-gha-risky-pull-request-target-usage.html -on: [pull_request_target] - -jobs: - changelog-edited: - runs-on: ubuntu-latest - if: ${{ !contains(github.event.pull_request.labels.*.name, 'allow-workflow-edits') }} - - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - ref: ${{ github.event.pull_request.head.sha }} - - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: '3.10' - - - name: Check - id: check - run: | - BRANCH_NAME=main - git fetch --depth=1 origin $BRANCH_NAME:$BRANCH_NAME - git diff --exit-code "$BRANCH_NAME" .github/workflows/ - From 3a7a6153e3dad5abe4f02b737c6b001bb77b820e Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Thu, 1 Jun 2023 12:15:13 -0400 Subject: [PATCH 18/37] Re added workflow edits --- .github/workflows/workflow-edits.yml | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/workflows/workflow-edits.yml diff --git a/.github/workflows/workflow-edits.yml b/.github/workflows/workflow-edits.yml new file mode 100644 index 0000000..450dbbd --- /dev/null +++ b/.github/workflows/workflow-edits.yml @@ -0,0 +1,33 @@ +# NOTE: we need this as a security measure so PRs from forks cannot submit a PR and +# modify this file. The only way for this test to pass is to add the +# 'allow-workflow-edits' label and push again. +name: workflow-edited + + +# note that this triggers on 'pull_request_target' instead of 'pull_request'. +# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target +# https://docs.boostsecurity.io/rules/cicd-gha-risky-pull-request-target-usage.html +on: [pull_request_target] + +jobs: + changelog-edited: + runs-on: ubuntu-latest + if: ${{ !contains(github.event.pull_request.labels.*.name, 'allow-workflow-edits') }} + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: '3.10' + + - name: Check + id: check + run: | + BRANCH_NAME=main + git fetch --depth=1 origin $BRANCH_NAME:$BRANCH_NAME + git diff --exit-code "$BRANCH_NAME" .github/workflows/ From 631c27c796d4e26a0da344565dcc1823d3f37c23 Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Thu, 1 Jun 2023 12:21:02 -0400 Subject: [PATCH 19/37] Fix CI --- .github/workflows/ci.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2362c1b..deac38c 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -4,11 +4,12 @@ on: [push, pull_request] jobs: unit-tests: - - runs-on: [ubuntu-latest, windows-latest, macos-latest] strategy: matrix: python-version: [3.7, 3.8, 3.9, '3.10'] + os: [ubuntu-latest, windows-latest, macos-latest] + + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 From f867bb1757f4848eceb35be9a7e1527676c5230c Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Thu, 1 Jun 2023 12:24:44 -0400 Subject: [PATCH 20/37] Commented Tests --- tests/test_github.py | 46 ++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/tests/test_github.py b/tests/test_github.py index 8b80c63..b8bb74a 100644 --- a/tests/test_github.py +++ b/tests/test_github.py @@ -7,30 +7,30 @@ def test_get_pr(): assert github.get_pr("ploomber", "ploomber", 1071) -@pytest.mark.parametrize( - "pr_number, expected_repo, expected_branch", - [ - [ - 1071, - "https://github.com/tonykploomber/ploomber", - "1070-noqa-coming-up-on-docs", - ], - [ - 1044, - "https://github.com/ploomber/ploomber", - "cloud_stats", - ], - ], - ids=[ - "fork", - "branch", - ], -) -def test_get_repo_and_branch_for_pr(pr_number, expected_repo, expected_branch): - repo, branch = github.get_repo_and_branch_for_pr("ploomber", "ploomber", pr_number) +# @pytest.mark.parametrize( +# "pr_number, expected_repo, expected_branch", +# [ +# [ +# 1071, +# "https://github.com/tonykploomber/ploomber", +# "1070-noqa-coming-up-on-docs", +# ], +# [ +# 1044, +# "https://github.com/ploomber/ploomber", +# "cloud_stats", +# ], +# ], +# ids=[ +# "fork", +# "branch", +# ], +# ) +# def test_get_repo_and_branch_for_pr(pr_number, expected_repo, expected_branch): +# repo, branch = github.get_repo_and_branch_for_pr("ploomber", "ploomber", pr_number) - assert repo == expected_repo - assert branch == expected_branch +# assert repo == expected_repo +# assert branch == expected_branch @pytest.mark.parametrize( From ce3ee64dd4e1a3496662c3eae7f5300ecd289964 Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Thu, 1 Jun 2023 12:27:00 -0400 Subject: [PATCH 21/37] Format --- tests/test_github.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_github.py b/tests/test_github.py index b8bb74a..a0ba601 100644 --- a/tests/test_github.py +++ b/tests/test_github.py @@ -27,7 +27,9 @@ def test_get_pr(): # ], # ) # def test_get_repo_and_branch_for_pr(pr_number, expected_repo, expected_branch): -# repo, branch = github.get_repo_and_branch_for_pr("ploomber", "ploomber", pr_number) +# repo, branch = github.get_repo_and_branch_for_pr("ploomber", +# "ploomber", pr_number) + # assert repo == expected_repo # assert branch == expected_branch From 539c7ebdb906d88aac20fe4386e7c19d4d0a5843 Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Thu, 1 Jun 2023 12:31:11 -0400 Subject: [PATCH 22/37] Commented some more --- tests/test_github.py | 58 ++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/tests/test_github.py b/tests/test_github.py index a0ba601..af30706 100644 --- a/tests/test_github.py +++ b/tests/test_github.py @@ -1,4 +1,4 @@ -import pytest +# import pytest from pkgmt import github @@ -35,33 +35,33 @@ def test_get_pr(): # assert branch == expected_branch -@pytest.mark.parametrize( - "pr_number, expected_repo, expected_branch", - [ - [ - "1071", - "https://github.com/tonykploomber/ploomber", - "1070-noqa-coming-up-on-docs", - ], - [ - "1044", - "https://github.com/ploomber/ploomber", - "cloud_stats", - ], - ], - ids=[ - "fork", - "branch", - ], -) -def test_get_repo_and_branch_for_readthedocs( - monkeypatch, pr_number, expected_repo, expected_branch -): - monkeypatch.setenv("READTHEDOCS_VERSION_NAME", pr_number) +# @pytest.mark.parametrize( +# "pr_number, expected_repo, expected_branch", +# [ +# [ +# "1071", +# "https://github.com/tonykploomber/ploomber", +# "1070-noqa-coming-up-on-docs", +# ], +# [ +# "1044", +# "https://github.com/ploomber/ploomber", +# "cloud_stats", +# ], +# ], +# ids=[ +# "fork", +# "branch", +# ], +# ) +# def test_get_repo_and_branch_for_readthedocs( +# monkeypatch, pr_number, expected_repo, expected_branch +# ): +# monkeypatch.setenv("READTHEDOCS_VERSION_NAME", pr_number) - repo, branch = github.get_repo_and_branch_for_readthedocs( - "https://github.com/ploomber/ploomber", default_branch="master" - ) +# repo, branch = github.get_repo_and_branch_for_readthedocs( +# "https://github.com/ploomber/ploomber", default_branch="master" +# ) - assert repo == expected_repo - assert branch == expected_branch +# assert repo == expected_repo +# assert branch == expected_branch From 0fdbc34822d4fbc667ddbf33d24f72ef8c46c206 Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Thu, 1 Jun 2023 12:36:07 -0400 Subject: [PATCH 23/37] more comments --- tests/test_links.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_links.py b/tests/test_links.py index 2c181b2..92e5b74 100644 --- a/tests/test_links.py +++ b/tests/test_links.py @@ -160,11 +160,11 @@ def another_function(): ) -def test_find_links_in_files(sample_files): - assert links._find_links_in_files(["py"]) == { - "script.py": ["https://ploomber.io/first"], - "some/nested/dir/another.py": ["https://ploomber.io/second"], - } +# def test_find_links_in_files(sample_files): +# assert links._find_links_in_files(["py"]) == { +# "script.py": ["https://ploomber.io/first"], +# "some/nested/dir/another.py": ["https://ploomber.io/second"], +# } def test_find_links_in_files_ignores_nontracked_files(sample_files): From 9be7f6da20571ccfa6730ca83b6e2a798ded1b86 Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Thu, 1 Jun 2023 13:04:54 -0400 Subject: [PATCH 24/37] Fix conftest --- tests/conftest.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 50ae70e..a6d03ad 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -75,10 +75,10 @@ def tmp_package_modi(root, tmp_empty): subprocess.run(["git", "commit", "-m", "init-commit-message"]) subprocess.run(["git", "checkout", "-b", "test_modified_doc"]) - Path("test_doc1").mkdir(parents=True, exist_ok=True) - Path("test_doc1/test_modified.txt").touch() - Path("test_doc2").mkdir(parents=True, exist_ok=True) - Path("test_doc2/test_modified.txt").touch() + Path.cwd().joinpath("test_doc1").mkdir(parents=True, exist_ok=True) + Path.cwd().joinpath("test_doc1","test_modified.txt").touch() + Path.cwd().joinpath("test_doc2").mkdir(parents=True, exist_ok=True) + Path.cwd().joinpath("test_doc2","test_modified.txt").touch() subprocess.run(["git", "add", "."]) subprocess.run(["git", "commit", "-m", "test_modified"]) From 86989b95f0f4692dc6f5f96d0ba55fd798533b66 Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Thu, 1 Jun 2023 13:06:55 -0400 Subject: [PATCH 25/37] Format --- tests/conftest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index a6d03ad..43f3c30 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -76,9 +76,9 @@ def tmp_package_modi(root, tmp_empty): subprocess.run(["git", "checkout", "-b", "test_modified_doc"]) Path.cwd().joinpath("test_doc1").mkdir(parents=True, exist_ok=True) - Path.cwd().joinpath("test_doc1","test_modified.txt").touch() + Path.cwd().joinpath("test_doc1", "test_modified.txt").touch() Path.cwd().joinpath("test_doc2").mkdir(parents=True, exist_ok=True) - Path.cwd().joinpath("test_doc2","test_modified.txt").touch() + Path.cwd().joinpath("test_doc2", "test_modified.txt").touch() subprocess.run(["git", "add", "."]) subprocess.run(["git", "commit", "-m", "test_modified"]) From c03a61aa64d497541e627f6658cd807b9df2420c Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Fri, 2 Jun 2023 09:08:38 -0400 Subject: [PATCH 26/37] Fix conftest --- tests/conftest.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 43f3c30..98e5504 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -63,8 +63,10 @@ def tmp_another_package(root, tmp_empty): def tmp_package_modi(root, tmp_empty): old = Path.cwd() path_to_templates = root / "tests" / "assets" / "package_name" + shutil.copytree(str(path_to_templates), "copy") - Path.cwd().joinpath("copy") + os.chdir("copy") + subprocess.run(["git", "init"]) subprocess.check_call(["git", "config", "commit.gpgsign", "false"]) @@ -84,7 +86,7 @@ def tmp_package_modi(root, tmp_empty): yield tmp_empty - Path.cwd().joinpath(old) + os.chdir(old) @pytest.fixture @@ -92,7 +94,7 @@ def tmp_package_modi_2(root, tmp_empty): old = Path.cwd() path_to_templates = root / "tests" / "assets" / "package_name" shutil.copytree(str(path_to_templates), "copy") - Path.cwd().joinpath("copy") + os.chdir("copy") subprocess.run(["git", "init"]) subprocess.check_call(["git", "config", "commit.gpgsign", "false"]) @@ -121,4 +123,4 @@ def tmp_package_modi_2(root, tmp_empty): yield tmp_empty - Path.cwd().joinpath(old) + os.chdir(old) From 54866263688fab4ce5cb5d5a8a06388218e85ce9 Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Fri, 2 Jun 2023 09:10:01 -0400 Subject: [PATCH 27/37] Format --- tests/conftest.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 98e5504..e2b5fe7 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -63,10 +63,9 @@ def tmp_another_package(root, tmp_empty): def tmp_package_modi(root, tmp_empty): old = Path.cwd() path_to_templates = root / "tests" / "assets" / "package_name" - + shutil.copytree(str(path_to_templates), "copy") os.chdir("copy") - subprocess.run(["git", "init"]) subprocess.check_call(["git", "config", "commit.gpgsign", "false"]) From 4a056ebd1566c45ffb0282d5be85a2f549cacdd3 Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Fri, 2 Jun 2023 12:26:12 -0400 Subject: [PATCH 28/37] Verbose testing --- .github/workflows/ci.yaml | 2 +- tests/conftest.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index deac38c..3e5af4c 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -30,7 +30,7 @@ jobs: flake8 - name: Test with pytest run: | - pytest + pytest -s -vv check: diff --git a/tests/conftest.py b/tests/conftest.py index e2b5fe7..5d2c46e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -67,6 +67,8 @@ def tmp_package_modi(root, tmp_empty): shutil.copytree(str(path_to_templates), "copy") os.chdir("copy") + print("os:list dir", os.listdir(".")) + subprocess.run(["git", "init"]) subprocess.check_call(["git", "config", "commit.gpgsign", "false"]) subprocess.check_call(["git", "config", "user.email", "ci@ploomberio"]) From 51e382f87649c4feef430ecb957cfa42a1cafa07 Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Fri, 2 Jun 2023 12:40:43 -0400 Subject: [PATCH 29/37] Revert back CI changes --- .github/workflows/ci.yaml | 9 ++-- tests/conftest.py | 2 - tests/test_github.py | 106 +++++++++++++++++++------------------- tests/test_links.py | 10 ++-- 4 files changed, 61 insertions(+), 66 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3e5af4c..04cb046 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -4,12 +4,11 @@ on: [push, pull_request] jobs: unit-tests: + + runs-on: ubuntu-latest strategy: matrix: python-version: [3.7, 3.8, 3.9, '3.10'] - os: [ubuntu-latest, windows-latest, macos-latest] - - runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 @@ -30,11 +29,11 @@ jobs: flake8 - name: Test with pytest run: | - pytest -s -vv + pytest check: - runs-on: [ubuntu-latest, windows-latest, macos-latest] + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} diff --git a/tests/conftest.py b/tests/conftest.py index 5d2c46e..e2b5fe7 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -67,8 +67,6 @@ def tmp_package_modi(root, tmp_empty): shutil.copytree(str(path_to_templates), "copy") os.chdir("copy") - print("os:list dir", os.listdir(".")) - subprocess.run(["git", "init"]) subprocess.check_call(["git", "config", "commit.gpgsign", "false"]) subprocess.check_call(["git", "config", "user.email", "ci@ploomberio"]) diff --git a/tests/test_github.py b/tests/test_github.py index af30706..8b80c63 100644 --- a/tests/test_github.py +++ b/tests/test_github.py @@ -1,4 +1,4 @@ -# import pytest +import pytest from pkgmt import github @@ -7,61 +7,59 @@ def test_get_pr(): assert github.get_pr("ploomber", "ploomber", 1071) -# @pytest.mark.parametrize( -# "pr_number, expected_repo, expected_branch", -# [ -# [ -# 1071, -# "https://github.com/tonykploomber/ploomber", -# "1070-noqa-coming-up-on-docs", -# ], -# [ -# 1044, -# "https://github.com/ploomber/ploomber", -# "cloud_stats", -# ], -# ], -# ids=[ -# "fork", -# "branch", -# ], -# ) -# def test_get_repo_and_branch_for_pr(pr_number, expected_repo, expected_branch): -# repo, branch = github.get_repo_and_branch_for_pr("ploomber", -# "ploomber", pr_number) +@pytest.mark.parametrize( + "pr_number, expected_repo, expected_branch", + [ + [ + 1071, + "https://github.com/tonykploomber/ploomber", + "1070-noqa-coming-up-on-docs", + ], + [ + 1044, + "https://github.com/ploomber/ploomber", + "cloud_stats", + ], + ], + ids=[ + "fork", + "branch", + ], +) +def test_get_repo_and_branch_for_pr(pr_number, expected_repo, expected_branch): + repo, branch = github.get_repo_and_branch_for_pr("ploomber", "ploomber", pr_number) + assert repo == expected_repo + assert branch == expected_branch -# assert repo == expected_repo -# assert branch == expected_branch +@pytest.mark.parametrize( + "pr_number, expected_repo, expected_branch", + [ + [ + "1071", + "https://github.com/tonykploomber/ploomber", + "1070-noqa-coming-up-on-docs", + ], + [ + "1044", + "https://github.com/ploomber/ploomber", + "cloud_stats", + ], + ], + ids=[ + "fork", + "branch", + ], +) +def test_get_repo_and_branch_for_readthedocs( + monkeypatch, pr_number, expected_repo, expected_branch +): + monkeypatch.setenv("READTHEDOCS_VERSION_NAME", pr_number) -# @pytest.mark.parametrize( -# "pr_number, expected_repo, expected_branch", -# [ -# [ -# "1071", -# "https://github.com/tonykploomber/ploomber", -# "1070-noqa-coming-up-on-docs", -# ], -# [ -# "1044", -# "https://github.com/ploomber/ploomber", -# "cloud_stats", -# ], -# ], -# ids=[ -# "fork", -# "branch", -# ], -# ) -# def test_get_repo_and_branch_for_readthedocs( -# monkeypatch, pr_number, expected_repo, expected_branch -# ): -# monkeypatch.setenv("READTHEDOCS_VERSION_NAME", pr_number) + repo, branch = github.get_repo_and_branch_for_readthedocs( + "https://github.com/ploomber/ploomber", default_branch="master" + ) -# repo, branch = github.get_repo_and_branch_for_readthedocs( -# "https://github.com/ploomber/ploomber", default_branch="master" -# ) - -# assert repo == expected_repo -# assert branch == expected_branch + assert repo == expected_repo + assert branch == expected_branch diff --git a/tests/test_links.py b/tests/test_links.py index 92e5b74..2c181b2 100644 --- a/tests/test_links.py +++ b/tests/test_links.py @@ -160,11 +160,11 @@ def another_function(): ) -# def test_find_links_in_files(sample_files): -# assert links._find_links_in_files(["py"]) == { -# "script.py": ["https://ploomber.io/first"], -# "some/nested/dir/another.py": ["https://ploomber.io/second"], -# } +def test_find_links_in_files(sample_files): + assert links._find_links_in_files(["py"]) == { + "script.py": ["https://ploomber.io/first"], + "some/nested/dir/another.py": ["https://ploomber.io/second"], + } def test_find_links_in_files_ignores_nontracked_files(sample_files): From c7e2d479777bded10a1f9be5d0f07c0617351e49 Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Fri, 2 Jun 2023 12:43:50 -0400 Subject: [PATCH 30/37] Moved to sys.exit --- src/pkgmt/fail_if_modified.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pkgmt/fail_if_modified.py b/src/pkgmt/fail_if_modified.py index adc28aa..0ba40a9 100644 --- a/src/pkgmt/fail_if_modified.py +++ b/src/pkgmt/fail_if_modified.py @@ -1,6 +1,6 @@ import subprocess import argparse - +import sys def check_modified(base_branch, exclude_path, debug=False): # https://stackoverflow.com/questions/4380945 @@ -44,4 +44,4 @@ def check_modified(base_branch, exclude_path, debug=False): args = parser.parse_args() returncode = check_modified(args.base_branch, args.exclude_path, debug=args.debug) - print(returncode) + sys.exit(returncode) From 8cfd99a3d7c6505c18360d34eb3361aa2f5b874a Mon Sep 17 00:00:00 2001 From: Mohit Mehta <43580047+mehtamohit013@users.noreply.github.com> Date: Fri, 2 Jun 2023 13:13:35 -0400 Subject: [PATCH 31/37] Minor From a5998cc5d808960852aee640be2b617f5214105e Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Fri, 2 Jun 2023 13:15:02 -0400 Subject: [PATCH 32/37] Minor --- .github/workflows/workflow-edits.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow-edits.yml b/.github/workflows/workflow-edits.yml index 450dbbd..199c17b 100644 --- a/.github/workflows/workflow-edits.yml +++ b/.github/workflows/workflow-edits.yml @@ -30,4 +30,4 @@ jobs: run: | BRANCH_NAME=main git fetch --depth=1 origin $BRANCH_NAME:$BRANCH_NAME - git diff --exit-code "$BRANCH_NAME" .github/workflows/ + git diff --exit-code "$BRANCH_NAME" .github/workflows/ \ No newline at end of file From fe85854ad184baa88c6ac603a0084377a90a044c Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Fri, 2 Jun 2023 13:18:17 -0400 Subject: [PATCH 33/37] Minor --- .github/workflows/workflow-edits.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/workflow-edits.yml b/.github/workflows/workflow-edits.yml index 199c17b..2f9906a 100644 --- a/.github/workflows/workflow-edits.yml +++ b/.github/workflows/workflow-edits.yml @@ -30,4 +30,5 @@ jobs: run: | BRANCH_NAME=main git fetch --depth=1 origin $BRANCH_NAME:$BRANCH_NAME - git diff --exit-code "$BRANCH_NAME" .github/workflows/ \ No newline at end of file + git diff --exit-code "$BRANCH_NAME" .github/workflows/ + From 83ced20dd8babcf9e41f9e4b1a8e99da84268993 Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Fri, 2 Jun 2023 13:20:06 -0400 Subject: [PATCH 34/37] Format --- src/pkgmt/fail_if_modified.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pkgmt/fail_if_modified.py b/src/pkgmt/fail_if_modified.py index 0ba40a9..d1c32ca 100644 --- a/src/pkgmt/fail_if_modified.py +++ b/src/pkgmt/fail_if_modified.py @@ -2,6 +2,7 @@ import argparse import sys + def check_modified(base_branch, exclude_path, debug=False): # https://stackoverflow.com/questions/4380945 cmd = f"git diff --exit-code {base_branch}... -- ." From 20c65e06e93ac56279f263316ef92f9ad3fa5369 Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Sat, 3 Jun 2023 12:16:35 -0400 Subject: [PATCH 35/37] Fix --- src/pkgmt/fail_if_modified.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pkgmt/fail_if_modified.py b/src/pkgmt/fail_if_modified.py index d1c32ca..c462b9a 100644 --- a/src/pkgmt/fail_if_modified.py +++ b/src/pkgmt/fail_if_modified.py @@ -8,7 +8,7 @@ def check_modified(base_branch, exclude_path, debug=False): cmd = f"git diff --exit-code {base_branch}... -- ." for path in exclude_path: - cmd += f" :^{path}" + cmd += f" ':^{path}'" if debug: print(f"cmd: {cmd}") From b7f01474a512cd5845645fc1b6a03aff22eabcf7 Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Sat, 3 Jun 2023 12:20:40 -0400 Subject: [PATCH 36/37] Windows CI --- .github/workflows/ci.yaml | 9 ++-- tests/test_github.py | 105 +++++++++++++++++++------------------- tests/test_links.py | 12 ++--- 3 files changed, 64 insertions(+), 62 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 04cb046..3e5af4c 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -4,11 +4,12 @@ on: [push, pull_request] jobs: unit-tests: - - runs-on: ubuntu-latest strategy: matrix: python-version: [3.7, 3.8, 3.9, '3.10'] + os: [ubuntu-latest, windows-latest, macos-latest] + + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 @@ -29,11 +30,11 @@ jobs: flake8 - name: Test with pytest run: | - pytest + pytest -s -vv check: - runs-on: ubuntu-latest + runs-on: [ubuntu-latest, windows-latest, macos-latest] steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} diff --git a/tests/test_github.py b/tests/test_github.py index 8b80c63..c488a79 100644 --- a/tests/test_github.py +++ b/tests/test_github.py @@ -1,4 +1,4 @@ -import pytest +# import pytest from pkgmt import github @@ -7,59 +7,60 @@ def test_get_pr(): assert github.get_pr("ploomber", "ploomber", 1071) -@pytest.mark.parametrize( - "pr_number, expected_repo, expected_branch", - [ - [ - 1071, - "https://github.com/tonykploomber/ploomber", - "1070-noqa-coming-up-on-docs", - ], - [ - 1044, - "https://github.com/ploomber/ploomber", - "cloud_stats", - ], - ], - ids=[ - "fork", - "branch", - ], -) -def test_get_repo_and_branch_for_pr(pr_number, expected_repo, expected_branch): - repo, branch = github.get_repo_and_branch_for_pr("ploomber", "ploomber", pr_number) +# @pytest.mark.parametrize( +# "pr_number, expected_repo, expected_branch", +# [ +# [ +# 1071, +# "https://github.com/tonykploomber/ploomber", +# "1070-noqa-coming-up-on-docs", +# ], +# [ +# 1044, +# "https://github.com/ploomber/ploomber", +# "cloud_stats", +# ], +# ], +# ids=[ +# "fork", +# "branch", +# ], +# ) +# def test_get_repo_and_branch_for_pr(pr_number, expected_repo, expected_branch): +# repo, branch = github.get_repo_and_branch_for +# _pr("ploomber", "ploomber", pr_number) - assert repo == expected_repo - assert branch == expected_branch +# assert repo == expected_repo +# assert branch == expected_branch -@pytest.mark.parametrize( - "pr_number, expected_repo, expected_branch", - [ - [ - "1071", - "https://github.com/tonykploomber/ploomber", - "1070-noqa-coming-up-on-docs", - ], - [ - "1044", - "https://github.com/ploomber/ploomber", - "cloud_stats", - ], - ], - ids=[ - "fork", - "branch", - ], -) -def test_get_repo_and_branch_for_readthedocs( - monkeypatch, pr_number, expected_repo, expected_branch -): - monkeypatch.setenv("READTHEDOCS_VERSION_NAME", pr_number) +# @pytest.mark.parametrize( +# "pr_number, expected_repo, expected_branch", +# [ +# [ +# "1071", +# "https://github.com/tonykploomber/ploomber", +# "1070-noqa-coming-up-on-docs", +# ], +# [ +# "1044", +# "https://github.com/ploomber/ploomber", +# "cloud_stats", +# ], +# ], +# ids=[ +# "fork", +# "branch", +# ], +# ) +# def test_get_repo_and_branch_for_readthedocs( +# monkeypatch, pr_number, expected_repo, expected_branch +# ): +# monkeypatch.setenv("READTHEDOCS_VERSION_NAME", pr_number) - repo, branch = github.get_repo_and_branch_for_readthedocs( - "https://github.com/ploomber/ploomber", default_branch="master" - ) +# repo, branch = github.get_repo_and_branch_for_readthedocs( +# "https://github.com/ploomber/ploomber", default_branch="master" +# ) - assert repo == expected_repo - assert branch == expected_branch +# assert repo == expected_repo +# assert branch == expected_branch diff --git a/tests/test_links.py b/tests/test_links.py index 2c181b2..33b0f49 100644 --- a/tests/test_links.py +++ b/tests/test_links.py @@ -180,12 +180,12 @@ def test_find_links_in_files_ignores_nontracked_files(sample_files): } -def test_find_links_in_files_on_ipynb(tmp_empty, root): - text = Path(root / "tests" / "assets" / "notebook.ipynb").read_text() - Path("notebook.ipynb").write_text(text) - assert links._find_links_in_files(["ipynb"]) == { - "notebook.ipynb": ["https://ploomber.io"] - } +# def test_find_links_in_files_on_ipynb(tmp_empty, root): +# text = Path(root / "tests" / "assets" / "notebook.ipynb").read_text() +# Path("notebook.ipynb").write_text(text) +# assert links._find_links_in_files(["ipynb"]) == { +# "notebook.ipynb": ["https://ploomber.io"] +# } def test_find_broken_in_files_only_hits_urls_once(monkeypatch, tmp_empty): From 988f1d3d05156da67e71f737d8b9e1ded41a1a4d Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Sat, 3 Jun 2023 12:30:51 -0400 Subject: [PATCH 37/37] Revert back Windows CI --- .github/workflows/ci.yaml | 9 ++-- tests/test_github.py | 105 +++++++++++++++++++------------------- tests/test_links.py | 12 ++--- 3 files changed, 62 insertions(+), 64 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3e5af4c..04cb046 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -4,12 +4,11 @@ on: [push, pull_request] jobs: unit-tests: + + runs-on: ubuntu-latest strategy: matrix: python-version: [3.7, 3.8, 3.9, '3.10'] - os: [ubuntu-latest, windows-latest, macos-latest] - - runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 @@ -30,11 +29,11 @@ jobs: flake8 - name: Test with pytest run: | - pytest -s -vv + pytest check: - runs-on: [ubuntu-latest, windows-latest, macos-latest] + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} diff --git a/tests/test_github.py b/tests/test_github.py index c488a79..8b80c63 100644 --- a/tests/test_github.py +++ b/tests/test_github.py @@ -1,4 +1,4 @@ -# import pytest +import pytest from pkgmt import github @@ -7,60 +7,59 @@ def test_get_pr(): assert github.get_pr("ploomber", "ploomber", 1071) -# @pytest.mark.parametrize( -# "pr_number, expected_repo, expected_branch", -# [ -# [ -# 1071, -# "https://github.com/tonykploomber/ploomber", -# "1070-noqa-coming-up-on-docs", -# ], -# [ -# 1044, -# "https://github.com/ploomber/ploomber", -# "cloud_stats", -# ], -# ], -# ids=[ -# "fork", -# "branch", -# ], -# ) -# def test_get_repo_and_branch_for_pr(pr_number, expected_repo, expected_branch): -# repo, branch = github.get_repo_and_branch_for -# _pr("ploomber", "ploomber", pr_number) +@pytest.mark.parametrize( + "pr_number, expected_repo, expected_branch", + [ + [ + 1071, + "https://github.com/tonykploomber/ploomber", + "1070-noqa-coming-up-on-docs", + ], + [ + 1044, + "https://github.com/ploomber/ploomber", + "cloud_stats", + ], + ], + ids=[ + "fork", + "branch", + ], +) +def test_get_repo_and_branch_for_pr(pr_number, expected_repo, expected_branch): + repo, branch = github.get_repo_and_branch_for_pr("ploomber", "ploomber", pr_number) -# assert repo == expected_repo -# assert branch == expected_branch + assert repo == expected_repo + assert branch == expected_branch -# @pytest.mark.parametrize( -# "pr_number, expected_repo, expected_branch", -# [ -# [ -# "1071", -# "https://github.com/tonykploomber/ploomber", -# "1070-noqa-coming-up-on-docs", -# ], -# [ -# "1044", -# "https://github.com/ploomber/ploomber", -# "cloud_stats", -# ], -# ], -# ids=[ -# "fork", -# "branch", -# ], -# ) -# def test_get_repo_and_branch_for_readthedocs( -# monkeypatch, pr_number, expected_repo, expected_branch -# ): -# monkeypatch.setenv("READTHEDOCS_VERSION_NAME", pr_number) +@pytest.mark.parametrize( + "pr_number, expected_repo, expected_branch", + [ + [ + "1071", + "https://github.com/tonykploomber/ploomber", + "1070-noqa-coming-up-on-docs", + ], + [ + "1044", + "https://github.com/ploomber/ploomber", + "cloud_stats", + ], + ], + ids=[ + "fork", + "branch", + ], +) +def test_get_repo_and_branch_for_readthedocs( + monkeypatch, pr_number, expected_repo, expected_branch +): + monkeypatch.setenv("READTHEDOCS_VERSION_NAME", pr_number) -# repo, branch = github.get_repo_and_branch_for_readthedocs( -# "https://github.com/ploomber/ploomber", default_branch="master" -# ) + repo, branch = github.get_repo_and_branch_for_readthedocs( + "https://github.com/ploomber/ploomber", default_branch="master" + ) -# assert repo == expected_repo -# assert branch == expected_branch + assert repo == expected_repo + assert branch == expected_branch diff --git a/tests/test_links.py b/tests/test_links.py index 33b0f49..2c181b2 100644 --- a/tests/test_links.py +++ b/tests/test_links.py @@ -180,12 +180,12 @@ def test_find_links_in_files_ignores_nontracked_files(sample_files): } -# def test_find_links_in_files_on_ipynb(tmp_empty, root): -# text = Path(root / "tests" / "assets" / "notebook.ipynb").read_text() -# Path("notebook.ipynb").write_text(text) -# assert links._find_links_in_files(["ipynb"]) == { -# "notebook.ipynb": ["https://ploomber.io"] -# } +def test_find_links_in_files_on_ipynb(tmp_empty, root): + text = Path(root / "tests" / "assets" / "notebook.ipynb").read_text() + Path("notebook.ipynb").write_text(text) + assert links._find_links_in_files(["ipynb"]) == { + "notebook.ipynb": ["https://ploomber.io"] + } def test_find_broken_in_files_only_hits_urls_once(monkeypatch, tmp_empty):