Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Fix: mypy now creates a temp file to locate and test the pkg
  • Loading branch information
Breno Fernandes (Mac OS) committed Jun 29, 2022
commit 2ca61ab0d268ee09787aecc4342ee113d13f0e1d
9 changes: 1 addition & 8 deletions scripts/__init__.py
Original file line number Diff line number Diff line change
@@ -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": [
{
Expand Down
46 changes: 45 additions & 1 deletion scripts/test/procedures.py
Original file line number Diff line number Diff line change
@@ -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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If for some reason this fails, the file would still be there. Can't you use the rollback technique you have used elsewhere in case of failure?

destroy_mypy_pkg_file()


def run_pyright_src():
Expand All @@ -31,24 +47,49 @@ def install_dist():
subprocess.run(cmd, check=True)


def add_last_changes():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be part of a different PR

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()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When testing the distribution, you do NOT want to have this file present, as the distribution is installed

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():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be a different PR

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)
Expand All @@ -74,3 +115,6 @@ def create_new_venv():
cmd = ["poetry", "shell"]
subprocess.run(cmd, check=True)


if __name__ == '__main__':
restore_last_changes()