Skip to content

Commit

Permalink
Merge pull request #10 from argoyal/9-publish-as-pip-package
Browse files Browse the repository at this point in the history
restructuring for pip package
  • Loading branch information
argoyal authored Feb 27, 2024
2 parents 0ad8758 + b7b7cf3 commit 69da15e
Show file tree
Hide file tree
Showing 23 changed files with 200 additions and 81 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/publish-to-pypi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Publish to PyPI

on:
push:
tags:
- v[0-9]+.[0-9]+.[0-9]+

jobs:
publish:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8'

- name: Extract version from tag
id: extract_version
run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/v}

- name: Write version to file
run: echo "${{ steps.extract_version.outputs.VERSION }}" > VERSION

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install wheel
- name: Build distribution
run: |
python setup.py sdist bdist_wheel
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ __pycache__
.venv
*.zip
.DS_Store
build/
dist/
wbck.egg-info
.vscode
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) [2024] [Arpit Goyal]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
File renamed without changes.
File renamed without changes.
42 changes: 42 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import os
from setuptools import setup, find_packages

with open("README.md", "r", encoding = "utf-8") as fh:
long_description = fh.read()


def get_version():
if not os.path.exists("VERSION"):
raise FileNotFoundError("Version file does not exist")

with open("VERSION", "r") as f:
version = f.read()

return version


setup(
name='wbck',
version=get_version(),
author="Arpit Goyal",
author_email="[email protected]",
description="a command line utility to perform workspace backup",
long_description_content_type="text/markdown",
long_description=long_description,
url="https://github.com/argoyal/wbck.git",
packages=find_packages(),
install_requires=[
'boto3'
],
entry_points={
'console_scripts': [
'wbck = wbck:cli',
]
},
python_requires=">=3.6",
classifiers=[
"Programming Language :: Python :: 3",
"Operating System :: OS Independent",
"License :: OSI Approved :: MIT License"
]
)
File renamed without changes.
150 changes: 79 additions & 71 deletions run.py → wbck/__init__.py
Original file line number Diff line number Diff line change
@@ -1,71 +1,79 @@
import os
import argparse
from app.runners import backup_data, restore_data, setup_from_template
from app.load_config import is_config_loadable


def restore_workspace(args):
is_config_loadable(args.config_path)
restore_data(args.config_path)


def backup_workspace(args):
is_config_loadable(args.config_path)
backup_data(args.config_path)


def create_new_workspace(args):
setup_from_template(args.name, args.workspace_path, args.config_folder)


if __name__ == "__main__":
parser = argparse.ArgumentParser(
description='Application to backup and restore my workspace data using config files'
)
subparsers = parser.add_subparsers(title="Commands")

create_parser = subparsers.add_parser(
"create",
help="creates a new workspace"
)
create_parser.add_argument(
"--name",
required=True,
help="name of the new workspace"
)
create_parser.add_argument(
"--workspace-path",
default=os.path.expanduser("~"),
help="path where the workspace needs to be created"
)
create_parser.add_argument(
"--config-folder",
required=True,
help="path where the config for this workspace is"
)
create_parser.set_defaults(func=create_new_workspace)

backup_parser = subparsers.add_parser(
"backup",
help="commands pertaining to backup of your workspaces"
)
backup_parser.add_argument(
"--config-path",
required=True,
help="path where the config for this workspace is"
)
backup_parser.set_defaults(func=backup_workspace)

restore_parser = subparsers.add_parser(
"restore",
help="commands pertaining to restore of your workspaces"
)
restore_parser.add_argument(
"--config-path",
required=True,
help="path where the config for this workspace is"
)
restore_parser.set_defaults(func=restore_workspace)

args = parser.parse_args()
args.func(args)
import os
import argparse
from .runners import backup_data, restore_data, setup_from_template
from .load_config import is_config_loadable


def restore_workspace(args):
is_config_loadable(args.config_path)
restore_data(args.config_path)


def backup_workspace(args):
is_config_loadable(args.config_path)
backup_data(args.config_path)


def create_new_workspace(args):
setup_from_template(args.name, args.workspace_path, args.config_folder)


def cli():
"""
defines the entire cli parsing components of wbck
"""

parser = argparse.ArgumentParser(
description='Application to backup and restore my workspace data using config files'
)
subparsers = parser.add_subparsers(title="Commands")

create_parser = subparsers.add_parser(
"create",
help="creates a new workspace"
)
create_parser.add_argument(
"--name",
required=True,
help="name of the new workspace"
)
create_parser.add_argument(
"--workspace-path",
default=os.path.expanduser("~"),
help="path where the workspace needs to be created"
)
create_parser.add_argument(
"--config-folder",
required=True,
help="path where the config for this workspace is"
)
create_parser.set_defaults(func=create_new_workspace)

backup_parser = subparsers.add_parser(
"backup",
help="commands pertaining to backup of your workspaces"
)
backup_parser.add_argument(
"--config-path",
required=True,
help="path where the config for this workspace is"
)
backup_parser.set_defaults(func=backup_workspace)

restore_parser = subparsers.add_parser(
"restore",
help="commands pertaining to restore of your workspaces"
)
restore_parser.add_argument(
"--config-path",
required=True,
help="path where the config for this workspace is"
)
restore_parser.set_defaults(func=restore_workspace)

args = parser.parse_args()
args.func(args)


if __name__ == "__main__":
cli()
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 2 additions & 3 deletions app/runners.py → wbck/runners.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import os
import json
import shutil
from .sources.aws import AwsSource
from .sources.local import LocalSource
from .sources import AwsSource, LocalSource
from .repositories import clone_repositories


Expand Down Expand Up @@ -76,4 +75,4 @@ def restore_data(config_path):

for src in enabled_sources:
print("Backing up data using {}".format(src))
class_mapping[src].restore_data()
class_mapping[src].restore_data()
10 changes: 10 additions & 0 deletions wbck/sources/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from .base import BaseSource
from .aws import AwsSource
from .local import LocalSource


__all__ = [
"BaseSource",
"LocalSource",
"AwsSource"
]
5 changes: 1 addition & 4 deletions app/sources/aws.py → wbck/sources/aws.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import os
import boto3
import shutil
import zipfile

from .base import BaseSource

Expand Down Expand Up @@ -54,4 +51,4 @@ def restore_data(self):

self.extract_from_compressed_data()

self.perform_cleanup()
self.perform_cleanup()
File renamed without changes.
4 changes: 1 addition & 3 deletions app/sources/local.py → wbck/sources/local.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import os
import shutil
import zipfile
from ..utils import zipdir
from .base import BaseSource


Expand Down Expand Up @@ -43,4 +41,4 @@ def restore_data(self):

self.extract_from_compressed_data()

self.perform_cleanup()
self.perform_cleanup()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.

0 comments on commit 69da15e

Please sign in to comment.