From 318f7bcd39eb024cf1cb6b7ca545eaea05af6d3b Mon Sep 17 00:00:00 2001 From: jan Date: Fri, 3 Jul 2020 13:37:10 -0700 Subject: [PATCH 1/9] avoid importing the package before it's installed --- lethe.py | 2 +- setup.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lethe.py b/lethe.py index 6154516..d0a4ab9 100755 --- a/lethe.py +++ b/lethe.py @@ -13,7 +13,7 @@ import sys __author__ = 'Jan Petykeiwicz' -version = 0.7 +__version__ = '0.8' def _run(command: str or List[str], **kwargs): diff --git a/setup.py b/setup.py index 4f65088..fffcae1 100644 --- a/setup.py +++ b/setup.py @@ -1,13 +1,12 @@ #!/usr/bin/env python3 from setuptools import setup -import lethe with open('README.md', 'r') as f: long_description = f.read() setup(name='lethe', - version=lethe.version, + version='0.8', description='Git-based snapshotting', long_description=long_description, long_description_content_type='text/markdown', From 171e6985459e6f5f0f54ec99eb582700bbe9a70d Mon Sep 17 00:00:00 2001 From: jan Date: Fri, 3 Jul 2020 13:38:18 -0700 Subject: [PATCH 2/9] add egg-info and pycache to gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aadc86c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.egg-info/ +__pycache__/ From 342930aca52f19344213b4413e77b0a0ac3e8528 Mon Sep 17 00:00:00 2001 From: jan Date: Fri, 3 Jul 2020 13:40:42 -0700 Subject: [PATCH 3/9] add more python-related stuff to gitignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index aadc86c..73a7eec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ +build/ +dist/ + *.egg-info/ __pycache__/ +*.pyc From 3db4f500bc416664bab486e9f5cdb9a344c1df36 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Sun, 1 Nov 2020 23:56:30 -0800 Subject: [PATCH 4/9] add .gitignore --- .gitignore | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 73a7eec..7293a7d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,10 @@ -build/ -dist/ - -*.egg-info/ __pycache__/ *.pyc + +.*.swp +.*.swo + +build/ +dist/ +*.egg-info/ +.mypy_cache From 53f47fbafda6b91a1018b6bf2642226780fd1c11 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Sun, 1 Nov 2020 23:57:07 -0800 Subject: [PATCH 5/9] improve type annotations --- lethe.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lethe.py b/lethe.py index d0a4ab9..23f15e5 100755 --- a/lethe.py +++ b/lethe.py @@ -3,12 +3,12 @@ Git snapshotting tool """ +from typing import List, Union import subprocess import tempfile import datetime import argparse from itertools import chain -from typing import List import sys @@ -16,7 +16,7 @@ __author__ = 'Jan Petykeiwicz' __version__ = '0.8' -def _run(command: str or List[str], **kwargs): +def _run(command: Union[str, List[str]], **kwargs) -> str: """ Wrapper for subprocess.run(): - Accepts args as either a list of strings or space-delimited string From 84bc016f2720103273bed56aa186cceeed09691e Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Mon, 2 Nov 2020 00:13:56 -0800 Subject: [PATCH 6/9] move to multi-file module (required for type checking) --- lethe/VERSION.py | 4 ++++ lethe/__init__.py | 12 ++++++++++++ lethe/__main__.py | 4 ++++ lethe.py => lethe/lethe.py | 4 ---- lethe/py.typed | 0 setup.py | 17 ++++++++++++----- 6 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 lethe/VERSION.py create mode 100644 lethe/__init__.py create mode 100644 lethe/__main__.py rename lethe.py => lethe/lethe.py (99%) create mode 100644 lethe/py.typed diff --git a/lethe/VERSION.py b/lethe/VERSION.py new file mode 100644 index 0000000..9de6fb9 --- /dev/null +++ b/lethe/VERSION.py @@ -0,0 +1,4 @@ +""" VERSION defintion. THIS FILE IS MANUALLY PARSED BY setup.py and REQUIRES A SPECIFIC FORMAT """ +__version__ = ''' +0.7 +''' diff --git a/lethe/__init__.py b/lethe/__init__.py new file mode 100644 index 0000000..337e2b9 --- /dev/null +++ b/lethe/__init__.py @@ -0,0 +1,12 @@ +""" +Git snapshotting tool +""" +from .lethe import ( + main, snap, snap_ref, snap_tree, find_merge_base, deref_symref, + update_ref, commit_tree, get_tree, get_commit, get_obj, get_root, get_latest_commit, + shorten_hash, _run, + ) + +from .VERSION import __version__ + +__author__ = 'Jan Petykeiwicz' diff --git a/lethe/__main__.py b/lethe/__main__.py new file mode 100644 index 0000000..ff534a2 --- /dev/null +++ b/lethe/__main__.py @@ -0,0 +1,4 @@ +from .lethe import main + +if __name__ == '__main__': + main() diff --git a/lethe.py b/lethe/lethe.py similarity index 99% rename from lethe.py rename to lethe/lethe.py index 23f15e5..a1ac0c2 100755 --- a/lethe.py +++ b/lethe/lethe.py @@ -12,10 +12,6 @@ from itertools import chain import sys -__author__ = 'Jan Petykeiwicz' -__version__ = '0.8' - - def _run(command: Union[str, List[str]], **kwargs) -> str: """ Wrapper for subprocess.run(): diff --git a/lethe/py.typed b/lethe/py.typed new file mode 100644 index 0000000..e69de29 diff --git a/setup.py b/setup.py index fffcae1..8a03a7b 100644 --- a/setup.py +++ b/setup.py @@ -1,18 +1,26 @@ #!/usr/bin/env python3 -from setuptools import setup +from setuptools import setup, find_packages -with open('README.md', 'r') as f: + +with open('README.md', 'rt') as f: long_description = f.read() +with open('lethe/VERSION.py', 'rt') as f: + version = f.readlines()[2].strip() + setup(name='lethe', - version='0.8', + version=version, description='Git-based snapshotting', long_description=long_description, long_description_content_type='text/markdown', author='Jan Petykiewicz', author_email='anewusername@gmail.com', - py_modules=['lethe'], + url='https://mpxd.net/code/jan/lethe', + packages=find_packages(), + package_data={ + 'lethe': ['py.typed'], + }, entry_points={ 'console_scripts': [ 'lethe=lethe:main', @@ -21,7 +29,6 @@ setup(name='lethe', install_requires=[ 'typing', ], - url='https://mpxd.net/code/jan/lethe', keywords=[ 'git', 'snapshot', From 68f394c03723bd2337d114f40a281e35df49b50d Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Mon, 2 Nov 2020 00:21:02 -0800 Subject: [PATCH 7/9] add flake8 config --- .flake8 | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .flake8 diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..0042015 --- /dev/null +++ b/.flake8 @@ -0,0 +1,29 @@ +[flake8] +ignore = + # E501 line too long + E501, + # W391 newlines at EOF + W391, + # E241 multiple spaces after comma + E241, + # E302 expected 2 newlines + E302, + # W503 line break before binary operator (to be deprecated) + W503, + # E265 block comment should start with '# ' + E265, + # E123 closing bracket does not match indentation of opening bracket's line + E123, + # E124 closing bracket does not match visual indentation + E124, + # E221 multiple spaces before operator + E221, + # E201 whitespace after '[' + E201, + # E741 ambiguous variable name 'I' + E741, + + +per-file-ignores = + # F401 import without use + */__init__.py: F401, From a83c30348828d23687e4dfa89bbd25446fa558a6 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Mon, 2 Nov 2020 00:21:35 -0800 Subject: [PATCH 8/9] typing and comment cleanup --- lethe/__init__.py | 4 ++-- lethe/lethe.py | 61 +++++++++++++++++++++++------------------------ 2 files changed, 32 insertions(+), 33 deletions(-) diff --git a/lethe/__init__.py b/lethe/__init__.py index 337e2b9..7a4b8ec 100644 --- a/lethe/__init__.py +++ b/lethe/__init__.py @@ -3,8 +3,8 @@ Git snapshotting tool """ from .lethe import ( main, snap, snap_ref, snap_tree, find_merge_base, deref_symref, - update_ref, commit_tree, get_tree, get_commit, get_obj, get_root, get_latest_commit, - shorten_hash, _run, + update_ref, commit_tree, get_tree, get_commit, get_obj, + shorten_hash, get_root, get_latest_commit, ) from .VERSION import __version__ diff --git a/lethe/lethe.py b/lethe/lethe.py index a1ac0c2..589cd5f 100755 --- a/lethe/lethe.py +++ b/lethe/lethe.py @@ -3,18 +3,18 @@ Git snapshotting tool """ -from typing import List, Union +from typing import List, Union, Optional import subprocess import tempfile import datetime import argparse from itertools import chain -import sys def _run(command: Union[str, List[str]], **kwargs) -> str: """ - Wrapper for subprocess.run(): + Wrapper for `subprocess.run()`: + - Accepts args as either a list of strings or space-delimited string - Captures and returns stdout """ @@ -27,7 +27,7 @@ def _run(command: Union[str, List[str]], **kwargs) -> str: return result.stdout.decode().strip() -def get_latest_commit(short: bool=True, cwd: str=None) -> str: +def get_latest_commit(short: bool = True, cwd: Optional[str] = None) -> str: """ Get the most recent commit's hash. This includes non-lethe commits. @@ -36,14 +36,14 @@ def get_latest_commit(short: bool=True, cwd: str=None) -> str: return _run('git log --all -1 --format=%{}'.format(fmt), cwd=cwd) -def shorten_hash(sha: str, cwd: str=None) -> str: +def shorten_hash(sha: str, cwd: Optional[str] = None) -> str: """ Get the short version of a hash """ return _run('git rev-parse --short {}'.format(sha), cwd=cwd) -def get_root(cwd: str=None) -> str: +def get_root(cwd: Optional[str] = None) -> str: """ Get the root directory of a git repository """ @@ -53,7 +53,7 @@ def get_root(cwd: str=None) -> str: return root -def get_obj(ref: str, cwd: str=None) -> str: +def get_obj(ref: str, cwd: Optional[str] = None) -> str: """ Transform a ref into its corresponding hash using git-rev-parse """ @@ -61,14 +61,14 @@ def get_obj(ref: str, cwd: str=None) -> str: return sha -def get_commit(ref: str, cwd: str=None) -> str: +def get_commit(ref: str, cwd: Optional[str] = None) -> str: """ Transform a ref to a commit into its corresponding hash using git-rev-parse """ return get_obj(ref, cwd=cwd) -def get_tree(ref: str, cwd: str=None) -> str: +def get_tree(ref: str, cwd: Optional[str] = None) -> str: """ Take a ref to a commit, and return the hash of the tree it points to """ @@ -77,8 +77,8 @@ def get_tree(ref: str, cwd: str=None) -> str: def commit_tree(tree: str, parents: List[str], - message: str = None, - cwd: str = None, + message: Optional[str] = None, + cwd: Optional[str] = None, ) -> str: """ Create a commit pointing to the given tree, with the specified parent commits and message. @@ -94,13 +94,13 @@ def commit_tree(tree: str, def update_ref(target_ref: str, target_commit: str, - old_commit: str = None, + old_commit: Optional[str] = None, message: str = 'new snapshot', - cwd: str = None, + cwd: Optional[str] = None, ) -> str: """ - Update target_ref to point to target_commit, optionally verifying that - it points old_commit before the update. + Update `target_ref` to point to `target_commit`, optionally verifying that + it points `old_commit` before the update. Returns the resulting ref. """ cmd = ['git', 'update-ref', '-m', message, target_ref, target_commit] @@ -110,14 +110,14 @@ def update_ref(target_ref: str, return result_ref -def deref_symref(ref: str, cwd: str=None) -> str: +def deref_symref(ref: str, cwd: Optional[str] = None) -> str: """ Dereference a symbolic ref """ return _run(['git', 'symbolic-ref', '--quiet', ref], cwd=cwd) -def find_merge_base(commits: List[str], cwd: str=None) -> str: +def find_merge_base(commits: List[str], cwd: Optional[str] = None) -> str: """ Find the "best common ancestor" commit. """ @@ -131,7 +131,7 @@ def find_merge_base(commits: List[str], cwd: str=None) -> str: return base -def snap_tree(cwd: str=None) -> str: +def snap_tree(cwd: Optional[str] = None) -> str: """ Create a new tree, consisting of all non-ignored files in the repository. Return the hash of the tree. @@ -147,11 +147,11 @@ def snap_tree(cwd: str=None) -> str: def snap_ref(parent_refs: List[str], target_refs: List[str], - message: str = None, - cwd: str = None, + message: Optional[str] = None, + cwd: Optional[str] = None, ) -> str: """ - is used as the commit message. + `message` is used as the commit message. """ new_tree = snap_tree(cwd=cwd) parent_commits = [c for c in [get_commit(p, cwd=cwd) for p in parent_refs] if c] @@ -176,29 +176,28 @@ def snap_ref(parent_refs: List[str], return commit - -def snap(parent_refs: List[str] = None, - target_refs: List[str] = None, - message: str = None, - cwd: str = None, +def snap(parent_refs: Optional[List[str]] = None, + target_refs: Optional[List[str]] = None, + message: Optional[str] = None, + cwd: Optional[str] = None, ) -> str: """ Create a new commit of all non-ignored files in the repository. - default to ['HEAD']. - If there are any symbolic refs in , the refs + `parent_refs` default to `['HEAD']`. + If there are any symbolic refs in `parent_refs`, the refs they point to are added to . - All commits pointed to by existing and , + All commits pointed to by existing `parent_refs` and `target_refs`, become parents of the newly created commit. - are created/updated to point the commit. + `target_refs` are created/updated to point the commit. Default is 'refs/lethe/head_name' for each parent ref of the form 'refs/heads/head_name', and 'refs/lethe/path/to/ref' for each parent ref of the form 'refs/path/to/ref'. - is used as the commit message. + `message` is used as the commit message. """ if parent_refs is None: parent_refs = ['HEAD'] From 8fb7eca50122d7167a9c6a32be03c2ce6aca555f Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Mon, 2 Nov 2020 00:21:56 -0800 Subject: [PATCH 9/9] bump version to v0.9 --- lethe/VERSION.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lethe/VERSION.py b/lethe/VERSION.py index 9de6fb9..032341c 100644 --- a/lethe/VERSION.py +++ b/lethe/VERSION.py @@ -1,4 +1,4 @@ """ VERSION defintion. THIS FILE IS MANUALLY PARSED BY setup.py and REQUIRES A SPECIFIC FORMAT """ __version__ = ''' -0.7 +0.9 '''