11import os
22import sys
3+ import ast
34import json
45import pydoc
56import asyncio
7+ import pathlib
68import getpass
79import importlib
810import contextlib
@@ -434,6 +436,127 @@ async def run(self):
434436 raise RuntimeError
435437
436438
439+ class BumpMain (CMD ):
440+ """
441+ Bump the version number of the main package within the dependency list of
442+ each plugin.
443+ """
444+
445+ async def run (self ):
446+ main_package = is_develop ("dffml" )
447+ if not main_package :
448+ raise NotImplementedError (
449+ "Need to reinstall the main package in development mode."
450+ )
451+ # TODO Implement this in Python
452+ proc = await asyncio .create_subprocess_exec (
453+ "bash" , str (pathlib .Path (main_package , "scripts" , "bump_deps.sh" ))
454+ )
455+ await proc .wait ()
456+ if proc .returncode != 0 :
457+ raise RuntimeError
458+
459+
460+ class BumpPackages (CMD ):
461+ """
462+ Bump all the versions of all the packages and increment the version number
463+ given.
464+ """
465+
466+ arg_skip = Arg (
467+ "-skip" ,
468+ help = "Do not increment versions in these packages" ,
469+ nargs = "+" ,
470+ default = [],
471+ required = False ,
472+ )
473+ arg_only = Arg (
474+ "-only" ,
475+ help = "Only increment versions in these packages" ,
476+ nargs = "+" ,
477+ default = [],
478+ required = False ,
479+ )
480+ arg_version = Arg ("version" , help = "Version to increment by" )
481+
482+ @staticmethod
483+ def bump_version (original , increment ):
484+ # Split on .
485+ # map: int: Convert to an int
486+ # zip: Create three instances of (original[i], increment[i])
487+ # map: sum: Add each pair together
488+ # map: str: Convert back to strings
489+ return "." .join (
490+ map (
491+ str ,
492+ map (
493+ sum ,
494+ zip (
495+ map (int , original .split ("." )),
496+ map (int , increment .split ("." )),
497+ ),
498+ ),
499+ )
500+ )
501+
502+ async def run (self ):
503+ main_package = is_develop ("dffml" )
504+ if not main_package :
505+ raise NotImplementedError (
506+ "Need to reinstall the main package in development mode."
507+ )
508+ main_package = pathlib .Path (main_package )
509+ skel = main_package / "dffml" / "skel"
510+ # Update all the version files
511+ for version_file in main_package .rglob ("**/version.py" ):
512+ # Ignore skel
513+ if skel in version_file .parents :
514+ self .logger .debug (
515+ "Skipping skel verison file %s" , version_file
516+ )
517+ continue
518+ # If we're only supposed to increment versions of some packages,
519+ # check we're in the right package, skip if not.
520+ setup_filepath = version_file .parent .parent / "setup.py"
521+ with chdir (setup_filepath .parent ):
522+ name = SetupPyKWArg .get_kwargs (setup_filepath )["name" ]
523+ if self .only and name not in self .only :
524+ self .logger .debug (
525+ "Verison file not in only %s" , version_file
526+ )
527+ continue
528+ elif name in self .skip :
529+ self .logger .debug ("Skipping verison file %s" , version_file )
530+ continue
531+ # Read the file
532+ filetext = version_file .read_text ()
533+ # Find the version as a string
534+ modified_lines = []
535+ for line in filetext .split ("\n " ):
536+ # Look for the line containing the version string
537+ if line .startswith ("VERSION" ):
538+ # Parse the version string
539+ version = ast .literal_eval (line .split ("=" )[- 1 ].strip ())
540+ # Increment the version string
541+ version = self .bump_version (version , self .version )
542+ # Modify the line to use the new version string
543+ line = f'VERSION = "{ version } "'
544+ # Append line to list of lines to write back
545+ modified_lines .append (line )
546+ # Write back the file using the modified lines
547+ filetext = version_file .write_text ("\n " .join (modified_lines ))
548+ self .logger .debug ("Updated verison file %s" , version_file )
549+
550+
551+ class Bump (CMD ):
552+ """
553+ Bump the the main package in the versions plugins, or any or all libraries.
554+ """
555+
556+ main = BumpMain
557+ packages = BumpPackages
558+
559+
437560class Develop (CMD ):
438561 """
439562 Development utilities for hacking on DFFML itself
@@ -447,3 +570,4 @@ class Develop(CMD):
447570 install = Install
448571 release = Release
449572 setuppy = SetupPy
573+ bump = Bump
0 commit comments