Skip to content

Commit

Permalink
fix depreciation warning on log.warn and move from simplejson to json
Browse files Browse the repository at this point in the history
  • Loading branch information
jharshman committed Jan 16, 2024
1 parent e4cf392 commit d83b0db
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 34 deletions.
2 changes: 1 addition & 1 deletion assetman/S3UploadThread.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def replacer(match):
replacement_link = prefix.rstrip('/') + '/' + versioned_path.lstrip('/')
logging.info('replacing %s -> %s', path, replacement_link)
return replacement_link
logging.warn('Missing path %s in manifest, using %s', path, match.group(0))
logging.warning('Missing path %s in manifest, using %s', path, match.group(0))
return match.group(0)
pattern = get_static_pattern(static_url_prefix)
return re.sub(pattern, replacer, src)
4 changes: 2 additions & 2 deletions assetman/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from assetman.manifest import Manifest

# also update in setup.py
__version__ = "0.2.0"
version_info = (0, 2, 0)
__version__ = "0.3.0"
version_info = (0, 3, 0)
6 changes: 3 additions & 3 deletions assetman/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def iter_template_deps(static_dir, src_path, static_url_prefix):
if os.path.isfile(dep_path):
yield dep_path
else:
logging.warn('Missing dep %s (src: %s)', dep_path, src_path)
logging.warning('Missing dep %s (src: %s)', dep_path, src_path)

###############################################################################

Expand Down Expand Up @@ -294,7 +294,7 @@ def iter_static_deps(static_dir, src_path, static_url_prefix):
if os.path.isfile(dep_path):
yield dep_path
else:
logging.warn('Missing dep %s (src: %s)', dep_path, src_path)
logging.warning('Missing dep %s (src: %s)', dep_path, src_path)


def _build_manifest_helper(static_dir, src_paths, static_url_prefix, manifest):
Expand Down Expand Up @@ -390,7 +390,7 @@ def run(settings):
tornado_paths = list(iter_template_paths(settings['tornado_template_dirs'], settings['template_extension']))

if not tornado_paths:
logging.warn("No templates found")
logging.warning("No templates found")

# Load the current manifest and generate a new one
cached_manifest = Manifest(settings).load()
Expand Down
10 changes: 5 additions & 5 deletions assetman/compilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def run_proc(cmd, stdin=None):
if proc.returncode != 0:
raise CompileError(cmd, err)
elif err:
logging.warn('%s stderr:\n%s', cmd[0], err)
logging.warning('%s stderr:\n%s', cmd[0], err)
return out

class CompileError(Exception):
Expand Down Expand Up @@ -88,16 +88,16 @@ def needs_compile(self, cached_manifest, current_manifest):
if cached_manifest.blocks[name_hash]['version'] == content_hash:
compiled_path = self.get_compiled_path()
if not os.path.exists(compiled_path):
logging.warn('Missing compiled asset %s from %s',
logging.warning('Missing compiled asset %s from %s',
compiled_path, self)
return True
return False
else:
logging.warn('Contents of %s changed', self)
logging.warning('Contents of %s changed', self)
else:
compiled_path = self.get_compiled_path()
if not os.path.exists(compiled_path):
logging.warn('New/unknown hash %s from %s', name_hash, self)
logging.warning('New/unknown hash %s from %s', name_hash, self)
else:
logging.info('new hash %s from %s but already exists on file %s', name_hash, self, compiled_path)
return False
Expand Down Expand Up @@ -224,7 +224,7 @@ def replacer(match):

for url, count in seen_assets.items():
if count > 1:
logging.warn('inline asset duplicated %dx: %s', count, url)
logging.warning('inline asset duplicated %dx: %s', count, url)

return result

Expand Down
8 changes: 4 additions & 4 deletions assetman/manifest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


import os
import simplejson as json
import json
import logging

from assetman.settings import Settings
Expand Down Expand Up @@ -52,7 +52,7 @@ def load(self, compiled_asset_path=None):
assert isinstance(self.assets, dict)
assert isinstance(self.blocks, dict)
except (AssertionError, KeyError, IOError, json.JSONDecodeError) as e:
logging.warn('error opening manifest file: %s', e)
logging.warning('error opening manifest file: %s', e)
self._manifest = self.make_empty_manifest()

return self
Expand Down Expand Up @@ -102,11 +102,11 @@ def assets_in_sync(asset):
logging.info('new asset %s (not in current manifest)', asset)
return False
if self.assets[asset]['version'] != newer_manifest.assets[asset]['version']:
logging.warn('Static asset %s version mismatch', asset)
logging.warning('Static asset %s version mismatch', asset)
return False
return True
assets_out_of_sync = not all(map(assets_in_sync, newer_manifest.assets))
if assets_out_of_sync:
logging.warn('Static assets out of sync')
logging.warning('Static assets out of sync')
return assets_out_of_sync

5 changes: 1 addition & 4 deletions assetman/settings.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@


import os
try:
import json
except ImportError:
import simplejson as json # pyflakes.ignore
import json

example_settings = {
# Assetman needs to be able to point at assets to be served by us and by a
Expand Down
1 change: 1 addition & 0 deletions assetman/tests/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def get_settings(**opts):
sass_compiler=opts.get("sass_compiler", "/bitly/local/bin/sass"),
lessc_path=opts.get("lessc_path", "/bitly/local/hamburger/node_modules/.bin/lessc"), # lessc is included as a node module in hamburger. Does not exist in /bitly/local/bin/
aws_username=None,
java_bin="java",
)
return assetman_settings

Expand Down
2 changes: 1 addition & 1 deletion assetman/tests/test_manifest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import os
import unittest
import simplejson as json
import json

from assetman.manifest import Manifest
from assetman.settings import Settings
Expand Down
5 changes: 3 additions & 2 deletions assetman/tests/test_settings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


import unittest
import simplejson as json
import json

from assetman.settings import Settings

Expand All @@ -13,7 +13,8 @@ def test_settings_can_load_from_file(self):
"lessc_path" : "asdf",
"sass_compiler": "asdf",
"minify_compressor_path": "asdf",
"closure_compiler": "asdf"
"closure_compiler": "asdf",
"java_bin": "asdf"
}

savepath = "./assetman/tests/test_settings"
Expand Down
6 changes: 0 additions & 6 deletions assetman/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ def _utf8(s):
return s.decode("utf-8")
assert isinstance(s, str), "_utf8 expected a str, not %r" % type(s)
return s
#def _utf8(s):
# """encode a unicode string as utf-8"""
# if isinstance(s, str):
# return s.encode("utf-8")
# assert isinstance(s, str), "_utf8 expected a str, not %r" % type(s)
# return s

def iter_template_paths(template_dirs, template_ext):
"""Walks each directory in the given list of template directories,
Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
aadict==0.2.3
asgiref==3.7.2
asset==0.6.13
boto3==1.34.15
botocore==1.34.15
Django==4.2.9
exceptiongroup==1.2.0
globre==0.1.5
iniconfig==2.0.0
jmespath==1.0.1
packaging==23.2
pluggy==1.3.0
pytest==7.4.4
python-dateutil==2.8.2
s3transfer==0.10.0
simplejson==3.19.2
six==1.16.0
sqlparse==0.4.4
tomli==2.0.1
Expand Down
7 changes: 2 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@
author_email="wm@bit.ly",
maintainer="Jehiah Czebotar",
maintainer_email="jehiah@gmail.com",
packages=['assetman', 'assetman/parsers', 'assetman/tornadoutils', 'assetman/django_assetman',
'assetman/django_assetman/templatetags'],
install_requires=['simplejson',
'multiprocessing',
],
packages=['assetman', 'assetman/parsers', 'assetman/tornadoutils'],
install_requires=['multiprocessing'],
classifiers = [
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
Expand Down

0 comments on commit d83b0db

Please sign in to comment.