Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a --python3 flag to enable use in python3 environs. #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion ethronsoft/gcspypi/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ def main():
help="Specifies GCS bucket name hosting the packages. If not provided, gcspypi will try to read it from ~/.gcspypirc")
parser.add_argument("--verbose", "-v", action="store_true", default=False,
help="Verbose mode: exceptions stacktraces will be printed")
parser.add_argument("--python3", action="store_true", default=False,
help="Python3 mode: run in python3 mode")
subparsers = parser.add_subparsers(title="commands", help="use command --help for help", dest="command")

#init colorama
Expand All @@ -37,7 +39,8 @@ def main():
[_, value] = reporc[0].split("=")
repository = value.strip()
config = {
"repository": repository
"repository": repository,
"python3": args.get("python3")
}
handlers[args["command"]](config, args)

Expand Down
21 changes: 17 additions & 4 deletions ethronsoft/gcspypi/package/package_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,34 @@

class PackageInstaller(object): # pragma: no cover

def __init__(self, is_python3):
self.__is_python3 = is_python3

def install(self, resource, flags=[]):
subprocess.check_call(["python", "-m", "pip","install", resource] + flags)
if self.__is_python3:
subprocess.check_call(["python3", "-m", "pip","install", resource] + flags)
else:
subprocess.check_call(["python", "-m", "pip","install", resource] + flags)

def uninstall(self, pkg):
subprocess.check_call(["python", "-m", "pip","uninstall", pkg.full_name.replace(":", "==")])
if self.__is_python3:
subprocess.check_call(["python3", "-m", "pip","uninstall", pkg.full_name.replace(":", "==")])
else:
subprocess.check_call(["python", "-m", "pip","uninstall", pkg.full_name.replace(":", "==")])

class PackageManager(object):

def __init__(self, repo, console, installer=PackageInstaller(), overwrite=False, mirroring=True, install_deps=True):
def __init__(self, repo, console, installer=None, is_python3=False, overwrite=False, mirroring=True, install_deps=True):
self.__repo = repo
self.__console = console
self.__installer = installer
self.__overwrite = overwrite
self.__mirroring = mirroring
if installer:
self.__installer = installer
else:
self.__installer = PackageInstaller(is_python3 = is_python3)
self.__install_deps = install_deps
self.__is_python3 = is_python3
self.__prog = re.compile("((?:\w|-)*)(==|<=?|>=?)?((?:\d*\.?){0,3})?,?(==|<=?|>=?)?((?:\d*\.?){0,3})?")
self.__repo_cache = []
self.refresh_cache()
Expand Down
7 changes: 4 additions & 3 deletions ethronsoft/gcspypi/parsers/backup.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
from ethronsoft.gcspypi.package.package_manager import PackageManager
from ethronsoft.gcspypi.package.package_manager import PackageManager,PackageInstaller
from ethronsoft.gcspypi.utilities.console import Console
from ethronsoft.gcspypi.parsers.commons import init_repository

def handle_pull(config, data):
with Console(verbose=config.get("verbose", False), exit_on_error=True) as c:
repo = init_repository(c, config["repository"])
pkg_mgr = PackageManager(repo, console=c)
is_python3 = config.get("python3", False)
pkg_mgr = PackageManager(repo, console=c, installer=None, is_python3=config.get("python3", False))
pkg_mgr.clone(data["destination"])

def handle_push(config, data):
with Console(verbose=config.get("verbose", False), exit_on_error=True) as c:
repo = init_repository(c, config["repository"])
pkg_mgr = PackageManager(repo, console=c)
pkg_mgr = PackageManager(repo, console=c, installer=None, is_python3=config.get("python3", False))
pkg_mgr.restore(data["zipped_repo"])

class BackupParser(object):
Expand Down
2 changes: 1 addition & 1 deletion ethronsoft/gcspypi/parsers/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
def handle_(config, data):
with Console(verbose=config.get("verbose", False), exit_on_error=True) as c:
repo = init_repository(c, config["repository"])
pkg_mgr = PackageManager(repo, console=c)
pkg_mgr = PackageManager(repo, console=c, installer=None, is_python3 = config.get("python3", False))
downloaded = pkg_mgr.download_by_name(data["obj"], data["dir"])
c.info("Downloaded: {0}".format(downloaded))

Expand Down
7 changes: 6 additions & 1 deletion ethronsoft/gcspypi/parsers/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
def handle_(config, data):
with Console(verbose=config.get("verbose", False), exit_on_error=True) as c:
repo = init_repository(c, config["repository"])
pkg_mgr = PackageManager(repo, console=c, mirroring=data["mirror"], install_deps=not data["no_dependencies"])
pkg_mgr = PackageManager(repo,
console=c,
installer=None,
is_python3=config.get("python3", False),
mirroring=data["mirror"],
install_deps=not data["no_dependencies"])
if data["requirements"]:
c.info("installing from requirements file...")
for syntax in open(data["requirements"], "r").readlines():
Expand Down
2 changes: 1 addition & 1 deletion ethronsoft/gcspypi/parsers/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
def handle_(config, data):
with Console(verbose=config.get("verbose", False), exit_on_error=True) as c:
repo = init_repository(c, config["repository"])
pkg_mgr = PackageManager(repo, console=c)
pkg_mgr = PackageManager(repo, console=c, installer=None, is_python3 = config.get("python3", False))
for path in sorted(pkg_mgr.list_items(data["package"], from_cache=True)):
c.output(path.split("/")[-1])

Expand Down
2 changes: 1 addition & 1 deletion ethronsoft/gcspypi/parsers/remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
def handle_(config, data):
with Console(verbose=config.get("verbose", False), exit_on_error=True) as c:
repo = init_repository(c, config["repository"])
pkg_mgr = PackageManager(repo, console=c)
pkg_mgr = PackageManager(repo, console=c, installer=None, is_python3 = config.get("python3", False))
for syntax in data["packages"]:
pkg = pkg_mgr.search(syntax)
ok = pkg is not None
Expand Down
2 changes: 1 addition & 1 deletion ethronsoft/gcspypi/parsers/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
def handle_(config, data):
with Console(verbose=config.get("verbose", False), exit_on_error=True) as c:
repo = init_repository(c, config["repository"])
pkg_mgr = PackageManager(repo, console=c)
pkg_mgr = PackageManager(repo, console=c, installer=None, is_python3 = config.get("python3", False))
for syntax in data["syntax"]:
pkg = pkg_mgr.search(syntax)
if pkg:
Expand Down
2 changes: 1 addition & 1 deletion ethronsoft/gcspypi/parsers/uninstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
def handle_(config, data):
with Console(verbose=config.get("verbose", False), exit_on_error=True) as c:
repo = init_repository(c, config["repository"])
pkg_mgr = PackageManager(repo, console=c)
pkg_mgr = PackageManager(repo, console=c, installer=None, is_python3 = config.get("python3", False))
for syntax in data["packages"]:
pkg_mgr.uninstall(Package.from_text(syntax))

Expand Down
2 changes: 1 addition & 1 deletion ethronsoft/gcspypi/parsers/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
def handle_(config, data):
with Console(verbose=config.get("verbose", False), exit_on_error=True) as c:
repo = init_repository(c, config["repository"])
pkg_mgr = PackageManager(repo, console=c, overwrite=data["overwrite"])
pkg_mgr = PackageManager(repo, console=c, installer=None, is_python3 = config.get("python3", False), overwrite=data["overwrite"])
pkg = PackageBuilder(os.path.abspath(data["file"])).build()
c.info("uploading {}...".format(str(pkg)))
pkg_mgr.upload(pkg, os.path.abspath(data["file"]))
Expand Down
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='gcspypi',
version='1.0.7',
version='1.0.8',
author='Ethronsoft',
author_email='[email protected]',
license=open("LICENSE").read(),
Expand All @@ -13,10 +13,10 @@
packages=find_packages(),
zip_safe=False,
install_requires=[
"tqdm",
"colorama",
"six==1.11.0",
"google-cloud-storage==1.5.0",
"tqdm>=4.32.0",
"colorama>=0.4.1",
"six>=1.12.0",
"google-cloud-storage>=1.23.0",
],
tests_require=[
"pytest",
Expand Down