Skip to content

Commit

Permalink
Update of requirements.txt ++
Browse files Browse the repository at this point in the history
 * Update of `--production` logic
  • Loading branch information
funilrys committed Jun 15, 2018
1 parent bd40433 commit bde642b
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 52 deletions.
2 changes: 1 addition & 1 deletion PyFunceble/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
from PyFunceble.production import Production

CURRENT_DIRECTORY = getcwd() + directory_separator
VERSION = "0.80.4.dev-beta"
VERSION = "0.80.5.dev-beta"

CONFIGURATION_FILENAME = ".PyFunceble.yaml"

Expand Down
154 changes: 112 additions & 42 deletions PyFunceble/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,63 +69,75 @@
from PyFunceble.clean import Clean
from PyFunceble.config import Version
from PyFunceble.directory_structure import DirectoryStructure
from PyFunceble.helpers import Dict, File, Regex
from PyFunceble.helpers import Dict, File, Regex, Command


class Production(object): # pylint: disable=too-few-public-methods
"""
This class will manage and provide the production logic.
Argument:
- extern: bool
True: We do not execute the logic and allow method to be called.
"""

def __init__(self):
self.data_version_yaml = self._get_current_version_yaml()
def __init__(self, extern=False):
if not extern:

self.version_yaml = Version(True).split_versions(
self.data_version_yaml["current_version"]
)
self.current_version = Version(True).split_versions(PyFunceble.VERSION, True)
if not self._is_dev_version() and not self._is_master_version():
raise Exception("Please switch to `dev` or `master` branch.")

if self._is_version_greater():
Clean(None)
DirectoryStructure(production=True)
self.data_version_yaml = self._get_current_version_yaml()

if self._does_require_deprecation():
to_deprecate = ".".join(self.version_yaml)
self.version_yaml = Version(True).split_versions(
self.data_version_yaml["current_version"]
)
self.current_version = Version(True).split_versions(
PyFunceble.VERSION, True
)

self.data_version_yaml["deprecated"].append(to_deprecate)
if self._is_version_greater():
Clean(None)
DirectoryStructure(production=True)

if self._does_require_force_update():
to_force_update = ".".join(self.version_yaml)
if self._does_require_deprecation():
to_deprecate = ".".join(self.version_yaml)

self.data_version_yaml["force_update"]["minimal_version"].append(
to_force_update
)
self.data_version_yaml["deprecated"].append(to_deprecate)

if self.current_version[-1]:
self.current_version[0].append(self.current_version[-1])
if self._does_require_force_update():
to_force_update = ".".join(self.version_yaml)

self.data_version_yaml["current_version"] = ".".join(
self.current_version[0]
)
self.data_version_yaml["force_update"]["minimal_version"].append(
to_force_update
)

Dict(self.data_version_yaml).to_yaml(
PyFunceble.CURRENT_DIRECTORY + "version.yaml"
)
if self.current_version[-1]:
self.current_version[0].append(self.current_version[-1])

self.data_version_yaml["current_version"] = ".".join(
self.current_version[0]
)

self._update_readme_md()
Dict(self.data_version_yaml).to_yaml(
PyFunceble.CURRENT_DIRECTORY + "version.yaml"
)

message = Fore.GREEN + Style.BRIGHT + "We are ready to ship!! \n"
message += Fore.CYAN + "Please do not touch version.yaml nor setup.py (version update)"
self._update_readme_md()
self._update_setup_py()

print(message)
exit(0)
else:
print(
Fore.YELLOW
+ Style.BRIGHT
+ "Are you sure that you did some changes ? Please update PyFunceble.VERSION if it is the case." # pylint: disable=line-too-long
)
exit(1)
message = Fore.GREEN + Style.BRIGHT + "We are ready to ship!! \n"
message += Fore.CYAN + "Please do not touch version.yaml nor setup.py (version update)" # pylint: disable=line-too-long

print(message)
exit(0)
else:
print(
Fore.YELLOW
+ Style.BRIGHT
+ "Are you sure that you did some changes ? Please update PyFunceble.VERSION if it is the case." # pylint: disable=line-too-long
)
exit(1)

@classmethod
def _get_current_version_yaml(cls):
Expand All @@ -151,6 +163,36 @@ def _is_version_greater(self):

return False

@classmethod
def _is_dev_version(cls):
"""
This method check if the current branch is `dev`.
"""

command = "git branch"
command_result = Command(command).execute()

for branch in command_result.split("\n"):
if branch.startswith("*") and "dev" in branch:
return True

return False

@classmethod
def _is_master_version(cls):
"""
This method check if the current branch is `master`.
"""

command = "git branch"
command_result = Command(command).execute()

for branch in command_result.split("\n"):
if branch.startswith("*") and "master" in branch:
return True

return False

def _does_require_deprecation(self):
"""
This method check if we have to put the previous version into the deprecated list.
Expand All @@ -173,23 +215,51 @@ def _does_require_force_update(self):

return False

@classmethod
def _update_readme_md(cls):
def _update_readme_md(self):
"""
This method update README.md so that it's always giving branch related bases.
Note: This only apply to dev and master
"""

readme_path = PyFunceble.CURRENT_DIRECTORY + "README.md"

if "dev" in PyFunceble.VERSION:
if self._is_dev_version():
regexes = {"/dev/": r"\/master\/", "=dev": "=master"}
else:
elif self._is_master_version():
regexes = {"/master/": r"\/dev\/", "=master": "=dev"}
else:
raise Exception("Please switch to `dev` or `master` branch.")

to_update = File(readme_path).read()

for replacement, regex in regexes.items():
to_update = Regex(to_update, regex, replace_with=replacement).replace()

File(readme_path).write(to_update, overwrite=True)

def _update_setup_py(self):
"""
This method will update setup.py so that it always have the right name.
"""

setup_py_path = PyFunceble.CURRENT_DIRECTORY + "setup.py"

if self._is_dev_version():
regexes = {
'name="PyFunceble-dev"': r'name=".*"',
"Development Status :: 4 - Beta": r'Development\sStatus\s::.*"',
}
elif self._is_master_version():
regexes = {
'name="PyFunceble"': r'name=".*"',
"Development Status :: 5 - Production/Stable": r'Development\sStatus\s::.*"',
}
else:
raise Exception("Please switch to `dev` or `master` branch.")

to_update = File(setup_py_path).read()

for replacement, regex in regexes.items():
to_update = Regex(to_update, regex, replace_with=replacement).replace()

File(setup_py_path).write(to_update, overwrite=True)
12 changes: 6 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
urllib3>=1.22
requests>=2.18.4
colorama>=0.3.9
PyYAML>=3.12
setuptools>=39.0.1
pypandoc>=1.4
requests==2.18.4
colorama==0.3.9
urllib3==1.22
pypandoc==1.4
setuptools==39.2.0
PyYAML==3.12
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def _get_long_description():

if __name__ == "__main__":
setup(
name="PyFunceble",
name="PyFunceble-dev",
version=_get_version(),
install_requires=_get_requirements(),
description="The tool to check domains or IP availability.",
Expand All @@ -148,7 +148,7 @@ def _get_long_description():
classifiers=[
"Environment :: Console",
"Topic :: Internet",
"Development Status :: 5 - Production/Stable",
"Development Status :: 4 - Beta,
"Intended Audience :: Developers",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
Expand Down
2 changes: 1 addition & 1 deletion version.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
current_version: 0.80.4.dev-beta
current_version: 0.80.5.dev-beta
deprecated: [0.0.0, 0.0.1, 0.65.0, 0.67.1, 0.68.0, 0.69.3, 0.69.5, 0.70.4, 0.71.2,
0.72.7, 0.73.1, 0.74.5, 0.75.1, 0.76.2, 0.77.0, 0.78.0, 0.79.1]
force_update:
Expand Down

0 comments on commit bde642b

Please sign in to comment.