diff --git a/README.md b/README.md index eee1519..62b9637 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,11 @@ ===================================== generator=datazen version=3.1.2 - hash=e17a2a1feecf3316dd227e4ef69c4351 + hash=a4e47be8738ab981e11e2267b94bc9fc ===================================== --> -# rcmpy ([1.1.1](https://pypi.org/project/rcmpy/)) +# rcmpy ([1.2.0](https://pypi.org/project/rcmpy/)) [![python](https://img.shields.io/pypi/pyversions/rcmpy.svg)](https://pypi.org/project/rcmpy/) ![Build Status](https://github.com/vkottler/rcmpy/workflows/Python%20Package/badge.svg) diff --git a/local/variables/package.yaml b/local/variables/package.yaml index 1de4416..88b52bd 100644 --- a/local/variables/package.yaml +++ b/local/variables/package.yaml @@ -1,5 +1,5 @@ --- major: 1 -minor: 1 -patch: 1 +minor: 2 +patch: 0 entry: rcmpy diff --git a/pyproject.toml b/pyproject.toml index 0ace383..4384c50 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta:__legacy__" [project] name = "rcmpy" -version = "1.1.1" +version = "1.2.0" description = "A configuration-file management system." readme = "README.md" requires-python = ">=3.7" diff --git a/rcmpy/__init__.py b/rcmpy/__init__.py index 70bdd8a..d981441 100644 --- a/rcmpy/__init__.py +++ b/rcmpy/__init__.py @@ -1,7 +1,7 @@ # ===================================== # generator=datazen # version=3.1.2 -# hash=8cf27e726efd71565b56531e6b4da766 +# hash=7d9db5b03071a6b0e78c3e545b31a7ea # ===================================== """ @@ -10,4 +10,4 @@ DESCRIPTION = "A configuration-file management system." PKG_NAME = "rcmpy" -VERSION = "1.1.1" +VERSION = "1.2.0" diff --git a/rcmpy/commands/apply.py b/rcmpy/commands/apply.py index 7169a0a..46c3c63 100644 --- a/rcmpy/commands/apply.py +++ b/rcmpy/commands/apply.py @@ -28,6 +28,9 @@ def apply_env(args: _Namespace, env: Environment) -> int: env.logger.error("Template '%s' not found!", file.template) continue + if not file.platform: + continue + is_new = env.state.is_new() # Check if this file has any updated templates. diff --git a/rcmpy/config/__init__.py b/rcmpy/config/__init__.py index 591e17d..4f1f6d8 100644 --- a/rcmpy/config/__init__.py +++ b/rcmpy/config/__init__.py @@ -45,6 +45,7 @@ def init(self, data: _JsonObject) -> None: Path(expandvars(file["directory"])).expanduser(), file.get("name", file["template"]), file["link"], + set(file.get("platforms", [])), ) # Keep track of all templates used in any file. diff --git a/rcmpy/config/file.py b/rcmpy/config/file.py index ddd21cc..9b45147 100644 --- a/rcmpy/config/file.py +++ b/rcmpy/config/file.py @@ -7,6 +7,7 @@ from dataclasses import dataclass from pathlib import Path from shutil import copyfile +import sys from typing import Set # third-party @@ -28,11 +29,18 @@ class ManagedFile: link: bool + platforms: Set[str] + @property def output(self) -> Path: """Get the full output path.""" return self.directory.joinpath(self.name) + @property + def platform(self) -> bool: + """Determine if the platform is correct for handling this file.""" + return not self.platforms or sys.platform in self.platforms + def update_root(self, root: Path) -> None: """ If the output directory is a relative path, update it to be an diff --git a/rcmpy/data/schemas/ManagedFile.yaml b/rcmpy/data/schemas/ManagedFile.yaml index d207055..37cb320 100644 --- a/rcmpy/data/schemas/ManagedFile.yaml +++ b/rcmpy/data/schemas/ManagedFile.yaml @@ -20,6 +20,12 @@ properties: name: type: string + platforms: + type: array + items: + type: string + enum: ["linux", "cygwin", "darwin", "win32"] + # Templates that may be included in the main template. extra_templates: type: array diff --git a/tests/data/valid/scenarios/simple/rcmpy.yaml b/tests/data/valid/scenarios/simple/rcmpy.yaml index 57d2f7d..6198905 100644 --- a/tests/data/valid/scenarios/simple/rcmpy.yaml +++ b/tests/data/valid/scenarios/simple/rcmpy.yaml @@ -7,3 +7,10 @@ files: - template: basic.txt link: false + + - template: linux.txt + platforms: [linux] + - template: darwin.txt + platforms: [darwin] + - template: win32.txt + platforms: [win32] diff --git a/tests/data/valid/scenarios/simple/templates/common/darwin.txt b/tests/data/valid/scenarios/simple/templates/common/darwin.txt new file mode 100644 index 0000000..dafe603 --- /dev/null +++ b/tests/data/valid/scenarios/simple/templates/common/darwin.txt @@ -0,0 +1 @@ +This will be handled on 'darwin' platforms. diff --git a/tests/data/valid/scenarios/simple/templates/common/linux.txt b/tests/data/valid/scenarios/simple/templates/common/linux.txt new file mode 100644 index 0000000..bf42f7a --- /dev/null +++ b/tests/data/valid/scenarios/simple/templates/common/linux.txt @@ -0,0 +1 @@ +This will be handled 'linux' platforms. diff --git a/tests/data/valid/scenarios/simple/templates/common/win32.txt b/tests/data/valid/scenarios/simple/templates/common/win32.txt new file mode 100644 index 0000000..a351b44 --- /dev/null +++ b/tests/data/valid/scenarios/simple/templates/common/win32.txt @@ -0,0 +1 @@ +This will be handled on 'win32' platforms.