Skip to content

Commit

Permalink
Dynamic version info
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesridgway committed Mar 5, 2022
1 parent e609ede commit fa3737e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ dist/
*.pyc
.idea/
*.egg-info
venv/
venv/
attachment_downloader/version.py
31 changes: 31 additions & 0 deletions attachment_downloader/version_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os

VERSION_FILENAME = os.path.abspath(os.path.join(os.path.dirname(__file__), 'version.py'))
import subprocess


class Version:
@staticmethod
def generate():
process = subprocess.Popen(["git", "describe", "--always", "--tags"], stdout=subprocess.PIPE, stderr=None)
last_tag = process.communicate()[0].decode('ascii').strip()
version = last_tag.split('-g')[0].replace('-', '.') if '-g' in last_tag else last_tag
with open(VERSION_FILENAME, 'w') as f:
f.write(f'ATTACHMENT_DOWNLOADER_VERSION = "{version}"\n')
return version

@staticmethod
def get(retry=True):
try:
from attachment_downloader.version import ATTACHMENT_DOWNLOADER_VERSION
return ATTACHMENT_DOWNLOADER_VERSION
except ModuleNotFoundError as e:
if retry:
Version.generate()
return Version.get(False)
return 'unknown'
except ImportError as e:
if retry:
Version.generate()
return Version.get(False)
return 'unknown'
2 changes: 2 additions & 0 deletions bin/attachment-downloader
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ from jinja2 import Template, UndefinedError

from attachment_downloader.cli import valid_date, get_password
from attachment_downloader.logging import Logger
from attachment_downloader.version_info import Version

if __name__ == '__main__':
Logger.setup()
logging.info(f'Attachment Downloader - Version: {Version.get()}')

if sys.version_info[0] < 3:
logging.error("This application requires Python 3+, you are running version: %s", sys.version)
Expand Down
17 changes: 13 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
from setuptools import setup
import os

from setuptools import setup, find_packages

from attachment_downloader.version_info import Version

Version.generate()

with open(os.path.abspath(os.path.join(os.path.dirname(__file__), 'requirements.txt'))) as f:
install_reqs = f.read().splitlines()

setup(
name='attachment-downloader',
version='1.1.7',
version=Version.get(),
description='Simple tool for downloading email attachments for all emails in a given folder using an IMAP client.',
long_description=open('README.rst').read(),
author='James Ridgway',
url='https://github.com/jamesridgway/attachment-downloader',
license='MIT',
packages=['attachment_downloader'],
packages=find_packages(),
scripts=['bin/attachment-downloader'],
install_requires=["jinja2", "imbox", "python-dateutil"]
install_requires=install_reqs
)

0 comments on commit fa3737e

Please sign in to comment.