-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from DavidVujic/add_info_command_with_basic_fun…
…ctionality Add info command with basic functionality
- Loading branch information
Showing
17 changed files
with
126 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dir_name = "bases" |
3 changes: 1 addition & 2 deletions
3
poetry_polylith_plugin/components/bases.py → ...olylith_plugin/components/bases/create.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dir_name = "components" |
3 changes: 1 addition & 2 deletions
3
..._polylith_plugin/components/components.py → ...th_plugin/components/components/create.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dir_name = "projects" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters