Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
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
12 changes: 9 additions & 3 deletions scripts/test/__init__.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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!")

Expand Down Expand Up @@ -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),
Copy link
Collaborator

Choose a reason for hiding this comment

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

don't you need a rollback here?

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),
Expand Down
20 changes: 19 additions & 1 deletion scripts/test/procedures.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
import shutil
import subprocess
from pathlib import Path
import sys

from scripts._job import Step, run_job

def create_mypy_pkg_file():
pkg_path = [path for path in sys.path if path.endswith('site-packages')]
Copy link
Member

Choose a reason for hiding this comment

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

A contextmanager would here also be nice, but I'm not sure whether that fits easily in the structure of having multiple steps.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it could work using tempfile lib, thx.


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


if __name__ == '__main__':
restore_last_changes()