2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-18 21:15:41 +00:00

pylint checks

This commit is contained in:
Matthias Mair
2024-08-20 00:26:32 +02:00
parent c197358ce4
commit 8a163237ac
24 changed files with 54 additions and 46 deletions

View File

@ -131,7 +131,7 @@ def load_config_data(set_cache: bool = False) -> map:
cfg_file = get_config_file()
with open(cfg_file) as cfg:
with open(cfg_file, encoding='utf-8') as cfg:
data = yaml.safe_load(cfg)
# Set the cache if requested

View File

@ -47,7 +47,7 @@ class Command(BaseCommand):
filename = kwargs.get('filename', 'inventree_settings.json')
with open(filename, 'w') as f:
with open(filename, 'w', encoding='utf-8') as f:
json.dump(settings, f, indent=4)
print(f"Exported InvenTree settings definitions to '{filename}'")

View File

@ -103,14 +103,14 @@ class Command(BaseCommand):
})
self.stdout.write(f'Writing icon map for {len(icons.keys())} icons')
with open(kwargs['output_file'], 'w') as f:
with open(kwargs['output_file'], 'w', encoding='utf-8') as f:
json.dump(icons, f, indent=2)
self.stdout.write(f'Icon map written to {kwargs["output_file"]}')
# Import icon map file
if kwargs['input_file']:
with open(kwargs['input_file']) as f:
with open(kwargs['input_file'], encoding='utf-8') as f:
icons = json.load(f)
self.stdout.write(f'Loaded icon map for {len(icons.keys())} icons')

View File

@ -19,7 +19,9 @@ def render_file(file_name, source, target, locales, ctx):
target_file = os.path.join(target, locale + '.' + file_name)
with open(target_file, 'w') as localised_file, lang_over(locale):
with open(target_file, 'w', encoding='utf-8') as localised_file, lang_over(
locale
):
rendered = render_to_string(os.path.join(source, file_name), ctx)
localised_file.write(rendered)

View File

@ -70,7 +70,7 @@ class URLTest(TestCase):
pattern = '{% url [\'"]([^\'"]+)[\'"]([^%]*)%}'
with open(input_file) as f:
with open(input_file, encoding='utf-8') as f:
data = f.read()
results = re.findall(pattern, data)

View File

@ -15,7 +15,7 @@ def reload_translation_stats():
STATS_FILE = settings.BASE_DIR.joinpath('InvenTree/locale_stats.json').absolute()
try:
with open(STATS_FILE) as f:
with open(STATS_FILE, encoding='utf-8') as f:
_translation_stats = json.load(f)
except Exception:
_translation_stats = None

View File

@ -55,7 +55,7 @@ def get_icon_packs():
tabler_icons_path = Path(__file__).parent.parent.joinpath(
'InvenTree/static/tabler-icons/icons.json'
)
with open(tabler_icons_path) as tabler_icons_file:
with open(tabler_icons_path, encoding='utf-8') as tabler_icons_file:
tabler_icons = json.load(tabler_icons_file)
icon_packs = [

View File

@ -2060,7 +2060,7 @@ class InvenTreeSetting(BaseInvenTreeSetting):
'description': _(
'Check that all plugins are installed on startup - enable in container environments'
),
'default': str(os.getenv('INVENTREE_DOCKER', False)).lower()
'default': str(os.getenv('INVENTREE_DOCKER', 'False')).lower()
in ['1', 'true'],
'validator': bool,
'requires_restart': True,

View File

@ -5,4 +5,4 @@ from django import template
register = template.Library()
from generic.states.tags import status_label
__all__ = [status_label]
__all__ = ['status_label']

View File

@ -19,7 +19,7 @@ class ImporterTest(InvenTreeTestCase):
fn = os.path.join(os.path.dirname(__file__), 'test_data', 'companies.csv')
with open(fn) as input_file:
with open(fn, encoding='utf-8') as input_file:
data = input_file.read()
session = DataImportSession.objects.create(

View File

@ -1618,7 +1618,7 @@ class PartDetailTests(PartAPITestBase):
# Try to upload a non-image file
test_path = BASE_DIR / '_testfolder' / 'dummy_image'
with open(f'{test_path}.txt', 'w') as dummy_image:
with open(f'{test_path}.txt', 'w', encoding='utf-8') as dummy_image:
dummy_image.write('hello world')
with open(f'{test_path}.txt', 'rb') as dummy_image:

View File

@ -49,7 +49,7 @@ class BomExportTest(InvenTreeTestCase):
with open(filename, 'wb') as f:
f.write(response.getvalue())
with open(filename) as f:
with open(filename, encoding='utf-8') as f:
reader = csv.reader(f, delimiter=',')
for line in reader:
@ -96,7 +96,7 @@ class BomExportTest(InvenTreeTestCase):
f.write(response.getvalue())
# Read the file
with open(filename) as f:
with open(filename, encoding='utf-8') as f:
reader = csv.reader(f, delimiter=',')
for line in reader:

View File

@ -7,7 +7,7 @@ import sys
def calculate_coverage(filename):
"""Calculate translation coverage for a .po file."""
with open(filename) as f:
with open(filename, encoding='utf-8') as f:
lines = f.readlines()
lines_count = 0
@ -72,7 +72,7 @@ if __name__ == '__main__':
print('-' * 16)
# write locale stats
with open(STAT_FILE, 'w') as target:
with open(STAT_FILE, 'w', encoding='utf-8') as target:
json.dump(locales_perc, target)
avg = int(sum(percentages) / len(percentages)) if len(percentages) > 0 else 0

View File

@ -45,7 +45,8 @@ if __name__ == '__main__':
print('Generating icon list...')
with open(
os.path.join(TMP_FOLDER, 'node_modules', '@tabler', 'icons', 'icons.json')
os.path.join(TMP_FOLDER, 'node_modules', '@tabler', 'icons', 'icons.json'),
encoding='utf-8',
) as f:
icons = json.load(f)
@ -60,7 +61,7 @@ if __name__ == '__main__':
},
}
with open(os.path.join(STATIC_FOLDER, 'icons.json'), 'w') as f:
with open(os.path.join(STATIC_FOLDER, 'icons.json'), 'w', encoding='utf-8') as f:
json.dump(res, f, separators=(',', ':'))
print('Cleaning up...')

View File

@ -41,7 +41,7 @@ from InvenTree.fields import InvenTreeModelMoneyField, InvenTreeURLField
from order.status_codes import SalesOrderStatusGroups
from part import models as PartModels
from plugin.events import trigger_event
from stock import models as StockModels
from stock import models as StockModels # noqa: PLW0406
from stock.generators import generate_batch_code
from stock.status_codes import StockHistoryCode, StockStatus, StockStatusGroups
from users.models import Owner

View File

@ -38,7 +38,7 @@ class TemplateTagTest(InvenTreeTestCase):
manifest_file = Path(__file__).parent.joinpath('static/web/.vite/manifest.json')
# Try with removed manifest file
manifest_file.rename(manifest_file.with_suffix('.json.bak')) # Rename
resp = resp = spa_helper.spa_bundle()
resp = spa_helper.spa_bundle()
self.assertIsNone(resp)
manifest_file.with_suffix('.json.bak').rename(
manifest_file.with_suffix('.json')