Skip to content

Commit

Permalink
<Performance>[Python]: <Turn assertions off>
Browse files Browse the repository at this point in the history
[See the issue for problems;  Not yet working]

[#327]
  • Loading branch information
hasii2011 committed Mar 8, 2022
1 parent 38e220a commit 1a5f091
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ __pycache__/
/html/
build/
dist/
UNKNOWN.egg-info
Pyut.egg-info
/venv-pyenv-3.9.1/
/site/
/docs/
Expand Down
2 changes: 1 addition & 1 deletion scripts/cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ changeToProjectRoot

rm -rf dist build
rm -rf Pyut.dist Pyut.build
rm -rf src/Pyut.egg-info

find . -type d -name '*'.egg-info -delete
find . -type f -name pyutHistory"*" -delete
find . -type f -name "*.log" -delete
find . -type f -name UnitTest.gml -delete
Expand Down
11 changes: 9 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
OPTIONS = {}

setup(
name='Pyut',
version='6.5.4',
app=APP,
data_files=DATA_FILES,
packages=['org',
Expand Down Expand Up @@ -65,8 +67,13 @@
plist=dict(
CFBundleGetInfoString='Edits Pyut UML Files',
CFBundleIdentifier='org.pyut',
LSMinimumSystemVersion='12'
)),
LSMinimumSystemVersion='12',
LSEnvironment=dict(
APP_MODE='True',
PYTHONOPTIMIZE='1',
)
)
),
),
setup_requires=['py2app'],
install_requires=['antlr4-python3-runtime',
Expand Down
25 changes: 17 additions & 8 deletions src/Pyut.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

from os import chdir
from os import getcwd
from os import environ

from sys import path as sysPath
from sys import argv

Expand All @@ -11,6 +13,7 @@

from json import load as jsonLoad

from org.pyut.PyutConstants import PyutConstants
from org.pyut.PyutUtils import PyutUtils
from org.pyut.preferences.PyutPreferences import PyutPreferences

Expand All @@ -29,7 +32,7 @@ class Pyut:

def __init__(self):
self._setupSystemLogging()
self.logger: Logger = getLogger(__name__)
self.logger: Logger = getLogger(Pyut.MADE_UP_PRETTY_MAIN_NAME)
PyutPreferences.determinePreferencesLocation()
# Lang.importLanguage()

Expand All @@ -45,6 +48,9 @@ def __init__(self):
"""
self.handleCommandLineArguments()

optimize: str = environ.get(f'{PyutConstants.PYTHON_OPTIMIZE}')
self.logger.warning(f'{PyutConstants.PYTHON_OPTIMIZE}={optimize}')

@property
def userPath(self) -> str:
return self._userPath
Expand Down Expand Up @@ -93,11 +99,14 @@ def _getExePath(self) -> str:
return absPath

def _setOurSysPath(self):
try:
sysPath.append(self._exePath)
chdir(self._exePath)
except OSError as msg:
self.logger.error(f"Error while setting path: {msg}")
appMode: str = environ.get(f'{PyutConstants.APP_MODE}')
self.logger.warning(f'{{PyutConstants.APP_MODE}}={appMode}')
if appMode != 'True':
try:
sysPath.append(self._exePath)
chdir(self._exePath)
except OSError as msg:
self.logger.error(f"_setOurSysPath - Error while setting path: {msg}")

def _updateOurDirectoryPreferences(self):
"""
Expand Down Expand Up @@ -149,9 +158,9 @@ def displaySystemMetrics(self):

# noinspection PyUnreachableCode
if __debug__:
print("Assertions are turned on")
self.logger.warning("Assertions are turned on")
else:
print("Assertions are turned off")
self.logger.warning("Assertions are turned off")

def handleCommandLineArguments(self):
"""
Expand Down
5 changes: 4 additions & 1 deletion src/org/pyut/PyutConstants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from org.pyut.resources.img.methodparameters.DoNotDisplay import embeddedImage as doNotDisplayImage
from org.pyut.resources.img.methodparameters.UnSpecified import embeddedImage as unSpecifiedImage

# noinspection PyProtectedMember
from org.pyut.general.Globals import _

from org.pyut.enums.DiagramType import DiagramType
Expand All @@ -30,6 +31,9 @@ class PyutConstants:
PYUT_EXTENSION: str = '.put'
XML_EXTENSION: str = '.xml'
DEFAULT_FILENAME: str = _('Untitled') + PYUT_EXTENSION
APP_MODE: str = 'APP_MODE'
# noinspection SpellCheckingInspection
PYTHON_OPTIMIZE: str = 'PYTHONOPTIMIZE'

THE_GREAT_MAC_PLATFORM: str = 'darwin'

Expand Down Expand Up @@ -67,4 +71,3 @@ def doNotDisplayMethodsIcon() -> Bitmap:
def unspecifiedDisplayMethodsIcon() -> Bitmap:
bmp: Bitmap = unSpecifiedImage.GetBitmap()
return bmp

24 changes: 22 additions & 2 deletions src/org/pyut/resources/loggingConfiguration.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,37 @@
"class": "logging.StreamHandler",
"formatter": "pyutSimple",
"stream": "ext://sys.stdout"
},
"syslogHandler": {
"class": "logging.handlers.SysLogHandler",
"formatter": "pyutSimple"
},
"fileHandler": {
"class": "logging.handlers.WatchedFileHandler",
"formatter": "pyutSimple",
"filename": "/tmp/pyut.log",
"mode": "a",
"encoding": "utf-8"
},
"rotatingFileHandler": {
"class": "logging.handlers.logging.handlers.RotatingFileHandler",
"formatter": "pyutSimple",
"filename": "/tmp/pyut.log",
"mode": "a",
"maxBytes": 10240,
"backupCount": 5,
"encoding": "utf-8"
}

},
"loggers": {
"root": {
"level": "ERROR",
"handlers": ["consoleHandler"],
"handlers": ["rotatingFileHandler"],
"propagate": "False"
},
"Pyut": {
"level": "INFO",
"handlers": ["consoleHandler"],
"propagate": "False"
},
"org": {
Expand Down

0 comments on commit 1a5f091

Please sign in to comment.