Browse Source

add `AbstractProjectModel`, update `shut changelog`

shut-new-model
Niklas Rosenstein 9 months ago
parent
commit
fc260cbc7c
No known key found for this signature in database GPG Key ID: 6D269B33D25F6C6
5 changed files with 63 additions and 27 deletions
  1. + 22
    - 17
      src/shut/commands/changelog/__init__.py
  2. + 2
    - 2
      src/shut/model/__init__.py
  3. + 35
    - 0
      src/shut/model/abstract.py
  4. + 2
    - 3
      src/shut/model/monorepo.py
  5. + 2
    - 5
      src/shut/model/package.py

+ 22
- 17
src/shut/commands/changelog/__init__.py

@ -19,22 +19,24 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
from shore.__main__ import _edit_text, _editor_open, _load_subject
from shore.model import Package
from shore.util.version import parse_version
import logging
import sys
from typing import List, Optional
from nr.utils.git import Git
from termcolor import colored
import click
import yaml
from .. import shut, commons
from shore.__main__ import _edit_text, _editor_open
from .. import shut, commons, project
from shut.changelog import v3
from shut.changelog.manager import mapper, ChangelogManager
from shut.changelog.render import render as render_changelogs
from termcolor import colored
from typing import List, Optional
import click
import logging
import sys
import yaml
from shut.model.version import parse_version
from shut.model.package import PackageModel
_git = Git()
logger = logging.getLogger(__name__)
@ -61,15 +63,18 @@ def changelog(**args):
logger.error('unsupported combination of arguments')
sys.exit(1)
subject = _load_subject(allow_none=True)
if subject:
manager = ChangelogManager(subject.changelog_directory)
else:
manager = ChangelogManager(Package.changelog_directory.default)
project.load()
monorepo = project.monorepo
package = project.subject if project.subject != monorepo else None
def _split(s: Optional[str]) -> List[str]:
return list(filter(bool, map(str.strip, (s or '').split(','))))
manager = ChangelogManager(
package.get_changelog_directory() if package
else monorepo.get_changelog_directory() if monorepo
else '.changelog')
if args['add']:
if not args['for']:
@ -109,8 +114,8 @@ def changelog(**args):
_git.add([manager.unreleased.filename])
if args['commit']:
commit_message = entry.description
if isinstance(subject, Package) and subject.monorepo:
commit_message = '{}({}): '.format(entry.type_.name, subject.name) + commit_message
if package and monorepo:
commit_message = '{}({}): '.format(entry.type_.name, package.data.name) + commit_message
else:
commit_message = '{}: '.format(entry.type_.name) + commit_message
if fixes:

+ 2
- 2
src/shut/model/__init__.py

@ -23,7 +23,7 @@ import os
import sys
from typing import Any, List, T, TextIO, Tuple, Type, TypeVar, Union
from databind.core import datamodel, field, Registry
from databind.core import ConversionError, datamodel, field, Registry
from databind.json import from_json, to_json, registry as json_registry
from nr.stream import Stream
import yaml
@ -125,7 +125,7 @@ class Project:
if package_fn:
try:
self._load_package(package_fn)
except SerializationError as exc:
except ConversionError as exc:
self.invalid_packages.append((item_name, sys.exc_info()))
return self.monorepo

+ 35
- 0
src/shut/model/abstract.py

@ -0,0 +1,35 @@
# -*- coding: utf8 -*-
# Copyright (c) 2020 Niklas Rosenstein
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
import os
from typing import List, Optional
from databind.core import datamodel, field
from .changelog import ChangelogConfiguration
@datamodel
class AbstractProjectModel:
filename: Optional[str] = field(derived=True, default=None)
unknown_keys: List[str] = field(derived=True, default_factory=list)
changelog: ChangelogConfiguration = field(default_factory=ChangelogConfiguration)
def get_changelog_directory(self) -> str:
return os.path.join(os.path.dirname(self.filename), self.changelog.directory)

+ 2
- 3
src/shut/model/monorepo.py

@ -22,14 +22,13 @@
from typing import List, Optional
from databind.core import datamodel, field
from .author import Author
from .abstract import AbstractProjectModel
from .version import Version
from .release import MonorepoReleaseConfiguration
@datamodel
class MonorepoModel:
filename: Optional[str] = field(derived=True, default=None)
unknown_keys: List[str] = field(derived=True, default_factory=list)
class MonorepoModel(AbstractProjectModel):
name: str
version: Optional[Version] = None
author: Optional[Author] = None

+ 2
- 5
src/shut/model/package.py

@ -25,6 +25,7 @@ from typing import Dict, Iterable, List, Optional
from databind.core import datamodel, field
from shore.util.ast import load_module_members
from .abstract import AbstractProjectModel
from .author import Author
from .changelog import ChangelogConfiguration
from .linter import LinterConfiguration
@ -93,11 +94,8 @@ class InstallConfiguration:
@datamodel
class PackageModel:
filename: Optional[str] = field(derived=True, default=None)
unknown_keys: List[str] = field(derived=True, default_factory=list)
class PackageModel(AbstractProjectModel):
data: PackageData = field(altname='package')
changelog: ChangelogConfiguration = field(default_factory=ChangelogConfiguration)
install: InstallConfiguration = field(default_factory=InstallConfiguration)
linter: LinterConfiguration = field(default_factory=LinterConfiguration)
release: ReleaseConfiguration = field(default_factory=ReleaseConfiguration)
@ -128,7 +126,6 @@ class PackageModel:
prefix='README.',
preferred=['README.md', 'README.rst', 'README.txt', 'README'])
def get_license(self) -> Optional[str]:
"""
Returns the absolute path to the LICENSE file for this package.

Loading…
Cancel
Save