-
Notifications
You must be signed in to change notification settings - Fork 4
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
RD-1601 py2 py3 setup #48
Open
IliaFeldgun
wants to merge
1
commit into
master
Choose a base branch
from
PEP-440
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+327
−156
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
*.pyc | ||
*.swp | ||
.idea | ||
__pycache__ | ||
dist | ||
build | ||
*.egg-info | ||
*.stratolog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM rackattack-nas.dc1:5000/ubuntu-dev-base:379308aa77bd0a19ebf12d868e7d19ee35a19d6c | ||
RUN apt-get install -y python2.7 python2.7-dev | ||
RUN curl 'https://bootstrap.pypa.io/pip/2.7/get-pip.py' | python2.7 | ||
COPY requirements.txt /tmp/requirements.txt | ||
COPY dev-requirements.txt /tmp/dev-requirements.txt | ||
RUN python2.7 -m pip install -r /tmp/requirements.txt -r /tmp/dev-requirements.txt | ||
RUN python3 -m pip install -r /tmp/requirements.txt -r /tmp/dev-requirements.txt | ||
RUN rm /tmp/requirements.txt /tmp/dev-requirements.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,29 @@ | ||
all: test check_convention | ||
.PHONY: all test build test_py2 test_py3 lint_py2 lint_py3 | ||
ARTIFACT=dist/strato_common_log-*-py2.py3-none-any.whl | ||
all: lint test build | ||
|
||
test: | ||
PYTHONPATH=$(PWD)/py python py/strato/common/log/tests/test.py | ||
test: test_py2 test_py3 | ||
|
||
check_convention: | ||
pep8 py --max-line-length=109 | ||
test_py3: | ||
PYTHONPATH=$(PWD)/py python3 py/strato/common/log/tests/test.py | ||
|
||
test_py2: | ||
PYTHONPATH=$(PWD)/py python2.7 py/strato/common/log/tests/test.py | ||
|
||
lint: lint_py2 lint_py3 | ||
|
||
lint_py3: | ||
python3 -m pep8 py --max-line-length=120 | ||
|
||
lint_py2: | ||
python2.7 -m pep8 py --max-line-length=120 | ||
|
||
build: $(ARTIFACT) | ||
|
||
clean: | ||
find . -name *.pyc -delete | ||
find . -name __pycache__ -delete | ||
rm -rf dist */*.egg-info build *.stratolog | ||
|
||
$(ARTIFACT): | ||
python3 -m build --wheel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# pycommonlog | ||
|
||
# Build | ||
```bash | ||
skipper make -i all | ||
``` | ||
|
||
# Demo | ||
|
||
```python | ||
from strato.common.log import configurelogging | ||
configurelogging.configureLogging('test-strato-log', forceDirectory=".") | ||
import logging # noqa: E402 | ||
logging.warning('Running test') | ||
logging.error('Running test') | ||
logging.progress('Running test') | ||
logging.step('Running test') | ||
logging.critical('Running test') | ||
logging.success('Running test') | ||
logging.debug('Running test') | ||
try: | ||
raise Exception('Test exception') | ||
except Exception: | ||
logging.exception('Running test') | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pips: | ||
- dist/strato_common_log-*-py2.py3-none-any.whl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
build | ||
pep8 | ||
ipdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +0,0 @@ | ||
import upseto.pythonnamespacejoin | ||
__path__.extend(upseto.pythonnamespacejoin.join(globals())) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +0,0 @@ | ||
import upseto.pythonnamespacejoin | ||
__path__.extend(upseto.pythonnamespacejoin.join(globals())) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,12 +7,16 @@ | |
import sys | ||
import atexit | ||
import json | ||
import subprocess | ||
import signal | ||
try: | ||
import subprocess32 as subprocess | ||
except ImportError: | ||
import subprocess | ||
|
||
_name = None | ||
_registered_file_handles = dict() | ||
|
||
|
||
def logFilename(name): | ||
return '%s/%s%s' % (config.LOGS_DIRECTORY, name, config.LOGS_SUFFIX) | ||
|
||
|
@@ -77,16 +81,21 @@ def changeHandlerLogLevelbyHandlerType(logger, logLevel, handlerType=None): | |
[handler.setLevel(logLevel) for handler in logger.handlers if not handlerType or type(handler) == handlerType] | ||
|
||
|
||
def _findCaller(): | ||
f = sys._getframe(3) | ||
def _findCallerPyAgnostic(*args, **kwargs): | ||
FILE_BLACKLIST = ['logging/__init__.py', 'common/log/morelevels.py', 'configurelogging.py'] | ||
f = logging.currentframe() | ||
while hasattr(f, "f_code"): | ||
co = f.f_code | ||
filename = os.path.normcase(co.co_filename) | ||
if 'logging/__init__.py' in filename or 'common/log/morelevels.py' in filename: | ||
if any([blacklisted in filename for blacklisted in FILE_BLACKLIST]): | ||
f = f.f_back | ||
continue | ||
return (filename, f.f_lineno, co.co_name) | ||
return ("(unknown file)", 0, "(unknown function)") | ||
if sys.version_info[0] == 2: | ||
return (filename, f.f_lineno, co.co_name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is co? I know some were already this way, but I really can't understand. |
||
return (filename, f.f_lineno, co.co_name, None) | ||
if sys.version_info[0] == 2: | ||
return ("(unknown file)", 0, "(unknown function)") | ||
return ("(unknown file)", 0, "(unknown function)", None) | ||
|
||
|
||
def _useColorsForScreenOutput(): | ||
|
@@ -118,7 +127,7 @@ def _configureOutputToScreen(logger, loggerName): | |
|
||
def _configureOutputToFile(logger, logName): | ||
if not os.path.isdir(config.LOGS_DIRECTORY): | ||
os.makedirs(config.LOGS_DIRECTORY, mode=0777) | ||
os.makedirs(config.LOGS_DIRECTORY, mode=0o777) | ||
handler = logging.FileHandler(filename=logFilename(logName)) | ||
atexit.register(handler.close) | ||
handler.setFormatter(machinereadableformatter.MachineReadableFormatter()) | ||
|
@@ -128,7 +137,8 @@ def _configureOutputToFile(logger, logName): | |
logger.addHandler(handler) | ||
global _registered_file_handles | ||
_registered_file_handles[logName] = (logger, handler) | ||
logger.findCaller = _findCaller | ||
logger.findCaller = _findCallerPyAgnostic | ||
|
||
|
||
def _configureLogLevels(name): | ||
if config.LOG_CONFIGURATION is not None: | ||
|
@@ -140,37 +150,42 @@ def _configureLogLevels(name): | |
try: | ||
with open(config.LOGS_CONFIGURATION_OVERRIDE_FILE, 'rt') as f: | ||
overrides = json.load(f) | ||
except: #pylint: disable=bare-except | ||
except: # pylint: disable=bare-except | ||
overrides = {} | ||
default_overrides = overrides.get('default_log_overrides', {}) | ||
dictConfig.update(default_overrides) | ||
dictConfig.update(overrides.get(name, {})) | ||
logging.config.dictConfig(dictConfig) | ||
|
||
|
||
def reopenLogginFiles(): | ||
global _registered_file_handles | ||
save_handles = _registered_file_handles | ||
_registered_file_handles = dict() | ||
for logName, (logger, handler) in save_handles.iteritems(): | ||
for logName, (logger, handler) in save_handles.items(): | ||
handler.close() | ||
logger.removeHandler(handler) | ||
_configureOutputToFile(logger, logName) | ||
|
||
|
||
def reloadLoggingConfiguration(): | ||
reopenLogginFiles() | ||
global _name | ||
if _name is not None: | ||
_configureLogLevels(_name) | ||
|
||
|
||
def _handleLoggingConfigurationSignal(signal, stackFrame): | ||
reloadLoggingConfiguration() | ||
|
||
|
||
def _getMultipleFuncsHandler(funcs): | ||
def _multipleFuncsHandler(signalNumber, stackFrame): | ||
for func in funcs: | ||
func(signalNumber, stackFrame) | ||
return _multipleFuncsHandler | ||
|
||
|
||
def _configureLoggingSignalHandlers(): | ||
currentHandler = signal.getsignal(config.UPDATE_LOGGING_CONFIGURATION_SIGNAL) | ||
if currentHandler in [signal.SIG_IGN, signal.SIG_DFL, None]: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is f