Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
1aab2db
add: partial copy method
TOsmanov Mar 14, 2025
53ad1cd
update: github workflow
TOsmanov Mar 18, 2025
8ea6cdc
update: foliant, workflow, lint settings, bump python version, tests
TOsmanov Mar 20, 2025
d17b922
bump: dependency versions, tests python versions
TOsmanov Mar 21, 2025
6c73370
update: python to version 3.12
TOsmanov Apr 1, 2025
249b786
add: dependency on multiproject
TOsmanov Apr 14, 2025
52dd7d8
update: partial copy
TOsmanov Apr 17, 2025
2fc8559
update: context for preprocessors
TOsmanov May 13, 2025
c34437b
fix: tests
TOsmanov May 14, 2025
89ba030
add: partial build message
TOsmanov May 14, 2025
4e5bf81
fix: tests
TOsmanov May 14, 2025
8d7ccd6
fix: partial build types
TOsmanov May 16, 2025
d18bb02
update: make
TOsmanov May 16, 2025
5dd9260
fix: tests
TOsmanov May 19, 2025
480df1f
update: include regex
TOsmanov May 22, 2025
4e98b05
update: find and copy includes
TOsmanov May 22, 2025
f1bc02c
update: _copy_files_recursive
TOsmanov May 22, 2025
6e0f39e
fix: lint errors
TOsmanov May 27, 2025
a734808
update: skip files that are not found
TOsmanov Jun 11, 2025
66e8edc
update: images recursive copy
TOsmanov Jun 11, 2025
710d276
update: tests
TOsmanov Jul 7, 2025
6f70568
split partial_copy fix bugs
TOsmanov Sep 16, 2025
2e3d763
fix: lint errors
TOsmanov Sep 16, 2025
31d3dc6
add: tests for partial_copy
TOsmanov Sep 16, 2025
776f1ba
update: stdout
TOsmanov Sep 16, 2025
9173495
update: stdout
TOsmanov Sep 17, 2025
867a7fb
update: lint
TOsmanov Oct 14, 2025
e628965
fix: pylintrc
TOsmanov Oct 14, 2025
cdd5a58
update: changelog.md
TOsmanov Oct 14, 2025
5179720
update: image pattren for image with annotation
TOsmanov Oct 17, 2025
15b616d
add: test image with annotation
TOsmanov Oct 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.8", "3.9" ]
python-version: [ "3.9", "3.10", "3.11" ]

steps:
- uses: actions/checkout@v3
Expand All @@ -21,10 +21,12 @@ jobs:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
version: 2.1.1
- name: Install library
run: poetry install --no-interaction
- name: Lint and test with poetry
- name: Lint with poetry
run: poetry run pylint foliant
- name: Test with poetry
run: |
poetry run pytest --cov=foliant
poetry run codecov
poetry run pylint foliant
poetry run codecov
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 1.0.14

- Add the `--only-partial` argument for to limit the list of files that the foliant must process.
This function allows you to build a website from a single file, a list of files, or a glob mask.

# 1.0.13

- Add the `clean_registry` function to `make`.
Expand Down
2 changes: 1 addition & 1 deletion foliant/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.0.13'
__version__ = '1.0.14'
27 changes: 22 additions & 5 deletions foliant/backends/base.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from importlib import import_module
from shutil import copytree
from datetime import date
from importlib import import_module
from logging import Logger
from pathlib import Path
from shutil import copytree
from typing import Union, List
from foliant.partial_copy import PartialCopy

from foliant.utils import spinner


class BaseBackend():
'''Base backend. All backends must inherit from this one.'''

Expand Down Expand Up @@ -50,6 +52,8 @@ def apply_preprocessor(self, preprocessor: str or dict):

:param preprocessor: Preprocessor name or a dict of the preprocessor name and its options
'''
preprocessor_name = None
preprocessor_options = {}

if isinstance(preprocessor, str):
preprocessor_name, preprocessor_options = preprocessor, {}
Expand Down Expand Up @@ -82,6 +86,17 @@ def apply_preprocessor(self, preprocessor: str or dict):
f'Failed to apply preprocessor {preprocessor_name}: {exception}'
) from exception

@staticmethod
def partial_copy(
source: Union[str, Path, List[Union[str, Path]]],
root: Union[str, Path],
destination: Union[str, Path],
) -> None:
"""
Delegates to the PartialCopy class for file copying operations.
"""
PartialCopy.partial_copy(source, root, destination)

def preprocess_and_make(self, target: str) -> str:
'''Apply preprocessors required by the selected backend and defined in the config file,
then run the ``make`` method.
Expand All @@ -92,8 +107,10 @@ def preprocess_and_make(self, target: str) -> str:
'''

src_path = self.project_path / self.config['src_dir']

copytree(src_path, self.working_dir)
if self.context['only_partial'] != "":
self.partial_copy(self.context['only_partial'], src_path, self.working_dir)
else:
copytree(src_path, self.working_dir)

common_preprocessors = (
*self.required_preprocessors_before,
Expand Down
1 change: 0 additions & 1 deletion foliant/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class Foliant(*get_available_clis().values()):

@set_help({'version': 'show version and exit'})
def _root(self, version=False):
# pylint: disable=no-self-use

if version:
print(f'Foliant v.{foliant_version}')
Expand Down
32 changes: 31 additions & 1 deletion foliant/cli/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from importlib import import_module
from logging import DEBUG, WARNING
from typing import List, Dict, Tuple
from glob import glob

from cliar import set_arg_map, set_metavars, set_help, ignore
from prompt_toolkit import prompt
Expand Down Expand Up @@ -87,6 +88,27 @@ def get_matching_backend(target: str, available_backends: Dict[str, Tuple[str]])
except KeyboardInterrupt as kbd_interrupt:
raise BackendError('No backend specified') from kbd_interrupt

@staticmethod
def prepare_list_of_file(only_partial, project_path):
list_of_files = []
if isinstance(only_partial, str):
if ',' in only_partial:
only_partial = [item.strip() for item in only_partial.split(',')]
elif any(char in only_partial for char in '*?['):
list_of_files = [Path(file) for file in glob(only_partial, recursive=True)]
else:
only_partial = [Path(only_partial.strip())]

if isinstance(only_partial, list):
for item in only_partial:
item_path = Path(item) if Path(item).is_absolute() else Path(project_path, item)
list_of_files.append(item_path)
elif isinstance(only_partial, (str, Path)):
only_partial_path = Path(only_partial) if isinstance(only_partial,
str) else only_partial
list_of_files.append(only_partial_path)
return list_of_files

def clean_registry(self, project_path):
multiprojectcache_dir = os.path.join(project_path, '.multiprojectcache')
if os.path.isdir(multiprojectcache_dir):
Expand Down Expand Up @@ -140,6 +162,7 @@ def get_config(
'logs_dir': 'Path to the directory to store logs, defaults to project path.',
'quiet': 'Hide all output accept for the result. Useful for piping.',
'keep_tmp': 'Keep the tmp directory after the build.',
'only_partial': 'using only a partial list of files',
'debug': 'Log all events during build. If not set, only warnings and errors are logged.'
}
)
Expand All @@ -152,6 +175,7 @@ def make(
logs_dir='',
quiet=False,
keep_tmp=False,
only_partial='',
debug=False
):
'''Make TARGET with BACKEND.'''
Expand All @@ -161,6 +185,7 @@ def make(
# pylint: disable=consider-using-sys-exit

self.logger.setLevel(DEBUG if debug else WARNING)
result = None

if logs_dir:
super().__init__(logs_dir)
Expand All @@ -173,6 +198,9 @@ def make(

self.clean_registry(project_path)

if only_partial != "":
only_partial = self.prepare_list_of_file(only_partial, project_path)

try:
if backend:
self.validate_backend(backend, target)
Expand All @@ -189,7 +217,9 @@ def make(
'project_path': project_path,
'config': config,
'target': target,
'backend': backend
'backend': backend,
'keep_tmp': keep_tmp,
'only_partial': only_partial
}

backend_module = import_module(f'foliant.backends.{backend}')
Expand Down
Loading