Skip to content

Commit

Permalink
Merge pull request #1 from DavidVujic/generate_readme
Browse files Browse the repository at this point in the history
Add a README.md when creating a new Polylith workspace
  • Loading branch information
DavidVujic authored Feb 13, 2022
2 parents e3c3db9 + 4f9e173 commit 2054baf
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 25 deletions.
48 changes: 26 additions & 22 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion poetry_polylith_plugin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from poetry_polylith_plugin.plugin import PolylithPlugin

__version__ = "0.1.2"
__version__ = "0.2.0"

__all__ = ["PolylithPlugin"]
Empty file.
Empty file.
21 changes: 21 additions & 0 deletions poetry_polylith_plugin/components/log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import logging


def getHandler():
handler = logging.StreamHandler()
formatter = logging.Formatter("%(name)s: %(message)s")

handler.setFormatter(formatter)

return handler


def getLogger(name="poetry-polylith-plugin"):
logger = logging.getLogger(name)

if not logger.hasHandlers():
handler = getHandler()
logger.addHandler(handler)
logger.setLevel(logging.INFO)

return logger
31 changes: 31 additions & 0 deletions poetry_polylith_plugin/components/readme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from pathlib import Path

from poetry_polylith_plugin.components import log, repo


template = """\
# A Python Polylith repo
The top namespace is `{namespace}`.
## Docs
The official Polylith documentation:
[high-level documentation](https://polylith.gitbook.io/polylith)
A Python implementation of the Polylith tool:
[poetry-polylith-plugin](https://github.com/DavidVujic/poetry-polylith-plugin#poetry-polylith-plugin)
"""


logger = log.getLogger()


def create_workspace_readme(path: Path, namespace: str):
fullpath = path / repo.readme_file

if fullpath.exists():
logger.info(f"A {repo.readme_file} already exists. Skipping this step.")
return

with fullpath.open("w", encoding="utf-8") as f:
f.write(template.format(namespace=namespace))
1 change: 1 addition & 0 deletions poetry_polylith_plugin/components/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

workspace_file = "workspace.toml"
default_toml = "pyproject.toml"
readme_file = "README.md"


def is_repo_root(cwd: Path) -> bool:
Expand Down
4 changes: 3 additions & 1 deletion poetry_polylith_plugin/components/workspaces.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pathlib import Path

import tomlkit
from poetry_polylith_plugin.components import bases, components, projects, repo
from poetry_polylith_plugin.components import bases, components, projects, readme, repo
from poetry_polylith_plugin.components.development import create_development
from poetry_polylith_plugin.components.dirs import create_dir

Expand Down Expand Up @@ -38,3 +38,5 @@ def create_workspace(path: Path, namespace: str):
create_development(path, keep=True)

create_workspace_config(path, namespace)

readme.create_workspace_readme(path, namespace)
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.1.2"
version = "0.2.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 2054baf

Please sign in to comment.