Browse Source

add VirtualFiles.abspaths(), VersionBumpData.update() must now return a list of changed files which fixes adding "setup.py" and "MANIFEST.in" before commit in "shut pkg bump"

shut-new-model
Niklas Rosenstein 9 months ago
parent
commit
1a40579117
No known key found for this signature in database GPG Key ID: 6D269B33D25F6C6
7 changed files with 38 additions and 20 deletions
  1. + 6
    - 3
      src/shut/commands/commons/bump.py
  2. + 1
    - 1
      src/shut/commands/commons/new.py
  3. + 2
    - 1
      src/shut/commands/mono/bump.py
  4. + 3
    - 1
      src/shut/commands/mono/update.py
  5. + 3
    - 2
      src/shut/commands/pkg/bump.py
  6. + 5
    - 1
      src/shut/commands/pkg/update.py
  7. + 18
    - 11
      src/shut/utils/io/virtual.py

+ 6
- 3
src/shut/commands/commons/bump.py

@ -127,8 +127,11 @@ class VersionBumpData(Generic[T], metaclass=abc.ABCMeta):
return changed_files
@abc.abstractmethod
def update(self) -> None:
pass
def update(self) -> Iterable[str]:
"""
Run the "update" function for the current monorepo or package. A list of the modified files
must be returned.
"""
def make_bump_command(
@ -224,7 +227,7 @@ def do_bump(args: Args, data: VersionBumpData[AbstractProjectModel]) -> None:
if not args.skip_update:
print()
print('updating files')
data.update()
changed_files += data.update()
if args.tag:
print()

+ 1
- 1
src/shut/commands/commons/new.py

@ -82,7 +82,7 @@ def write_files(
force: bool = False,
dry: bool = False,
indent: int = 0,
) -> None:
):
def _rel(fn: str) -> str:
path = os.path.relpath(fn)
if nr.fs.issub(path):

+ 2
- 1
src/shut/commands/mono/bump.py

@ -46,7 +46,8 @@ class MonorepoBumpdata(VersionBumpData[MonorepoModel]):
return check_monorepo(self.obj, self.args.warnings_as_errors)
def update(self) -> None:
update_monorepo(self.obj, dry=self.args.dry, indent=1)
vfiles = update_monorepo(self.obj, dry=self.args.dry, indent=1)
return vfiles.abspaths(self.obj.get_directory())
def bump_to_version(self, target_version: Version) -> Iterable[str]:
changed_files = list(super().bump_to_version(target_version))

+ 3
- 1
src/shut/commands/mono/update.py

@ -26,12 +26,14 @@ from shut.commands.commons.new import write_files
from shut.commands.pkg.update import update_package
from shut.model import MonorepoModel
from shut.renderers import get_files
from shut.utils.io.virtual import VirtualFiles
from . import mono
def update_monorepo(monorepo: MonorepoModel, dry: bool = False, indent: int = 0) -> None:
def update_monorepo(monorepo: MonorepoModel, dry: bool = False, indent: int = 0) -> VirtualFiles:
files = get_files(monorepo)
write_files(files, monorepo.get_directory(), force=True, dry=dry, indent=indent)
return files
@mono.command()

+ 3
- 2
src/shut/commands/pkg/bump.py

@ -52,8 +52,9 @@ class PackageBumpData(VersionBumpData[PackageModel]):
def run_checks(self) -> int:
return check_package(self.obj, self.args.warnings_as_errors)
def update(self) -> None:
update_package(self.obj, dry=self.args.dry, indent=1)
def update(self) -> Iterable[str]:
vfiles = update_package(self.obj, dry=self.args.dry, indent=1)
return vfiles.abspaths(self.obj.get_directory())
def get_snapshot_version(self) -> Version:
project = self.project

+ 5
- 1
src/shut/commands/pkg/update.py

@ -19,18 +19,22 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
from typing import Iterable
import click
from shut.commands import project
from shut.commands.commons.new import write_files
from shut.model import PackageModel
from shut.renderers import get_files
from shut.utils.io.virtual import VirtualFiles
from . import pkg
def update_package(package: PackageModel, dry: bool = False, indent: int = 0) -> None:
def update_package(package: PackageModel, dry: bool = False, indent: int = 0) -> VirtualFiles:
files = get_files(package)
write_files(files, package.get_directory(), force=True, dry=dry, indent=indent)
return files
@pkg.command()

+ 18
- 11
src/shut/utils/io/virtual.py

@ -19,7 +19,7 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
from typing import Any, Callable, Union
from typing import Any, Callable, Iterable, Union
import os
@ -43,8 +43,8 @@ class VirtualFiles:
filename: str,
render_func: Callable,
*args: Any,
text: bool=True,
inplace: bool=False,
text: bool = True,
inplace: bool = False,
) -> None:
self._files.append({
'filename': filename,
@ -56,20 +56,19 @@ class VirtualFiles:
def write_all(
self,
parent_directory: str=None,
on_write: Callable=None,
on_skip: Callable=None,
overwrite: bool=False,
create_directories: bool=True,
dry: bool=False,
parent_directory: str = None,
on_write: Callable = None,
on_skip: Callable = None,
overwrite: bool = False,
create_directories: bool = True,
dry: bool = False,
) -> None:
"""
Writes all files to disk. Relative files will be written relative to the
*parent_directory*.
"""
for file_ in self._files:
filename = os.path.normpath(os.path.join(parent_directory or '.', file_['filename']))
for file_, filename in zip(self._files, self.abspaths(parent_directory)):
exists = os.path.isfile(filename)
if exists and not overwrite:
if on_skip:
@ -91,3 +90,11 @@ class VirtualFiles:
else:
with open(filename, 'w' + mode) as dst:
file_['render_func'](dst, *file_['args'])
def abspaths(self, parent_directory: str = None) -> Iterable[str]:
"""
Returns all paths in this virtual fileset joined with *parent_directory*.
"""
for file_ in self._files:
yield os.path.normpath(os.path.join(parent_directory or '.', file_['filename']))

Loading…
Cancel
Save