Browse Source

add "shut mono" command group and "shut mono status" and "shut pkg status" commands

shut
Niklas Rosenstein 10 months ago
parent
commit
b6fc8ee4fb
No known key found for this signature in database GPG Key ID: 6D269B33D25F6C6
7 changed files with 193 additions and 6 deletions
  1. + 1
    - 0
      src/shore/commands/__init__.py
  2. + 33
    - 0
      src/shore/commands/commons/__init__.py
  3. + 59
    - 0
      src/shore/commands/commons/status.py
  4. + 38
    - 0
      src/shore/commands/mono/__init__.py
  5. + 29
    - 0
      src/shore/commands/mono/status.py
  6. + 4
    - 6
      src/shore/commands/pkg/__init__.py
  7. + 29
    - 0
      src/shore/commands/pkg/status.py

+ 1
- 0
src/shore/commands/__init__.py

@ -72,4 +72,5 @@ def shut(cwd, verbose, quiet):
from . import classifiers
from . import license
from . import mono
from . import pkg

+ 33
- 0
src/shore/commands/commons/__init__.py

@ -0,0 +1,33 @@
# -*- 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.
from shore.model import ObjectCache
import os
object_cache = ObjectCache()
def load_manifest(filename_choices, cls):
filename_choices = tuple(filename_choices)
for filename in filename_choices:
if os.path.isfile(filename):
return cls.load(filename, object_cache)
raise RuntimeError('file not found: ' + repr(filename_choices))

+ 59
- 0
src/shore/commands/commons/status.py

@ -0,0 +1,59 @@
# -*- 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.
from nr.utils.git import Git
from shore.model import Monorepo, Package
from termcolor import colored
from typing import Union
def get_commits_since_last_tag(subject: Union[Monorepo, Package]):
tag = subject.get_tag(subject.version)
ref = Git().rev_parse(tag)
if not ref:
return tag, None
else:
return tag, len(Git().rev_list(tag + '..HEAD', subject.directory))
def print_status(subject: Union[Monorepo, Package]) -> None:
"""
Prints the release status of a package or the packages in a monorepo.
"""
items = [subject]
if isinstance(subject, Monorepo):
items.extend(sorted(subject.get_packages(), key=lambda x: x.name))
if not subject.version:
items.remove(subject)
width = max(len(x.local_name) for x in items)
for item in items:
tag, num_commits = get_commits_since_last_tag(item)
if num_commits is None:
item_info = colored('tag "{}" not found'.format(tag), 'red')
elif num_commits == 0:
item_info = colored('no commits', 'green') + ' since "{}"'.format(tag)
else:
item_info = colored('{} commit(s)'.format(num_commits), 'yellow') + ' since "{}"'.format(tag)
print('{}: {}'.format(item.local_name.rjust(width), item_info))

+ 38
- 0
src/shore/commands/mono/__init__.py

@ -0,0 +1,38 @@
# -*- 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.
from .. import shut, commons
from shore.model import Monorepo
import click
@shut.group(help=__doc__)
def mono():
"""
Manage the current mono repository.
"""
def load_monorepo_manifest() -> Monorepo:
return commons.load_manifest(('monorepo.yaml', 'monorepo.yml'), Monorepo)
from . import status

+ 29
- 0
src/shore/commands/mono/status.py

@ -0,0 +1,29 @@
# -*- 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.
from . import mono, load_monorepo_manifest
from ..commons.status import print_status
import click
@mono.command()
def status():
print_status(load_monorepo_manifest())

+ 4
- 6
src/shore/commands/pkg/__init__.py

@ -19,12 +19,10 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
from .. import shut
from shore.model import Package, ObjectCache
from .. import shut, commons
from shore.model import Package
import click
_cache = ObjectCache()
@shut.group(help=__doc__)
def pkg():
@ -34,9 +32,9 @@ def pkg():
def load_package_manifest() -> Package:
filename = 'package.yaml'
return Package.load(filename, _cache)
return commons.load_manifest(('package.yaml', 'package.yml'), Package)
from . import bootstrap
from . import sanity
from . import status

+ 29
- 0
src/shore/commands/pkg/status.py

@ -0,0 +1,29 @@
# -*- 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.
from . import pkg, load_package_manifest
from ..commons.status import print_status
import click
@pkg.command()
def status():
print_status(load_package_manifest())

Loading…
Cancel
Save