Skip to content

Commit

Permalink
Merge pull request #13 from jlsneto/dev
Browse files Browse the repository at this point in the history
release-config: added new version validate
  • Loading branch information
jlsneto authored Jan 20, 2020
2 parents bf35d03 + d953265 commit 6ca16f6
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 18 deletions.
5 changes: 5 additions & 0 deletions cereja/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from cereja.utils import get_version_pep440_compliant
from . import utils
from importlib import import_module

VERSION = "1.0.0.final.0"

__version__ = get_version_pep440_compliant()

cj_modules_dotted_path = utils.import_string('cereja.conf.cj_modules_dotted_path')

for dot_module in cj_modules_dotted_path:
Expand Down
1 change: 1 addition & 0 deletions cereja/cj_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

T = Union[int, float, str]
Number = Union[float, int, complex]
PEP440 = Tuple[int, int, int, str, int]
5 changes: 1 addition & 4 deletions cereja/conf.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import sys
import logging

VERSION = "0.3.5"

# using by utils.module_references
_explicit_exclude = ["console_logger", "cj_modules"]
_explicit_include = ["VERSION"]
_explicit_exclude = ["console_logger", "cj_modules_dotted_path"]

# Used to add the functions of each module at the root
cj_modules_dotted_path = ['cereja.common', 'cereja.conf', 'cereja.decorators', 'cereja.path',
Expand Down
79 changes: 78 additions & 1 deletion cereja/utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import datetime
import functools
import os
from importlib import import_module
import subprocess
import importlib
import sys
import types
from typing import Any, Union
from typing import Any, Union, Tuple, Sequence
import logging

from cereja.cj_types import PEP440

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -103,3 +108,75 @@ def set_log_level(level: int):
def logger_level():
import logging
return logging.getLogger().level


def get_version(version: Union[str, PEP440] = None) -> PEP440:
"""
Dotted version of the string type is expected
e.g:
'1.0.3.a.3' # Pep440 see https://www.python.org/dev/peps/pep-0440/
:param version: Dotted version of the string
"""
if version is None:
from cereja import VERSION as version

if isinstance(version, str):
version = version.split('.')
version_note = version.pop(3)
version = list(map(int, version))
version.insert(3, version_note)

assert len(version) == 5, "Version must be size 5"

assert version[3] in ('alpha', 'beta', 'rc', 'final')
return version


@functools.lru_cache()
def latest_git():
"""
Return a numeric identifier of the latest git changeset.
"""
repo_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
git_log = subprocess.run(
['git', 'log', '--pretty=format:%ct', '--quiet', '-1', 'HEAD'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
shell=True, cwd=repo_dir, universal_newlines=True,
)
timestamp = git_log.stdout
try:
timestamp = datetime.datetime.utcfromtimestamp(int(timestamp))
except ValueError:
return None
return timestamp.strftime('%Y%m%d%H%M%S')


def get_version_pep440_compliant(version: str = None) -> str:
"""
Dotted version of the string type is expected
e.g:
'1.0.3.a.3' # Pep440 see https://www.python.org/dev/peps/pep-0440/
:param version: Dotted version of the string
"""
version_mapping = {'alpha': 'a', 'beta': 'b', 'rc': 'rc'}
version = get_version(version)
root_version = '.'.join(map(str, version[:3]))

sub = ''
if version[3] == 'alpha' and version[4] == 0:
git = latest_git()
if git:
sub = f'.dev{git}'

elif version[3] != 'final':
sub = version_mapping[version[3]] + str(version[4])

return f"{root_version}{sub}"


if __name__ == '__main__':
print(get_version_pep440_compliant())
42 changes: 31 additions & 11 deletions cj_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@
import sys
import os
import logging
import shutil

choice_level_change = """
0 -> major
1 -> minor
2 -> micro
Choose the level of change:
"""
logger = logging.getLogger(__name__)

base_dir = os.path.dirname(os.path.abspath(__file__))
os.chdir(base_dir)
setup_file = os.path.join(base_dir, 'setup.py')
conf_file = os.path.join(base_dir, 'cereja', 'conf.py')
conf_file = os.path.join(base_dir, 'cereja', '__ini__.py')

tests_case_result = subprocess.run([f"{sys.executable}", "-m", "unittest", "tests.tests.UtilsTestCase"]).returncode

Expand All @@ -24,23 +32,26 @@
print("Ok Exiting...")

if tests_case_result == 0 and allow_update_version:
level_change = int(input(choice_level_change))
with open(conf_file, 'r') as f:
lines = f.readlines()
for i, line in enumerate(lines):
if "VERSION = " in line:
version_base, version_middle, version_end = [int(i) for i in
line.strip().split('=')[1].strip(' "').split('.')]
if version_end < 10:
version_end = version_end + 1
elif version_middle < 10:
version_end = 0
version_middle = version_middle + 1
major, minor, micro = [int(i) for i in
line.strip().split('=')[1].strip(' "').split('.')]
is_release = input("Is Final? Y/n")
if micro < 10:
micro = micro + 1
elif minor < 10:
micro = 0
minor = minor + 1
else:
version_middle = 0
version_base = version_base + 1
minor = 0
major = major + 1

version = f'{version_base}.{version_middle}.{version_end}'
version = f'{major}.{minor}.{micro}'
lines[i] = f'VERSION = "{version}"\n'
break

with open(conf_file, 'w') as f:
f.writelines(lines)
Expand All @@ -59,3 +70,12 @@
subprocess.run([f"{sys.executable}", "-m", "twine", "upload", f"{dist}{os.path.sep}*"])
else:
print("Versão não foi enviada.")

# Remove latest build, info and dist
files_cereja_build = [
os.path.join(base_dir, 'build'),
os.path.join(base_dir, 'cereja.egg-info'),
os.path.join(base_dir, 'dist')
]
for p in files_cereja_build:
shutil.rmtree(p)
Empty file added lab/__init__.py
Empty file.
34 changes: 34 additions & 0 deletions lab/cj_lab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from typing import TypeVar

from cereja.common import flatten, get_shape

T = TypeVar('T')


class Vector(list):
"""
-- Development proposal --
Vector is a dynamic array, whose size can be increased and can store any type of objects
"""

def __init__(self, values):
super().__init__(values)
self._size = len(self.flatten())
self._shape = get_shape(self)

@property
def size(self):
# Need to create smart way to check changes
return self._size

@property
def shape(self):
# need to create smart way to check changes
return self._shape

def first(self) -> T:
return self[0]

def flatten(self):
return flatten(self)
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
with open("README.md", "r") as fh:
long_description = fh.read()

EXCLUDE_FROM_PACKAGES = ('cereja.tests'
EXCLUDE_FROM_PACKAGES = ('cereja.tests',
'cereja.lab',
)

setuptools.setup(
name="cereja",
version=cereja.VERSION,
version=cereja.__version__,
author="Joab Leite",
author_email="[email protected]",
description="Cereja is a bundle of useful functions that I don't want to rewrite.",
Expand Down

0 comments on commit 6ca16f6

Please sign in to comment.