Browse Source

replace shore.utils.git with nr.utils.git

master
Niklas Rosenstein 1 month ago
parent
commit
4f6de36c8d
Signed by: NiklasRosenstein <rosensteinniklas@gmail.com> GPG Key ID: 06D269B33D25F6C6
6 changed files with 18 additions and 117 deletions
  1. +6
    -0
      .changelog/_unreleased.yml
  2. +1
    -0
      package.yaml
  3. +1
    -1
      setup.py
  4. +3
    -2
      src/shore/__main__.py
  5. +0
    -108
      src/shore/util/git.py
  6. +7
    -6
      src/shore/util/version.py

+ 6
- 0
.changelog/_unreleased.yml View File

@@ -0,0 +1,6 @@
- types:
- improvement
issues: []
components:
- general
description: Replace `shore.utils.git` with `nr.utils.git` module

+ 1
- 0
package.yaml View File

@@ -20,6 +20,7 @@ requirements:
- nr.fs ^1.5.0
- nr.pylang.utils ^0.0.1
- nr.proxy ^0.0.1
- nr.utils.git ~0.1.3
- requests ^2.22.0
- packaging ^20.1
- PyYAML ^5.1.0


+ 1
- 1
setup.py View File

@@ -19,7 +19,7 @@ else:
print("warning: file \"{}\" does not exist.".format(readme_file), file=sys.stderr)
long_description = None

requirements = ['beautifulsoup4 >=4.8.1,<5.0.0', 'click >=7.0,<8.0.0', 'jinja2 >=2.11.1,<3.0.0', 'networkx >=2.4,<3.0.0', 'nr.databind.core >=0.0.1,<0.1.0', 'nr.databind.json >=0.0.1,<0.1.0', 'nr.fs >=1.5.0,<2.0.0', 'nr.pylang.utils >=0.0.1,<1.0.0', 'nr.proxy >=0.0.1,<1.0.0', 'requests >=2.22.0,<3.0.0', 'packaging >=20.1,<21.0.0', 'PyYAML >=5.1.0,<6.0.0', 'termcolor >=1.1.0,<2.0.0', 'twine', 'wheel']
requirements = ['beautifulsoup4 >=4.8.1,<5.0.0', 'click >=7.0,<8.0.0', 'jinja2 >=2.11.1,<3.0.0', 'networkx >=2.4,<3.0.0', 'nr.databind.core >=0.0.1,<0.1.0', 'nr.databind.json >=0.0.1,<0.1.0', 'nr.fs >=1.5.0,<2.0.0', 'nr.pylang.utils >=0.0.1,<1.0.0', 'nr.proxy >=0.0.1,<1.0.0', 'nr.utils.git >=0.1.3,<0.2.0', 'requests >=2.22.0,<3.0.0', 'packaging >=20.1,<21.0.0', 'PyYAML >=5.1.0,<6.0.0', 'termcolor >=1.1.0,<2.0.0', 'twine', 'wheel']

setuptools.setup(
name = 'nr.shore',


+ 3
- 2
src/shore/__main__.py View File

@@ -22,6 +22,7 @@
from fnmatch import fnmatch
from nr.proxy import proxy_decorator
from nr.stream import Stream
from nr.utils.git import Git
from shore import __version__
from shore.core.plugins import (
CheckResult,
@@ -33,7 +34,6 @@ from shore.core.plugins import (
from shore.mapper import mapper
from shore.model import Monorepo, ObjectCache, Package, VersionSelector
from shore.plugins.core import get_monorepo_interdependency_version_refs
from shore.util import git as _git
from shore.util.changelog import ChangelogEntry, ChangelogManager, render_changelogs
from shore.util.classifiers import get_classifiers
from shore.util.license import get_license_metadata, wrap_license_text
@@ -57,6 +57,7 @@ import sys
import textwrap
import yaml

_git = Git()
_cache = ObjectCache()
logger = logging.getLogger(__name__)

@@ -588,7 +589,7 @@ def bump(**args):
_git.tag(tag_name, force=args['force'])

if not args['dry'] and args['push']:
_git.push(_git.current_branch(), tag_name, force=args['force'])
_git.push('origin', _git.get_current_branch_name(), tag_name, force=args['force'])

if args['publish']:
_cache.clear()


+ 0
- 108
src/shore/util/git.py View File

@@ -1,108 +0,0 @@
# -*- 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 typing import Iterable, List, Optional
import collections
import subprocess

Branch = collections.namedtuple('Branch', 'name,current')
FileStatus = collections.namedtuple('FileStatus', 'mode,filename')


def add(files: List[str], path: str = None):
command = ['git', 'add', '--'] + files
subprocess.check_call(command, cwd=path)


def branches(path: str = None) -> List[Branch]:
command = ['git', 'branch']
results = []
for line in subprocess.check_output(command, cwd=path).decode().splitlines():
current = False
if line.startswith('*'):
line = line[1:]
current = True
results.append(Branch(line.strip(), current))
return results


def current_branch(path: str = None) -> str:
for branch in branches(path):
if branch.current:
return branch.name
raise RuntimeError('no curent branch ?')


def push(*refs, remote='origin', force: bool = False, path: str = None):
command = ['git', 'push', remote] + list(refs)
if force:
command.insert(2, '-f')
subprocess.check_call(command, cwd=path)


def porcelain() -> Iterable[FileStatus]:
for line in subprocess.getoutput('git status --porcelain').split('\n'):
mode, filename = line.strip().partition(' ')[::2]
yield FileStatus(mode, filename)


def add(filenames: List[str]):
subprocess.check_call(['git', 'add'] + filenames)


def commit(message, allow_empty: bool=False):
command = ['git', 'commit', '-m', message]
if allow_empty:
command.append('--allow-empty')
subprocess.check_call(command)


def tag(tag_name: str, force: bool=False):
command = ['git', 'tag', tag_name] + (['-f'] if force else [])
subprocess.check_call(command)


def rev_parse(rev: str, path: str = None) -> Optional[str]:
command = ['git', 'rev-parse', rev]
try:
return subprocess.check_output(command, stderr=subprocess.STDOUT, cwd=path).decode().strip()
except subprocess.CalledProcessError:
return None


def rev_list(rev: str, path: str = None) -> List[str]:
command = ['git', 'rev-list', rev]
if path:
command += ['--', path]
revlist = subprocess.check_output(command, stderr=subprocess.STDOUT).decode().strip().split('\n')
if revlist == ['']:
revlist = []
return revlist


def has_diff(path: str = None) -> bool:
try:
subprocess.check_call(['git', 'diff', '--exit-code'], stdout=subprocess.PIPE)
return False
except subprocess.CalledProcessError as exc:
if exc.returncode == 1:
return True
raise

+ 7
- 6
src/shore/util/version.py View File

@@ -20,7 +20,7 @@
# IN THE SOFTWARE.

from packaging.version import Version as _Version
from shore.util import git as _git
from nr.utils.git import Git
from typing import Optional, Union
import re

@@ -134,20 +134,21 @@ def get_commit_distance_version(repo_dir: str, version: Version, latest_tag: str
Todo: We could try to find the previous tag for this subject and use that.
"""

dirty = _git.has_diff(repo_dir)
git = Git(repo_dir)
dirty = git.has_diff()

if _git.rev_parse(latest_tag):
distance = len(_git.rev_list(latest_tag + '..HEAD', repo_dir))
if git.rev_parse(latest_tag):
distance = len(git.rev_list(latest_tag + '..HEAD'))
else:
logger.warning('tag "%s" does not exist', latest_tag)
version = Version('0.0.0')
distance = len(_git.rev_list('HEAD', repo_dir))
distance = len(git.rev_list('HEAD'))

if distance == 0:
if dirty:
return parse_version(str(version) + '+dirty')
return None

rev = _git.rev_parse('HEAD', repo_dir)
rev = git.rev_parse('HEAD')
local = '+{}.g{}{}'.format(distance, rev[:7], '.dirty' if dirty else '')
return parse_version(str(version) + local)

Loading…
Cancel
Save