Skip to content

Commit

Permalink
support explicitly setting the version when no git repository is avai…
Browse files Browse the repository at this point in the history
…lable

- use --set-verion #.#.# to set the version
- error is generated if --set-version is used when there
  is a git repository
  • Loading branch information
freddrake committed Feb 26, 2024
1 parent 646e73e commit ca02400
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Release history
---------------

#. Add Python 3.12 to default test plan. Removed Python prior to 3.10.
#. Added **--set-version** option to set the version of the generated Debian
package file when building a package where the git repository is not
available.
https://github.com/keepertech/appackager/issues/4


0.8.0 (2024-02-25)
Expand Down
14 changes: 14 additions & 0 deletions src/kt/appackager/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,20 @@ def non_editable_pipfile_lock(self):
os.rename(tmpname, lockname)

def next_version(self):
if os.path.exists('.git'):
if self.config.set_version:
print('cannot use --set-version when used in conjunction'
' with a git repository', file=sys.stderr)
sys.exit(1)
return self.next_version_from_git()
elif self.config.set_version:
return self.config.set_version
else:
print('use --set-version when running without access to a'
' git repository', file=sys.stderr)
sys.exit(1)

def next_version_from_git(self):
stdout = subprocess.check_output(
['git', 'log', '--pretty=format:%h %D'])
stdout = str(stdout, 'utf-8')
Expand Down
3 changes: 2 additions & 1 deletion src/kt/appackager/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@ def __init__(self, *args, **kwargs):
super(ArgumentParser, self).__init__(*args, **kwargs)
self.set_defaults(verbose=0)
self.add_argument('-c', '--configuration', default='appackager.toml')
self.add_argument('--set-version', action='store')
vg = self.add_mutually_exclusive_group()
vg.add_argument('-v', '--verbose', action='count')
vg.add_argument('--verbosity', action='store',
dest='verbose', type=int)

def parse_args(self):
self.add_argument('settings', nargs="*")
namespace = super(ArgumentParser, self).parse_args()
with open(namespace.configuration, 'rb') as cf:
namespace.config = Configuration(tomli.load(cf))
namespace.config.set_version = namespace.set_version
return namespace


Expand Down

0 comments on commit ca02400

Please sign in to comment.