Skip to content

Commit

Permalink
Fixed per testing
Browse files Browse the repository at this point in the history
  • Loading branch information
sophie-katz committed Aug 11, 2023
1 parent 24aa6ab commit ee82df8
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 16 deletions.
21 changes: 20 additions & 1 deletion template/pyproject.toml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,25 @@ py-modules = ["{{ module_name }}"]
[tool.pdm.scripts]
pre_lock = { shell = "python3 scripts/pdm_lockfile.py check" }
pre_install = { shell = "python3 scripts/pdm_lockfile.py check" }
lockfile = { shell = "python3 scripts/pdm_lockfile.py" }
"lint:mypy" = { shell = "mypy {{ module_name }}" }
"lint:pycodestyle" = { shell = "pycodestyle --ignore E501,W503,E261 {{ module_name }}" }
"lint:pydocstyle" = { shell = "pydocstyle {{ module_name }}" }
"lint:bandit" = { shell = "bandit -s B101 -r {{ module_name }}" }
"lint:vulture" = { shell = "vulture {{ module_name }}" }
"lint:isort" = { shell = "isort -c {{ module_name }}" }
lint = { composite = [
"lint:mypy",
"lint:pycodestyle",
"lint:pydocstyle",
"lint:bandit",
"lint:vulture",
"lint:isort",
] }
"format:black" = { shell = "black language_model" }
"format:isort" = { shell = "isort language_model" }
format = { composite = ["format:black", "format:isort"] }
test = { shell = "pytest language_model" }
[tool.pdm.dev-dependencies]
dev = [
Expand All @@ -47,6 +64,8 @@ dev = [
"vulture>=2.7",
"pyyaml>=6.0.1",
"termcolor>=2.3.0",
"types-requests>=2.31.0.2",
"types-tqdm>=4.66.0.0",
]
{%if use_pytorch %}
[project.optional-dependencies]
Expand Down
Empty file.
1 change: 1 addition & 0 deletions template/{{ module_name }}/__init__.py.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% include('includes/license_blurb_hashes.jinja') %}"""{{ project_name }} top-level module."""
6 changes: 5 additions & 1 deletion template/{{ module_name }}/settings.py.jinja
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{% include('includes/license_blurb_hashes.jinja') %}"""Project settings loaded from environment variables."""


from pydantic_settings import BaseSettings, SettingsConfigDict
# pycodestyle: disable=E621
from pydantic_settings import BaseSettings, SettingsConfigDict # type: ignore


class Settings(BaseSettings):
Expand All @@ -15,3 +16,6 @@ class Settings(BaseSettings):
comet_api_key: str
comet_project_name: str
comet_workspace: str


__all__ = ["Settings"]
Empty file.
1 change: 1 addition & 0 deletions template/{{ module_name }}/utils/__init__.py.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% include('includes/license_blurb_hashes.jinja') %}"""Utilities to support package."""
9 changes: 5 additions & 4 deletions template/{{ module_name }}/utils/download.py.jinja
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
{% include('includes/license_blurb_hashes.jinja') %}"""Utility functions for downloading files."""


from typing import Union
import pathlib
import requests
from typing import Union

import requests
from tqdm import tqdm


CHUNK_SIZE = 16384


def download_http(url: str, output_path: Union[str, pathlib.Path]) -> None:
"""Download a file from a URL to a local path."""

print(f"Downloading {url!r} to {output_path}...")

response = requests.get(url, stream=True, timeout=30)
Expand All @@ -38,3 +36,6 @@ def download_http(url: str, output_path: Union[str, pathlib.Path]) -> None:
progress_bar.close()

print(" Download complete.")


__all__ = ["download_http"]
3 changes: 1 addition & 2 deletions template/{{ module_name }}/utils/download_test.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

import os

from . import download
from . import project_paths
from . import download, project_paths


def test_download_http() -> None:
Expand Down
5 changes: 4 additions & 1 deletion template/{{ module_name }}/utils/extract.py.jinja
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{% include('includes/license_blurb_hashes.jinja') %}"""Utility functions for working with ZIP archives."""


from typing import Union
import pathlib
import zipfile
from typing import Union

from tqdm import tqdm

Expand Down Expand Up @@ -34,3 +34,6 @@ def extract_archive(
progress_bar.close()

print(" Extraction complete.")


__all__ = ["extract_archive"]
4 changes: 1 addition & 3 deletions template/{{ module_name }}/utils/extract_test.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

import os

from . import download
from . import extract
from . import project_paths
from . import download, extract, project_paths


def test_extract_archive() -> None:
Expand Down
16 changes: 14 additions & 2 deletions template/{{ module_name }}/utils/project_paths.py.jinja
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{% include('includes/license_blurb_hashes.jinja') %}"""Utility functions for dealing with paths within the project."""


from typing import Optional
import os
import pathlib
import re
from typing import Optional


def _is_git_repo(path: pathlib.Path) -> bool:
Expand Down Expand Up @@ -157,3 +156,16 @@ def get_dir_models(
return _optionally_create_and_return(
get_project_root_path(cwd) / "artifacts" / "models", create
)


# fmt: off
__all__ = [
"get_project_root_path",
"get_dir_artifacts_data_raw",
"get_dir_artifacts_data_intermediate",
"get_dir_artifacts_data_cache",
"get_dir_checkpoints",
"get_dir_logs",
"get_dir_models"
]
# fmt: on
46 changes: 44 additions & 2 deletions tests/test_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def _create_directory_test_minimal(license: str, cuda_version: str) -> Directory
]
),
}
)
),
},
)

Expand Down Expand Up @@ -422,7 +422,49 @@ def _run_copy_test(

directory_test.run(copy_directory)

result = subprocess.run(["pdm", "run", "pytest"], cwd=copy_directory)
result = subprocess.run(["pdm", "run", "lint:mypy"], cwd=copy_directory)

assert result.returncode == 0

result = subprocess.run(["pdm", "run", "lint:pycodestyle"], cwd=copy_directory)

assert result.returncode == 0

result = subprocess.run(["pdm", "run", "lint:pydocstyle"], cwd=copy_directory)

assert result.returncode == 0

result = subprocess.run(["pdm", "run", "lint:bandit"], cwd=copy_directory)

assert result.returncode == 0

result = subprocess.run(["pdm", "run", "lint:vulture"], cwd=copy_directory)

assert result.returncode == 0

result = subprocess.run(["pdm", "run", "lint:isort", "--df"], cwd=copy_directory)

assert result.returncode == 0

result = subprocess.run(["pdm", "run", "lint"], cwd=copy_directory)

assert result.returncode == 0

result = subprocess.run(
["pdm", "run", "format:black", "--diff"], cwd=copy_directory
)

assert result.returncode == 0

result = subprocess.run(["pdm", "run", "format:isort", "-c"], cwd=copy_directory)

assert result.returncode == 0

result = subprocess.run(["pdm", "run", "format"], cwd=copy_directory)

assert result.returncode == 0

result = subprocess.run(["pdm", "run", "test"], cwd=copy_directory)

assert result.returncode == 0

Expand Down

0 comments on commit ee82df8

Please sign in to comment.