Skip to content
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

[Requirements] Bump PyYAML #183

Merged
merged 3 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ jobs:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: '3.7'
python-version: '3.9'
cache: 'pipenv'

- name: Install pipenv
run: |
python -m pip install --upgrade pipenv wheel
python -m pipenv --python '3.7' install --dev
python -m pipenv --python '3.9' install --dev

- name: Run flake8
run: |
Expand All @@ -54,11 +54,11 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9']
python-version: ['3.9']
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pipenv'
Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,3 @@ magic-help:
.PHONY: install-requirements
install-requirements:
pipenv install --dev

6 changes: 2 additions & 4 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ name = "pypi"
nbconvert = ">=6.4.5"
# notebook.notebookapp has been deprecated since 7.0.0
notebook = ">=6.4, <7.0.0"
# pyyaml 6.0 added backwards incompatible change https://github.com/yaml/pyyaml/issues/576
pyyaml = ">=3.13, <6.0.0"
pyyaml = ">=3.13, <7"
requests = ">=2.20.1"
# nbconvert is not compatible with tornado 6 (which is in alpha)
#tornado = ">=5"
boto3 = ">=1.9"
importlib-metadata = "<8.0.0"

[dev-packages]
flake8 = "*"
Expand Down
2,127 changes: 1,171 additions & 956 deletions Pipfile.lock

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions nuclio/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@
from shutil import copyfile


def build_zip(zip_path, config, code, files=[], ext='.py', handler='handler'):
def build_zip(zip_path, config, code, files=None, ext='.py', handler='handler'):
files = files or []
z = zipfile.ZipFile(zip_path, "w")
config['spec']['build'].pop("functionSourceCode", None)
config['metadata'].pop("name", None)
z.writestr(handler + ext, code)
z.writestr('function.yaml', yaml.dump(config, default_flow_style=False))
z.writestr('function.yaml', yaml.safe_dump(config, default_flow_style=False))
for f in files:
if not path.isfile(f):
raise Exception('file name {} not found'.format(f))
Expand All @@ -43,7 +44,8 @@ def load_zip_config(zip_path):
return data['handler.py'], data['function.yaml']


def get_from_zip(zip_path, files=[]):
def get_from_zip(zip_path, files=None):
files = files or []
files_data = {}
with zipfile.ZipFile(zip_path) as myzip:
for f in files:
Expand Down
6 changes: 3 additions & 3 deletions nuclio/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def build_file(filename='', name='', handler='', archive=False, project='',

log = logger.info if verbose else logger.debug
log('Code:\n{}'.format(code))
log('Config:\n{}'.format(yaml.dump(config, default_flow_style=False)))
log('Config:\n{}'.format(yaml.safe_dump(config, default_flow_style=False)))

if archive or files:
output, url_target = archive_path(output_dir, project, name, tag)
Expand All @@ -106,7 +106,7 @@ def build_file(filename='', name='', handler='', archive=False, project='',
upload_file(zip_path, output, True)
config = get_archive_config(name, output)
config = extend_config(config, None, tag, filename)
config_text = yaml.dump(config, default_flow_style=False)
config_text = yaml.safe_dump(config, default_flow_style=False)
log('Archive Config:\n{}'.format(config_text))

elif output_dir:
Expand All @@ -116,7 +116,7 @@ def build_file(filename='', name='', handler='', archive=False, project='',

config['metadata'].pop("name", None)
put_data('{}/function.yaml'.format(output_dir),
yaml.dump(config, default_flow_style=False))
yaml.safe_dump(config, default_flow_style=False))
update_in(config, 'metadata.name', name)

# make sure we dont overwrite the source code
Expand Down
24 changes: 15 additions & 9 deletions nuclio/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,14 @@ def set_env(config, env):
create_or_update_env_var(config, key, value)


def set_env_dict(config, env={}):
def set_env_dict(config, env=None):
env = env or {}
for k, v in env.items():
create_or_update_env_var(config, k, value=str(v))


def set_external_source_env_dict(config, external_source_env={}):
def set_external_source_env_dict(config, external_source_env=None):
external_source_env = external_source_env or {}
for k, v in external_source_env.items():
create_or_update_env_var(config, k, value_from=v)

Expand Down Expand Up @@ -271,7 +273,11 @@ def update_env_var(config, key, value=None, value_from=None):
create_or_update_env_var(config, key, value=value, value_from=value_from)


def fill_config(config, extra_config={}, env={}, cmd=[], mount: Volume = None, external_source_env={}):
def fill_config(config, extra_config=None, env=None, cmd=None, mount: Volume = None, external_source_env=None):
extra_config = extra_config or {}
env = env or {}
cmd = cmd or []
external_source_env = external_source_env or {}
if config:
for k, v in extra_config.items():
current = get_in(config, k)
Expand Down Expand Up @@ -300,12 +306,12 @@ class ConfigSpec:

"""

def __init__(self, env={}, config={}, cmd=[],
mount: Volume = None, v3io=False, external_source_env={}):
self.env = env
self.external_source_env = external_source_env
self.extra_config = config
self.cmd = cmd
def __init__(self, env=None, config=None, cmd=None,
mount: Volume = None, v3io=False, external_source_env=None):
self.env = env or {}
self.external_source_env = external_source_env or {}
self.extra_config = config or {}
self.cmd = cmd or []
self.mounts = []
if mount:
self.mounts.append(mount)
Expand Down
6 changes: 3 additions & 3 deletions nuclio/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def deploy_zip(source='', name='', project='', tag='', dashboard_url='',

if verbose:
logger.info('Config:\n{}'.format(
yaml.dump(config, default_flow_style=False)))
yaml.safe_dump(config, default_flow_style=False)))

return deploy_config(config, dashboard_url, name=name, project=project,
tag=tag, verbose=verbose, create_new=create_project,
Expand All @@ -218,7 +218,7 @@ def deploy_code(code, dashboard_url='', name='', project='', handler='',
if verbose:
logger.info('Code:\n{}'.format(code))
logger.info('Config:\n{}'.format(
yaml.dump(newconfig, default_flow_style=False)))
yaml.safe_dump(newconfig, default_flow_style=False)))

if archive:
archive, url_target = archive_path(archive, name=name,
Expand All @@ -235,7 +235,7 @@ def deploy_code(code, dashboard_url='', name='', project='', handler='',
newconfig = get_archive_config(name, archive)
if verbose:
logger.info('Archive Config:\n{}'.format(
yaml.dump(newconfig, default_flow_style=False)))
yaml.safe_dump(newconfig, default_flow_style=False)))

newconfig = extend_config(newconfig, None, tag, 'code')
update_in(newconfig, 'metadata.name', name)
Expand Down
2 changes: 1 addition & 1 deletion nuclio/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def exporter_name():


def gen_config(config):
return header() + yaml.dump(config, default_flow_style=False)
return header() + yaml.safe_dump(config, default_flow_style=False)


def parse_magic_line(line):
Expand Down
12 changes: 6 additions & 6 deletions nuclio/magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,10 @@ def handler(context, event):

def save_handler(config_file, out_dir):
with open(config_file) as fp:
config = yaml.load(fp)
config_ = yaml.safe_load(fp)

py_code = b64decode(config['spec']['build']['functionSourceCode'])
py_module = config['spec']['handler'].split(':')[0]
py_code = b64decode(config_['spec']['build']['functionSourceCode'])
py_module = config_['spec']['handler'].split(':')[0]
with open('{}/{}.py'.format(out_dir, py_module), 'wb') as out:
out.write(py_code)

Expand Down Expand Up @@ -468,9 +468,9 @@ def print_handler_code(notebook_file=None):
if not notebook_file:
raise ValueError('cannot find notebook file name')

line = notebook_file = shlex.quote(notebook_file)
config, code = build(line, None, return_dir=True)
config_yaml = yaml.dump(config, default_flow_style=False)
line = shlex.quote(notebook_file)
config_, code = build(line, None, return_dir=True)
config_yaml = yaml.safe_dump(config_, default_flow_style=False)
print('Config:\n{}'.format(config_yaml))
print('Code:\n{}'.format(code))

Expand Down
1 change: 0 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

here = dirname(abspath(__file__))
environ['ENV_FILE'] = '{}/env.txt'.format(here)
is_travis = 'TRAVIS' in environ


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion tests/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_export():

def cases_from_yml_file(file_path: str):
with open(file_path) as f:
for case in yaml.load_all(f):
for case in yaml.safe_load_all(f):
yield pytest.param(case, id=case["name"])


Expand Down
48 changes: 0 additions & 48 deletions tests/test_install.py

This file was deleted.