Skip to content

Commit 6cd7b4b

Browse files
committed
Merge create and generate in commands to address import issues
1 parent bf501d7 commit 6cd7b4b

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

logya/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
__author__ = 'Ramiro Gómez'
22
__email__ = 'code@ramiro.org'
3-
__version__ = '5.2.2'
3+
__version__ = '5.3.0'

logya/generate.py renamed to logya/commands.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,31 @@
11
import shutil
2-
from shutil import copytree
2+
import sys
3+
from importlib import resources
34

45
from logya.content import write_collection, write_page
56
from logya.core import Logya
7+
from logya.util import paths
8+
9+
10+
def create(dir_site: str, name: str, site: str, **_kwargs) -> None:
11+
"""Create a new site in the specified directory."""
12+
13+
target = paths(dir_site=dir_site).root.joinpath(name)
14+
if target.exists():
15+
sys.exit(f'Error: "{target}" already exists. Please remove it or specify another location.')
16+
17+
source = resources.files(__name__).joinpath(f'sites/{site}')
18+
if source.is_dir():
19+
shutil.copytree(source, target) # type: ignore
20+
else:
21+
sys.exit(f'The site "{site}" is not installed.')
22+
23+
print(f'Site created in "{target}".')
624

725

826
def generate(dir_site: str, verbose: bool, keep: bool, **_kwargs):
27+
"""Generate a site in the public directory."""
28+
929
L = Logya(dir_site=dir_site, verbose=verbose)
1030
L.build()
1131

@@ -16,7 +36,7 @@ def generate(dir_site: str, verbose: bool, keep: bool, **_kwargs):
1636
print(f'Generate site in directory: {L.paths.public.as_posix()}')
1737
if L.paths.static.exists():
1838
print('Copy static files.')
19-
copytree(L.paths.static, L.paths.public, dirs_exist_ok=True)
39+
shutil.copytree(L.paths.static, L.paths.public, dirs_exist_ok=True)
2040

2141
print('Write pages.')
2242
for url, content in L.doc_index.items():

logya/create.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

logya/main.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
import argparse
33

44
from logya import __version__
5-
from logya.create import create
6-
from logya.generate import generate
5+
from logya.commands import create, generate
76
from logya.server import serve
87

98

0 commit comments

Comments
 (0)