Skip to content

Commit

Permalink
[Issue #1] Use setup.py instead of pyproject.toml. Store version in s…
Browse files Browse the repository at this point in the history
…rc/adbPullAs/VERSION
  • Loading branch information
ViliusSutkus89 committed Jul 26, 2022
1 parent aa3a0bd commit d698b3c
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 59 deletions.
20 changes: 10 additions & 10 deletions ci-scripts/incrementVersion
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,30 @@ if __name__ == '__main__':
try:
opts, args = getopt.getopt(sys.argv[1:], '', ['major', 'minor', 'patch'])
for o, a in opts:
if o == '--major': major = True
if o == '--minor': minor = True
if o == '--patch': patch = True
if o == '--major':
major = True
if o == '--minor':
minor = True
if o == '--patch':
patch = True

except getopt.GetoptError as err:
print(err, file=sys.stderr)
exit(os.EX_USAGE)

versioner = Versioner()
old_version = versioner.get_version_str()
updated_file_list = []
if major:
updated_file_list = versioner.increment_major()
versioner.increment_major()
elif minor:
updated_file_list = versioner.increment_minor()
versioner.increment_minor()
elif patch:
updated_file_list = versioner.increment_patch()
versioner.increment_patch()
else:
print('Specify either --major, --minor or --patch', file=sys.stderr)
exit(os.EX_USAGE)

new_version = versioner.get_version_str()
print(f'::set-output name=oldVersion::{old_version}')
print(f'::set-output name=newVersion::{new_version}')

updated_file_list = ' '.join(updated_file_list)
print(f'::set-output name=files::{updated_file_list}')
print(f'::set-output name=files::{versioner.version_file}')
37 changes: 9 additions & 28 deletions ci-scripts/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,26 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import os.path
import pathlib


class Versioner:
def __init__(self):
abs_dir_name = os.path.abspath(os.path.dirname(__file__))
self.__version_files = [os.path.abspath(os.path.join(abs_dir_name, f)) for f in ('../pyproject.toml', '../src/adbPullAs/__init__.py')]
self.__version_str = self.__get_version()
if not self.__version_str:
raise RuntimeError("Unable to find version string.")
here = pathlib.Path(__file__).parent.resolve()
self.version_file = os.path.abspath(here.parent / 'src' / 'adbPullAs' / 'VERSION')
with open(self.version_file, 'r') as f:
self.__version_str = f.read().strip()
self.__version = list(map(int, self.__version_str.split('.')))

def __get_version(self):
for f in self.__version_files:
with open(f, 'r') as fp:
for line in fp:
if line.startswith('version = '):
delimiter = '"' if '"' in line else "'"
return line.split(delimiter)[1]
return False
def get_version(self):
return self.__version

def get_version_str(self):
return self.__version_str

def __save_version_file(self, file):
with open(file, 'r+') as fh:
position = 0
for line in fh:
if line.startswith('version = '):
fh.seek(position)
fh.write(f"version = '{self.__version_str}' #")
return True
position += len(line)

def __save_version(self):
updated_list = []
for file in self.__version_files:
if self.__save_version_file(file):
updated_list.append(file)
return updated_list
with open(self.version_file, 'w') as f:
f.write(self.__version_str)

def increment_major(self):
self.__version[0] += 1
Expand Down
18 changes: 0 additions & 18 deletions pyproject.toml

This file was deleted.

39 changes: 39 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from setuptools import setup, find_packages
import pathlib


here = pathlib.Path(__file__).parent.resolve()
version = (here / 'src' / 'adbPullAs' / 'VERSION').read_text(encoding='utf-8')
long_description = (here / 'README.md').read_text(encoding='utf-8')

setup(
name='adbPullAs',
version=version,
description='adb pull wrapper to pull package private files from Android device',
long_description=long_description,
long_description_content_type='text/markdown',
url='https://github.com/ViliusSutkus89/adbPullAs/',
author="Vilius Sutkus '89",
author_email='ViliusSutkus89@gmail.com',
license='GPLv3',
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Console',
'Intended Audience :: Developers',
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
'Natural Language :: English',
'Operating System :: Android',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.9',
'Topic :: Utilities'
],
keywords='adb pull run-as',
project_urls={
'Tracker': 'https://github.com/ViliusSutkus89/adbPullAs/issues'
},
package_dir={'': 'src'},
packages=find_packages(where='src'),
python_requires='>=3.9',
package_data={'adbPullAs': ['VERSION']},
entry_points={'console_scripts': ['adbPullAs=adbPullAs:main']}
)
1 change: 1 addition & 0 deletions src/adbPullAs/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.1
8 changes: 5 additions & 3 deletions src/adbPullAs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@

import getopt
import os
import pathlib
import subprocess
import sys
from pathlib import PurePosixPath, PurePath

version = '1.0.1' ####################### buffer for in-place file modification, in case version STRING needs to grow


class FsTest:
def __init__(self, package_name):
Expand Down Expand Up @@ -168,8 +167,11 @@ def print_usage(output_to=sys.stdout):


def print_version():
here = pathlib.Path(__file__).parent.resolve()
version = (here / 'VERSION').read_text(encoding='utf-8')

print(os.path.basename(sys.argv[0]), '-', 'adb pull wrapper to pull package private files from Android device')
print('version: ', version)
print('version:', version)
print()
print('THIS WORKS ONLY ON DEBUG APPLICATIONS')
print()
Expand Down

0 comments on commit d698b3c

Please sign in to comment.