Skip to content

Commit

Permalink
Merge pull request #3 from DavidVujic/add_info_command_with_basic_fun…
Browse files Browse the repository at this point in the history
…ctionality

Add info command with basic functionality
  • Loading branch information
DavidVujic authored Feb 27, 2022
2 parents 8707bf4 + 49e1053 commit 63b4b3b
Show file tree
Hide file tree
Showing 17 changed files with 126 additions and 7 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ Add a project:
poetry poly create project --name my_example_aws_lambada_project
```

Show info about the workspace:

``` shell
poetry poly info
```
__Note__: the `info` command currently displays the very basic workspace info. The feature is currently developed.
Stay tuned for upcoming versions!


## Differences between the Clojure & Python implementations
First, this plugin only has the very basic features (yet). Functionality will be added, step by step.

Expand Down
2 changes: 2 additions & 0 deletions poetry_polylith_plugin/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
from poetry_polylith_plugin.commands.create_component import CreateComponentCommand
from poetry_polylith_plugin.commands.create_project import CreateProjectCommand
from poetry_polylith_plugin.commands.create_workspace import CreateWorkspaceCommand
from poetry_polylith_plugin.commands.info import InfoCommand


__all__ = [
"CreateBaseCommand",
"CreateComponentCommand",
"CreateProjectCommand",
"CreateWorkspaceCommand",
"InfoCommand",
]
27 changes: 27 additions & 0 deletions poetry_polylith_plugin/commands/info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from pathlib import Path

from poetry.console.commands.command import Command
from poetry_polylith_plugin.components import bases, components, projects, repo, workspaces


class InfoCommand(Command):
name = "poly info"
description = "Info about the <comment>Polylith</> workspace."

def handle(self) -> int:
root = repo.find_workspace_root(Path.cwd())
if not root:
raise ValueError(
"Didn't find the workspace root. Expected to find a workspace.toml file."
)

ns = workspaces.get_namespace_from_config(root)
project_names = projects.get_project_names(root)
components_data = components.get_components_data(root, ns)
bases_data = bases.get_bases_data(root, ns)

self.line(f"<comment>projects</>: {len(project_names)}")
self.line(f"<comment>components</>: {len(components_data)}")
self.line(f"<comment>bases</>: {len(bases_data)}")

return 0
6 changes: 6 additions & 0 deletions poetry_polylith_plugin/components/bases/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from poetry_polylith_plugin.components.bases.constants import dir_name
from poetry_polylith_plugin.components.bases.create import create_base
from poetry_polylith_plugin.components.bases.get import get_bases_data


__all__ = ["create_base", "get_bases_data", "dir_name"]
1 change: 1 addition & 0 deletions poetry_polylith_plugin/components/bases/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dir_name = "bases"
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from pathlib import Path

from poetry_polylith_plugin.components.bases.constants import dir_name
from poetry_polylith_plugin.components.blocks import create_block
from poetry_polylith_plugin.components.tests import create_test

dir_name = "bases"


def create_base(path: Path, namespace: str, package: str):
create_block(path, dir_name, namespace, package)
Expand Down
8 changes: 8 additions & 0 deletions poetry_polylith_plugin/components/bases/get.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from pathlib import Path

from poetry_polylith_plugin.components import components
from poetry_polylith_plugin.components.bases.constants import dir_name


def get_bases_data(path: Path, ns: str):
return components.get_components_data(path, ns, dir_name)
6 changes: 6 additions & 0 deletions poetry_polylith_plugin/components/components/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from poetry_polylith_plugin.components.components.constants import dir_name
from poetry_polylith_plugin.components.components.create import create_component
from poetry_polylith_plugin.components.components.get import get_components_data


__all__ = ["create_component", "get_components_data", "dir_name"]
1 change: 1 addition & 0 deletions poetry_polylith_plugin/components/components/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dir_name = "components"
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from pathlib import Path

from poetry_polylith_plugin.components.blocks import create_block
from poetry_polylith_plugin.components.components.constants import dir_name
from poetry_polylith_plugin.components.tests import create_test

dir_name = "components"


def create_component(path: Path, namespace: str, package: str):
create_block(path, dir_name, namespace, package)
Expand Down
30 changes: 30 additions & 0 deletions poetry_polylith_plugin/components/components/get.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from pathlib import Path

from poetry_polylith_plugin.components.components.constants import dir_name


def get_component_dirs(path: Path, top_dir):
component_dir = path / top_dir

return (f for f in component_dir.iterdir() if f.is_dir())


def dirs(path, ns, parent):
return (f.name for f in path.glob(f"{parent}/{ns}/{path.name}") if f.is_dir())


def component_dirs(path: Path, ns: str):
src_dirs = dirs(path, ns, "src")
test_dirs = dirs(path, ns, "test")

return {
"name": path.name,
"src": True if next(src_dirs, None) else False,
"test": True if next(test_dirs, None) else False,
}


def get_components_data(path: Path, ns: str, top_dir: str = dir_name):
dirs = get_component_dirs(path, top_dir)

return [component_dirs(d, ns) for d in dirs]
6 changes: 6 additions & 0 deletions poetry_polylith_plugin/components/projects/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from poetry_polylith_plugin.components.projects.constants import dir_name
from poetry_polylith_plugin.components.projects.create import create_project
from poetry_polylith_plugin.components.projects.get import get_project_names


__all__ = ["create_project", "get_project_names", "dir_name"]
1 change: 1 addition & 0 deletions poetry_polylith_plugin/components/projects/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dir_name = "projects"
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import tomlkit
from poetry_polylith_plugin.components import repo
from poetry_polylith_plugin.components.projects.constants import dir_name
from poetry_polylith_plugin.components.dirs import create_dir

dir_name = "projects"

template = """\
[tool.poetry]
name = "{name}"
Expand Down
23 changes: 23 additions & 0 deletions poetry_polylith_plugin/components/projects/get.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from pathlib import Path

import tomlkit


def get_project_name(data):
return data.get("tool", {}).get("poetry", {}).get("name")


def get_toml(path: Path) -> dict:
with path.open() as f:
return tomlkit.loads(f.read())


def get_project_files(path: Path):
return path.glob("projects/**/*.toml")


def get_project_names(path):
file_paths = get_project_files(path) or []
tomls = (get_toml(p) for p in file_paths)

return [get_project_name(d) for d in tomls]
2 changes: 2 additions & 0 deletions poetry_polylith_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
CreateComponentCommand,
CreateProjectCommand,
CreateWorkspaceCommand,
InfoCommand,
)

commands = [
CreateBaseCommand,
CreateComponentCommand,
CreateProjectCommand,
CreateWorkspaceCommand,
InfoCommand,
]


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "poetry-polylith-plugin"
version = "0.2.0"
version = "0.3.0"
description = "A Poetry plugin that aims to simplify working with Polylith monorepos"
authors = ["David Vujic"]
homepage = "https://github.com/davidvujic/poetry-polylith-plugin"
Expand Down

0 comments on commit 63b4b3b

Please sign in to comment.