Skip to content

Commit

Permalink
Address changes request, update readme and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jhonabreul committed Sep 15, 2022
1 parent df8d814 commit 9fe0234
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 45 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ A locally-focused workflow (local development, local execution) with the CLI may
- [`lean create-project`](#lean-create-project)
- [`lean data download`](#lean-data-download)
- [`lean data generate`](#lean-data-generate)
- [`lean delete-project`](#lean-delete-project)
- [`lean init`](#lean-init)
- [`lean library add`](#lean-library-add)
- [`lean library remove`](#lean-library-remove)
Expand Down Expand Up @@ -632,6 +633,24 @@ Options:

_See code: [lean/commands/data/generate.py](lean/commands/data/generate.py)_

### `lean delete-project`

Delete a project locally and in the cloud if it exists.

```
Usage: lean delete-project [OPTIONS] PROJECT
Delete a project locally and in the cloud if it exists.
The project is selected by name or cloud id.
Options:
--verbose Enable debug logging
--help Show this message and exit.
```

_See code: [lean/commands/delete_project.py](lean/commands/delete_project.py)_

### `lean init`

Scaffold a Lean configuration file and data directory.
Expand Down
9 changes: 8 additions & 1 deletion lean/commands/cloud/pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,17 @@ def pull(project: Optional[str], pull_bootcamp: bool) -> None:
This command will not delete local files for which there is no counterpart in the cloud.
"""
# Parse which projects need to be pulled
project_id = None
if project is not None:
try:
project_id = int(project)
except ValueError:
pass

api_client = container.api_client()
all_projects = api_client.projects.get_all()
project_manager = container.project_manager()
projects_to_pull = project_manager.get_projects_by_name_or_id(all_projects, project)
projects_to_pull = project_manager.get_projects_by_name_or_id(all_projects, project_id or project)

if project is None and not pull_bootcamp:
projects_to_pull = [p for p in projects_to_pull if not p.name.startswith("Boot Camp/")]
Expand Down
4 changes: 2 additions & 2 deletions lean/commands/delete_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
@click.command(cls=LeanCommand)
@click.argument("project", type=str)
def delete_project(project: str) -> None:
"""Delete a project both locally and in remotely, if there is a counterpart in the cloud.
"""Delete a project locally and in the cloud if it exists.
The project is selected by name or id.
The project is selected by name or cloud id.
"""
# Remove project from cloud
api_client = container.api_client()
Expand Down
27 changes: 0 additions & 27 deletions lean/components/util/project_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,6 @@ def delete_project(self, project_dir: Path) -> None:
:param project_dir: the directory of the project to delete
"""
if not self._directory_is_project(project_dir):
raise RuntimeError(f"Project directory {project_dir} is not a valid Lean project directory")

try:
shutil.rmtree(project_dir)
except FileNotFoundError:
Expand Down Expand Up @@ -195,30 +192,6 @@ def get_projects_by_name_or_id(self, cloud_projects: List[QCProject],

return projects

def _directory_is_project(self, project_dir: Path) -> bool:
"""Checks if a directory is a project.
:param project_dir: the directory of the project to check
"""
if not project_dir.exists():
return False

config_file = project_dir / "config.json"
if not config_file.exists():
return False

project_language = None
with open(config_file) as file:
project_language = json.load(file)["algorithm-language"]

if project_language is None:
return False

if project_language == "Python":
return (project_dir / "main.py").exists() and (project_dir / "research.ipynb").exists()

return (project_dir / "Main.cs").exists() and (project_dir / "research.ipynb").exists()

def _generate_python_library_projects_config(self) -> None:
"""Generates the required configuration to enable autocomplete on Python library projects."""
try:
Expand Down
15 changes: 0 additions & 15 deletions tests/commands/test_delete_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,6 @@ def test_delete_project_aborts_when_path_does_not_exist() -> None:
mock_delete.assert_not_called()


def test_delete_project_aborts_when_path_is_no_a_valid_project() -> None:
create_fake_lean_cli_directory()

path = "Non Existing Project"
assert_project_does_not_exist(path)

with mock.patch.object(ProjectClient, 'get_all', return_value=create_cloud_projects()) as mock_get_all,\
mock.patch.object(ProjectClient, 'delete', return_value=None) as mock_delete:
result = CliRunner().invoke(lean, ["delete-project", path])
assert result.exit_code != 0

mock_get_all.assert_called_once()
mock_delete.assert_not_called()


def test_delete_project_by_id_aborts_when_not_found_in_cloud() -> None:
create_fake_lean_cli_directory()

Expand Down

0 comments on commit 9fe0234

Please sign in to comment.