Skip to content

Commit

Permalink
Merge branch 'main' of github.com:odoonix/utils
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafabarmshory committed Feb 23, 2025
2 parents 54ab3d6 + f778892 commit 234bea4
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 117 deletions.
83 changes: 23 additions & 60 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -1,70 +1,33 @@
# This workflow will upload a Python Package to PyPI when a release is created
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflows will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

name: Upload Python Package

on:
release:
types: [published]

permissions:
contents: read
push:
tags:
- "**"

jobs:
release-build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: "3.x"

- name: Build release distributions
run: |
# NOTE: put your own distribution build steps here.
python -m pip install build
python -m build
- name: Upload distributions
uses: actions/upload-artifact@v4
with:
name: release-dists
path: dist/

pypi-publish:
publish-package:
runs-on: ubuntu-latest
needs:
- release-build
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write

# Dedicated environments with protections for publishing are strongly recommended.
# For more information, see: https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#deployment-protection-rules
environment:
name: pypi
# OPTIONAL: uncomment and update to include your PyPI project URL in the deployment status:
# url: https://pypi.org/p/YOURPROJECT
#
# ALTERNATIVE: if your GitHub Release name is the PyPI project version string
# ALTERNATIVE: exactly, uncomment the following line instead:
# url: https://pypi.org/project/YOURPROJECT/${{ github.event.release.name }}

defaults:
run:
shell: bash -l {0}
steps:
- name: Retrieve release distributions
uses: actions/download-artifact@v4
- name: Checkout Repo
uses: actions/checkout@v4
with:
name: release-dists
path: dist/

- name: Publish release distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
fetch-depth: 0 # avoids shallow checkout as needed by setuptools-scm
- name: Set up Python
uses: actions/setup-python@v5
with:
packages-dir: dist/
python-version: "3.10"
- name: Build Project and Publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
python -m pip install --upgrade pip setuptools tox
python -m tox -e clean,build
python -m tox -e publish -- --verbose --repository pypi
1 change: 1 addition & 0 deletions odoo/odoo
Submodule odoo added at a72ccd
4 changes: 3 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# https://setuptools.pypa.io/en/latest/references/keywords.html

[metadata]
name = utils
name = otoolbox
description = Utilities for Odoo from Odoonix
author = Odoonix
author_email = [email protected]
Expand Down Expand Up @@ -87,6 +87,8 @@ testing =
#
console_scripts =
otoolbox = otoolbox:run
otoolbox-workspace = otoolbox.workspace:run
otoolbox-repo = otoolbox.repositories:run


[tool:pytest]
Expand Down
55 changes: 27 additions & 28 deletions src/otoolbox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
from otoolbox import utils

from otoolbox.constants import (
ERROR_CODE_PRE_VERIFICATION,
ERROR_CODE_POST_VERIFICATION

ERROR_CODE_PRE_VERIFICATION,
ERROR_CODE_POST_VERIFICATION

)

Expand All @@ -35,24 +35,20 @@
del version, PackageNotFoundError






# def init_cli():
# """Initialize the command-line interface for the Odoo Toolbox."""
# arg_parser = argparse.ArgumentParser(
# prog='odoo-util',
# description="""
# Odoonix Toolbox is a comprehensive suite of tools designed to streamline
# the workflows of developers and maintainers working with Odoo. It
# simplifies tasks such as tracking changes in addons, cloning
# repositories, managing databases, and configuring development
# environments. With its user-friendly interface and automation
# features, Odoonix Toolbox enables teams to maintain consistency,
# reduce manual effort, and speed up development cycles. By integrating
# essential functionalities into one cohesive package, it empowers
# developers to focus on creating and maintaining high-quality Odoo
# Odoonix Toolbox is a comprehensive suite of tools designed to streamline
# the workflows of developers and maintainers working with Odoo. It
# simplifies tasks such as tracking changes in addons, cloning
# repositories, managing databases, and configuring development
# environments. With its user-friendly interface and automation
# features, Odoonix Toolbox enables teams to maintain consistency,
# reduce manual effort, and speed up development cycles. By integrating
# essential functionalities into one cohesive package, it empowers
# developers to focus on creating and maintaining high-quality Odoo
# solutions efficiently.
# """,
# epilog='Developer toolbox'
Expand Down Expand Up @@ -95,8 +91,8 @@ def _load_resources(*args):
package.init()



if __name__ == '__main__':
def run():
"""Run the application"""
_load_resources(
'otoolbox.addons.help',
'otoolbox.addons.workspace',
Expand All @@ -105,20 +101,19 @@ def _load_resources(*args):
'otoolbox.addons.repositories'
)


def callback_common_arguments(
odoo:str='18.0',
path:str='.',
silent:bool=False,
pre_check:bool=False,
post_check:bool=False,
continue_on_exception:bool=True
):
odoo: str = '18.0',
path: str = '.',
silent: bool = False,
pre_check: bool = False,
post_check: bool = False,
continue_on_exception: bool = True
):
env.context.update({
'odoo_version': odoo,
'path': path,
'silent': silent,
'pre_check':pre_check,
'pre_check': pre_check,
'post_check': post_check,
'continue_on_exception': continue_on_exception
})
Expand All @@ -133,7 +128,7 @@ def callback_common_arguments(
def result_callback(*args, **kargs):
if env.context.get('post_check', False):
utils.verify_all_resource()

# Launch the CLI application
app = typer.Typer(
callback=callback_common_arguments,
Expand All @@ -144,3 +139,7 @@ def result_callback(*args, **kargs):
app.add_typer(repositories.app, name="repo")
app.add_typer(developer.app, name="dev")
app()


if __name__ == '__main__':
run()
4 changes: 2 additions & 2 deletions src/otoolbox/addons/repositories/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def _load_repositories():

if not data:
data = env.resource_string(
RESOURCE_REPOSITORIES_PATH,
RESOURCE_REPOSITORIES_PATH,
packag_name=__name__
)
repo_list = json.loads(data)
Expand All @@ -42,7 +42,7 @@ def _load_repositories():
env.add_resource(
path="{}/{}".format(item["workspace"], item["name"]),
parent=item["workspace"],
title="Git repository: {}/{}".format(item["workspace"], item["name"]),
title=item["name"],
description="""Automaticaly added resources from git.""",
constructors=[
git.git_clone
Expand Down
13 changes: 9 additions & 4 deletions src/otoolbox/addons/repositories/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

_logger = logging.getLogger(__name__)

# GIT
GIT_ADDRESS_HTTPS = "https://github.com/{path}.git"
GIT_ADDRESS_SSH = "[email protected]:{path}.git"

GIT_ERROR_TABLE = {
2: {
'level': 'fatal',
Expand All @@ -18,6 +22,7 @@
}
}


def _rais_git_error(context, error_code):
if not error_code:
return
Expand All @@ -26,13 +31,13 @@ def _rais_git_error(context, error_code):
'message': "Unknown GIT error for distination path {path}. Error code is {error_code}. "
"See .otoolbox/logs.text for more information."
})
message = error['message'].format(error_code=error_code,**context.__dict__)
message = error['message'].format(error_code=error_code, **context.__dict__)
if env.context.get('continue_on_exception'):
_logger.error(message)
env.errors.append(message)
else:
raise RuntimeError(
error['message'].format(error_code=error_code,**context.__dict__)
error['message'].format(error_code=error_code, **context.__dict__)
)


Expand All @@ -48,13 +53,13 @@ def git_clone(context):
'clone',
'--branch', branch_name,
'--depth', depth,
f"[email protected]:{context.path}.git"
(GIT_ADDRESS_HTTPS if not env.context.get('ssh_git', False)
else GIT_ADDRESS_SSH).format(path=context.path),
], cwd=cwd)

_rais_git_error(context=context, error_code=result)



def git_pull(context):
"""Pull the git repository from github
"""
Expand Down
4 changes: 2 additions & 2 deletions src/otoolbox/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ class WorkspaceResourceGroup(WorkspaceResource):

def __init__(self,
path,
resources=None,
root=None,
resources=None,
root=None,
**kargs):
super().__init__(path, **kargs)
self.resources = resources if resources else []
Expand Down
20 changes: 12 additions & 8 deletions src/otoolbox/env.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
"""Envirnement fo the sysetm"""


import pkg_resources
# Standard
import os
import sys

# 3th party
import pkg_resources

# Odoo toolbox
from otoolbox.base import (
WorkspaceResource,
WorkspaceResourceGroup
)

from otoolbox.constants import(
RESOURCE_PREFIX_VIRTUAL
from otoolbox.constants import (
RESOURCE_PREFIX_VIRTUAL
)

VERSION = "0.1.0"
Expand All @@ -31,12 +34,12 @@
errors = []


def resource_string(resource_name:str, packag_name:str="otoolbox", encoding:str="utf-8"):
def resource_string(resource_name: str, packag_name: str = "otoolbox", encoding: str = "utf-8"):
"""Load resource"""
return pkg_resources.resource_string(packag_name, resource_name).decode(encoding)


def resource_stream(resource_name:str, packag_name:str="otoolbox"):
def resource_stream(resource_name: str, packag_name: str = "otoolbox"):
"""Load resource"""
return pkg_resources.resource_stream(packag_name, resource_name)

Expand All @@ -55,11 +58,12 @@ def get_workspace_path(path):
# Resource
#################################################################################
def add_resource(**kargs):
"""Add a resource to the workspace"""
resource = WorkspaceResource(**kargs)
path = kargs.get('path')
group = context['resources'].get(path)
if not group:
group = WorkspaceResourceGroup(path=path)
group = WorkspaceResourceGroup(**kargs)
group.append(resource)
context['resources'].append(group)
return sys.modules[__name__]
Loading

0 comments on commit 234bea4

Please sign in to comment.