Skip to content

Commit

Permalink
Python Code Cleanup (#24)
Browse files Browse the repository at this point in the history
* Python code cleanup by the cleanup-python-code Jenkins job.

This pull request was generated by the cleanup-python-code Jenkins job, which ran
```
modernize_travis;modernize_tox;make upgrade;find . -type f -name '*.py' | while read fname; do pyupgrade --exit-zero-even-if-changed --keep-percent-format --py3-plus --py36-plus --py38-plus "$fname"; done
```

The following packages were installed:
`pyupgrade,git+https://github.com/edx/repo-tools.git@c05453b733602ba7a2224ffbbf58a8d0903b62d8`

* Drop Python 3.6

* Bump version major

Co-authored-by: Zulqarnain <muhammad.zulqarnain@arbisoft.com>
  • Loading branch information
edx-requirements-bot and Zulqarnain committed Jan 18, 2021
1 parent a674c74 commit 5f16bd3
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 43 deletions.
10 changes: 4 additions & 6 deletions .travis.yml
@@ -1,16 +1,14 @@
language: python
matrix:
include:
- python: 3.6
env: TOXENV=py36
- python: 3.8
- python: '3.8'
env: TOXENV=py38
install:
- "pip install -r requirements/development.txt"
- pip install -r requirements/development.txt
script:
- tox -e $TOXENV
- tox -e $TOXENV
services:
- docker
- docker
deploy:
- provider: pypi
on:
Expand Down
8 changes: 4 additions & 4 deletions asym_crypto_yaml/crypto.py
Expand Up @@ -322,7 +322,7 @@ def add_secret_to_yaml_file(yaml_key, yaml_value_unencrypted, public_key_file, y
"""
public_key = load_public_key_from_file(public_key_file)
encrypted = encrypt_value(yaml_value_unencrypted, public_key)
with open(yaml_file_to_append_to, "r") as f:
with open(yaml_file_to_append_to) as f:
encrypted_dict = _safe_load(f)
if encrypted_dict is None:
encrypted_dict = {}
Expand Down Expand Up @@ -424,7 +424,7 @@ def decrypt_yaml_file_and_write_encrypted_file_to_disk(input_yaml_file_path, pri
private_key = None
if private_key_path is not None:
private_key = load_private_key_from_file(private_key_path)
with open(input_yaml_file_path, "r") as f:
with open(input_yaml_file_path) as f:
encrypted_secrets = _safe_load(f)
decrypted_secrets_dict = decrypt_yaml_dict(encrypted_secrets, private_key)
write_dict_to_yaml(decrypted_secrets_dict, output_yaml_file_path)
Expand All @@ -435,7 +435,7 @@ def reencrypt_secrets_and_write_to_yaml_file(input_yaml_file_path, private_key_p
if private_key_path and public_key_path is not None:
private_key = load_private_key_from_file(private_key_path)
public_key = load_public_key_from_file(public_key_path)
with open(input_yaml_file_path, "r") as f:
with open(input_yaml_file_path) as f:
encrypted_secrets = _safe_load(f)
encrypted_secrets_dict = reencrypt_secrets(encrypted_secrets, private_key, public_key)
write_dict_to_yaml(encrypted_secrets_dict, input_yaml_file_path)
Expand All @@ -448,7 +448,7 @@ def rotate_secrets_and_write_to_yaml_file(secrets_dir_path, private_key_path, pu
private_key = load_private_key_from_file(private_key_path)
public_key = load_public_key_from_file(public_key_path)
for input_yaml_file_path in glob.glob(os.path.join(secrets_dir_path, '*.y*ml')):
with open(input_yaml_file_path, "r") as f:
with open(input_yaml_file_path) as f:
encrypted_secrets = _safe_load(f)
encrypted_secrets_dict = rotate_secrets(encrypted_secrets, private_key, public_key, old_secret, new_secret)
write_dict_to_yaml(encrypted_secrets_dict, input_yaml_file_path)
4 changes: 2 additions & 2 deletions requirements/base.txt
Expand Up @@ -4,9 +4,9 @@
#
# make upgrade
#
cffi==1.14.3 # via cryptography
cffi==1.14.4 # via cryptography
click==7.1.2 # via -r requirements/base.in
cryptography==3.2.1 # via -r requirements/base.in
cryptography==3.3.1 # via -r requirements/base.in
pycparser==2.20 # via cffi
pyyaml==5.3.1 # via -r requirements/base.in
six==1.15.0 # via cryptography
18 changes: 9 additions & 9 deletions requirements/development.txt
Expand Up @@ -6,24 +6,24 @@
#
appdirs==1.4.4 # via virtualenv
attrs==20.3.0 # via pytest
cffi==1.14.3 # via -r requirements/base.txt, cryptography
cffi==1.14.4 # via -r requirements/base.txt, cryptography
click==7.1.2 # via -r requirements/base.txt, -r requirements/pip-tools.txt, pip-tools
cryptography==3.2.1 # via -r requirements/base.txt
cryptography==3.3.1 # via -r requirements/base.txt
distlib==0.3.1 # via virtualenv
filelock==3.0.12 # via tox, virtualenv
iniconfig==1.1.1 # via pytest
packaging==20.4 # via pytest, tox
pip-tools==5.3.1 # via -r requirements/pip-tools.txt
packaging==20.8 # via pytest, tox
pip-tools==5.5.0 # via -r requirements/pip-tools.txt
pluggy==0.13.1 # via pytest, tox
py==1.9.0 # via pytest, tox
py==1.10.0 # via pytest, tox
pycparser==2.20 # via -r requirements/base.txt, cffi
pyparsing==2.4.7 # via packaging
pytest==6.1.2 # via -r requirements/development.in
pytest==6.2.1 # via -r requirements/development.in
pyyaml==5.3.1 # via -r requirements/base.txt
six==1.15.0 # via -r requirements/base.txt, -r requirements/pip-tools.txt, cryptography, packaging, pip-tools, tox, virtualenv
six==1.15.0 # via -r requirements/base.txt, cryptography, tox, virtualenv
toml==0.10.2 # via pytest, tox
tox==3.20.1 # via -r requirements/development.in
virtualenv==20.1.0 # via tox
tox==3.21.0 # via -r requirements/development.in
virtualenv==20.3.0 # via tox

# The following packages are considered to be unsafe in a requirements file:
# pip
3 changes: 1 addition & 2 deletions requirements/pip-tools.txt
Expand Up @@ -5,8 +5,7 @@
# make upgrade
#
click==7.1.2 # via pip-tools
pip-tools==5.3.1 # via -r requirements/pip-tools.in
six==1.15.0 # via pip-tools
pip-tools==5.5.0 # via -r requirements/pip-tools.in

# The following packages are considered to be unsafe in a requirements file:
# pip
1 change: 0 additions & 1 deletion scripts/__init__.py
@@ -1,2 +1 @@

from .asym_crypto_yaml import *
5 changes: 2 additions & 3 deletions setup.py
Expand Up @@ -6,7 +6,6 @@

from setuptools import setup, find_packages
from os import path
from io import open

def load_requirements(*requirements_paths):
"""
Expand Down Expand Up @@ -39,9 +38,9 @@ def is_requirement(line):

setup(
name='asym_crypto_yaml', # Required
version='0.0.16', # Required
version='0.1.0', # Required
packages=find_packages(exclude=['contrib', 'docs', 'tests']), # Required
python_requires=">=3.6",
python_requires=">=3.8",
include_package_data=True,
install_requires=load_requirements('requirements/base.in'),
entry_points='''
Expand Down
16 changes: 8 additions & 8 deletions tests/test_crypto.py
Expand Up @@ -141,7 +141,7 @@ def test_substitution_for_pyyaml():
It should also work with encrypted values, even if no key is passed
"""
assert load('some str') == 'some str'
with open('fixtures/test_substitution_for_pyyaml.yml', "r") as f:
with open('fixtures/test_substitution_for_pyyaml.yml') as f:
loaded_dict = load(f)
assert isinstance(loaded_dict['PASSWORD'], Encrypted)

Expand Down Expand Up @@ -187,7 +187,7 @@ def test_add_secret_to_yaml_file():
copyfile(yaml_file_fixture, yaml_file_to_append_to)

before_dict = None
with open(yaml_file_to_append_to, "r") as f:
with open(yaml_file_to_append_to) as f:
before_dict = load(f)

# Check for expected test data
Expand All @@ -198,7 +198,7 @@ def test_add_secret_to_yaml_file():
assert test_key_value not in before_dict
add_secret_to_yaml_file(test_key_value, test_key_value, public_key_output_filename, yaml_file_to_append_to)

with open(yaml_file_to_append_to, "r") as f:
with open(yaml_file_to_append_to) as f:
after_dict = load(f)
# Test the value was added
assert test_key_value in after_dict
Expand Down Expand Up @@ -237,7 +237,7 @@ def test_decrypt_yaml_file_and_write_encrypted_file_to_disk():
add_secret_to_yaml_file(test_key_value, test_key_value, public_key_output_filename, yaml_file_to_append_to)

after_dict = None
with open(yaml_file_to_append_to, "r") as f:
with open(yaml_file_to_append_to) as f:
after_dict = load(f, private_key_output_filename)

after_dict["A"] = "A"
Expand All @@ -263,7 +263,7 @@ def test_reencrypt_secrets_and_write_to_yaml_file():
reencrypt_secrets_and_write_to_yaml_file(input_yaml_file, private_key_file, public_key_output_filename_new)

before_dict = None
with open(yaml_file_fixture, "r") as f:
with open(yaml_file_fixture) as f:
before_dict = load(f)

# Check for expected test data
Expand All @@ -275,7 +275,7 @@ def test_reencrypt_secrets_and_write_to_yaml_file():
assert test_encrypted_key_value == "C"

after_dict = None
with open(input_yaml_file, "r") as f:
with open(input_yaml_file) as f:
after_dict = load(f)

# Test the expected test data was not modified, and is still present
Expand All @@ -300,7 +300,7 @@ def test_add_nested_secret_to_yaml_file():
copyfile(yaml_file_fixture, yaml_file_to_append_to)

before_dict = None
with open(yaml_file_to_append_to, "r") as f:
with open(yaml_file_to_append_to) as f:
before_dict = load(f)

# Check for expected test data
Expand All @@ -309,7 +309,7 @@ def test_add_nested_secret_to_yaml_file():

add_secret_to_yaml_file(nested_key, nested_value, public_key_output_filename, yaml_file_to_append_to)

with open(yaml_file_to_append_to, "r") as f:
with open(yaml_file_to_append_to) as f:
after_dict = load(f)

# Test the value is encrypted.
Expand Down
12 changes: 4 additions & 8 deletions tox.ini
@@ -1,13 +1,9 @@
# tox (https://tox.readthedocs.io/) is a tool for running tests
# in multiple virtualenvs. This configuration file will run the
# test suite on all supported python versions. To use it, "pip install tox"
# and then run "tox" from this directory.

[tox]
envlist = py36,py38
envlist = py38

[testenv]
changedir = tests
deps = -r requirements/development.txt
commands =
python -Wd -m pytest {posargs}
commands =
python -Wd -m pytest {posargs}

0 comments on commit 5f16bd3

Please sign in to comment.