From 2ca61ab0d268ee09787aecc4342ee113d13f0e1d Mon Sep 17 00:00:00 2001 From: "Breno Fernandes (Mac OS)" Date: Wed, 29 Jun 2022 12:11:00 -0400 Subject: [PATCH 1/4] Fix: mypy now creates a temp file to locate and test the pkg --- scripts/__init__.py | 9 +------- scripts/test/procedures.py | 46 +++++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/scripts/__init__.py b/scripts/__init__.py index 9c40f6cf5..5d4942219 100644 --- a/scripts/__init__.py +++ b/scripts/__init__.py @@ -1,15 +1,8 @@ import sys from loguru import logger -from pathlib import Path - -pkg_path = [x for x in sys.path if x.endswith('site-packages')] - -if not Path(fr'{pkg_path[0]}/my_paths.pth').exists(): - with open(fr'{pkg_path[0]}/my_paths.pth', 'w') as file: - file.write(str(Path.cwd())) - +# Config the format of log message config = { "handlers": [ { diff --git a/scripts/test/procedures.py b/scripts/test/procedures.py index 4017c7464..ce3a98d05 100644 --- a/scripts/test/procedures.py +++ b/scripts/test/procedures.py @@ -1,13 +1,29 @@ import shutil import subprocess from pathlib import Path +import sys -from scripts._job import Step, run_job + +def create_mypy_pkg_file(): + pkg_path = [x for x in sys.path if x.endswith('site-packages')] + + if not Path(fr'{pkg_path[0]}/my_path.pth').exists(): + with open(fr'{pkg_path[0]}/my_path.pth', 'w') as file: + file.write(str(Path.cwd())) + + +def destroy_mypy_pkg_file(): + pkg_path = [x for x in sys.path if x.endswith('site-packages')] + + if Path(fr'{pkg_path[0]}/my_path.pth').exists(): + Path(fr'{pkg_path[0]}/my_path.pth').unlink() def run_mypy_src(): + create_mypy_pkg_file() cmd = ["mypy", "pandas-stubs", "tests", "--no-incremental"] subprocess.run(cmd, check=True) + destroy_mypy_pkg_file() def run_pyright_src(): @@ -31,24 +47,49 @@ def install_dist(): subprocess.run(cmd, check=True) +def add_last_changes(): + cmd = ["git", "add", "."] + subprocess.run(cmd, check=True) + + +def commit_last_changes(): + cmd = ["git", "commit", "-am", "\"temp commit\""] + subprocess.run(cmd, check=True) + + def remove_src(): shutil.rmtree(r"pandas-stubs") def run_mypy_dist(): + create_mypy_pkg_file() cmd = ["mypy", "tests", "--no-incremental"] subprocess.run(cmd, check=True) + destroy_mypy_pkg_file() def run_pyright_dist(): cmd = ["pyright", "tests"] subprocess.run(cmd, check=True) + def uninstall_dist(): cmd = ["pip", "uninstall", "-y", "pandas-stubs"] subprocess.run(cmd, check=True) +def restore_last_changes(): + cmd = ["git", "show", "-s", "--format=%s"] + process = subprocess.Popen(cmd, stdout=subprocess.PIPE) + last_commit_name = process.communicate()[0] + + if last_commit_name == b'"temp commit"\n': + cmd = ["git", "reset", "--soft", "HEAD~1"] + subprocess.run(cmd, check=True) + else: + print("There is not temp commit to restore.") + + def restore_src(): cmd = ["git", "checkout", "HEAD", "pandas-stubs"] subprocess.run(cmd, check=True) @@ -74,3 +115,6 @@ def create_new_venv(): cmd = ["poetry", "shell"] subprocess.run(cmd, check=True) + +if __name__ == '__main__': + restore_last_changes() \ No newline at end of file From 1315ebb0cdb912f48774f76424bc4ce5ec25593d Mon Sep 17 00:00:00 2001 From: "Breno Fernandes (Mac OS)" Date: Wed, 29 Jun 2022 19:43:49 -0400 Subject: [PATCH 2/4] Fix: Remove code from another PR and Add rollback action in mypy step --- scripts/test/__init__.py | 12 +++++++++--- scripts/test/procedures.py | 30 ++---------------------------- 2 files changed, 11 insertions(+), 31 deletions(-) diff --git a/scripts/test/__init__.py b/scripts/test/__init__.py index 5f9332b8d..825ad3350 100644 --- a/scripts/test/__init__.py +++ b/scripts/test/__init__.py @@ -1,6 +1,7 @@ from scripts._job import Step, run_job from scripts.test import procedures + def test_src(profile: str, clean_cache: bool = False): steps = [] if clean_cache: @@ -10,17 +11,20 @@ def test_src(profile: str, clean_cache: bool = False): ]) # Possible steps - mypy_step = Step(name="Run Mypy Against Source Code", run=procedures.run_mypy_src) + create_mypy_pkg_step = Step(name="Create mypy package file", run=procedures.create_mypy_pkg_file) + mypy_step = Step(name="Run Mypy Against Source Code", run=procedures.run_mypy_src, + rollback=procedures.destroy_mypy_pkg_file) + destroy_mypy_pkg_step = Step(name="Destroy mypy package file", run=procedures.destroy_mypy_pkg_file) pyright_step = Step(name="Run Pyright Against Source Code", run=procedures.run_pyright_src) pytest_step = Step(name="Run Pytest Against Source Code", run=procedures.run_pytest_src) # Defining which test is going to run according to a profile if profile in (None, "", "default"): - steps.extend([mypy_step, pyright_step]) + steps.extend([create_mypy_pkg_step, mypy_step, destroy_mypy_pkg_step, pyright_step]) elif profile == "pytest": steps.extend([pytest_step]) elif profile == "full": - steps.extend([mypy_step, pyright_step, pytest_step]) + steps.extend([create_mypy_pkg_step, mypy_step, destroy_mypy_pkg_step, pyright_step, pytest_step]) else: raise Exception("Profile not found!") @@ -57,7 +61,9 @@ def test_all(clean_cache: bool = False): ]) steps.extend([ + Step(name="Create mypy package file", run=procedures.create_mypy_pkg_file), Step(name="Run Mypy Against Source Code", run=procedures.run_mypy_src), + Step(name="Destroy mypy package file", run=procedures.destroy_mypy_pkg_file), Step(name="Run Pyright Against Source Code", run=procedures.run_pyright_src), Step(name="Run Pytest Against Source Code", run=procedures.run_pytest_src), Step(name="Build Dist", run=procedures.build_dist), diff --git a/scripts/test/procedures.py b/scripts/test/procedures.py index ce3a98d05..8cf786248 100644 --- a/scripts/test/procedures.py +++ b/scripts/test/procedures.py @@ -5,7 +5,7 @@ def create_mypy_pkg_file(): - pkg_path = [x for x in sys.path if x.endswith('site-packages')] + pkg_path = [path for path in sys.path if path.endswith('site-packages')] if not Path(fr'{pkg_path[0]}/my_path.pth').exists(): with open(fr'{pkg_path[0]}/my_path.pth', 'w') as file: @@ -13,17 +13,15 @@ def create_mypy_pkg_file(): def destroy_mypy_pkg_file(): - pkg_path = [x for x in sys.path if x.endswith('site-packages')] + pkg_path = [path for path in sys.path if path.endswith('site-packages')] if Path(fr'{pkg_path[0]}/my_path.pth').exists(): Path(fr'{pkg_path[0]}/my_path.pth').unlink() def run_mypy_src(): - create_mypy_pkg_file() cmd = ["mypy", "pandas-stubs", "tests", "--no-incremental"] subprocess.run(cmd, check=True) - destroy_mypy_pkg_file() def run_pyright_src(): @@ -47,25 +45,13 @@ def install_dist(): subprocess.run(cmd, check=True) -def add_last_changes(): - cmd = ["git", "add", "."] - subprocess.run(cmd, check=True) - - -def commit_last_changes(): - cmd = ["git", "commit", "-am", "\"temp commit\""] - subprocess.run(cmd, check=True) - - def remove_src(): shutil.rmtree(r"pandas-stubs") def run_mypy_dist(): - create_mypy_pkg_file() cmd = ["mypy", "tests", "--no-incremental"] subprocess.run(cmd, check=True) - destroy_mypy_pkg_file() def run_pyright_dist(): @@ -78,18 +64,6 @@ def uninstall_dist(): subprocess.run(cmd, check=True) -def restore_last_changes(): - cmd = ["git", "show", "-s", "--format=%s"] - process = subprocess.Popen(cmd, stdout=subprocess.PIPE) - last_commit_name = process.communicate()[0] - - if last_commit_name == b'"temp commit"\n': - cmd = ["git", "reset", "--soft", "HEAD~1"] - subprocess.run(cmd, check=True) - else: - print("There is not temp commit to restore.") - - def restore_src(): cmd = ["git", "checkout", "HEAD", "pandas-stubs"] subprocess.run(cmd, check=True) From a37d1366f234d67750ee0dabca63669fef0cb9ab Mon Sep 17 00:00:00 2001 From: "Breno Fernandes (Mac OS)" Date: Wed, 29 Jun 2022 20:05:43 -0400 Subject: [PATCH 3/4] Fix: Add Create mypy pkg in CI --- .github/workflows/test.yml | 3 +++ pyproject.toml | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index edda79616..4c2cccc91 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -37,6 +37,9 @@ jobs: - name: Install project dependencies run: poetry install -vvv --no-root + - name: Create MyPy Package File + run: poetry run poe create_mypy_pkg_file + - name: Run MyPy Against Source Code run: poetry run poe run_mypy_src diff --git a/pyproject.toml b/pyproject.toml index 5b5354f2f..b8a06c6a6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -89,6 +89,10 @@ script = "scripts.test:test_all(clean_cache)" options = ["-c", "--clean_cache"] default = false +[tool.poe.tasks.create_mypy_pkg_file] +help = "CI Test | Create mypy package file" +script = "scripts.test.procedures:create_mypy_pkg_file" + [tool.poe.tasks.run_mypy_src] help = "CI Test | Run mypy against source code" script = "scripts.test.procedures:run_mypy_src" From a10dfe0ee6b3427083c8751fab0aca229152e3e9 Mon Sep 17 00:00:00 2001 From: Breno Fernandes Date: Sat, 2 Jul 2022 21:19:33 -0230 Subject: [PATCH 4/4] Merge: Solving conflicts --- scripts/test/__init__.py | 1 - scripts/test/procedures.py | 76 -------------------------------------- 2 files changed, 77 deletions(-) delete mode 100644 scripts/test/procedures.py diff --git a/scripts/test/__init__.py b/scripts/test/__init__.py index 8ec7ef7da..d89102c41 100644 --- a/scripts/test/__init__.py +++ b/scripts/test/__init__.py @@ -2,7 +2,6 @@ from scripts.test import _step - def test_src(profile: str, clean_cache: bool = False): steps = [] if clean_cache: diff --git a/scripts/test/procedures.py b/scripts/test/procedures.py deleted file mode 100644 index 4017c7464..000000000 --- a/scripts/test/procedures.py +++ /dev/null @@ -1,76 +0,0 @@ -import shutil -import subprocess -from pathlib import Path - -from scripts._job import Step, run_job - - -def run_mypy_src(): - cmd = ["mypy", "pandas-stubs", "tests", "--no-incremental"] - subprocess.run(cmd, check=True) - - -def run_pyright_src(): - cmd = ["pyright"] - subprocess.run(cmd, check=True) - - -def run_pytest_src(): - cmd = ["pytest"] - subprocess.run(cmd, check=True) - - -def build_dist(): - cmd = ["poetry", "build", "-f", "wheel"] - subprocess.run(cmd, check=True) - - -def install_dist(): - path = next(Path("dist/").glob("*.whl")) - cmd = ["pip", "install", str(path)] - subprocess.run(cmd, check=True) - - -def remove_src(): - shutil.rmtree(r"pandas-stubs") - - -def run_mypy_dist(): - cmd = ["mypy", "tests", "--no-incremental"] - subprocess.run(cmd, check=True) - - -def run_pyright_dist(): - cmd = ["pyright", "tests"] - subprocess.run(cmd, check=True) - -def uninstall_dist(): - cmd = ["pip", "uninstall", "-y", "pandas-stubs"] - subprocess.run(cmd, check=True) - - -def restore_src(): - cmd = ["git", "checkout", "HEAD", "pandas-stubs"] - subprocess.run(cmd, check=True) - - -def clean_mypy_cache(): - if Path('.mypy_cache').exists(): - shutil.rmtree('.mypy_cache') - - -def clean_pytest_cache(): - if Path('.mypy_cache').exists(): - shutil.rmtree('.pytest_cache') - - -def create_new_venv(): - cmd = ["poetry", "remove", "python"] - subprocess.run(cmd, check=True) - - cmd = ["poetry", "update", "-vvv"] - subprocess.run(cmd, check=True) - - cmd = ["poetry", "shell"] - subprocess.run(cmd, check=True) -