Repo Init.

This commit is contained in:
SL
2024-04-25 09:12:48 +08:00
commit ee5002dbb5
3583 changed files with 348959 additions and 0 deletions
@@ -0,0 +1,45 @@
# -----------------------------------------------------------------------------
# Copyright (c) 2015-2020, PyInstaller Development Team.
#
# Distributed under the terms of the GNU General Public License (version 2
# or later) with exception for distributing the bootloader.
#
# The full license is in the file COPYING.txt, distributed with this software.
#
# SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
# -----------------------------------------------------------------------------
from inspect import getmembers, isfunction
from functools import partial
import boto
import boto.exception
credentials = dict(
aws_access_key_id='ASIAIH3F2FU3T63KIXKA',
aws_secret_access_key='lnN4qk1a0SuQAFVsGA+Y+ujo2/5rLq2j+a1O4Vuy')
# connect_cloudsearchdomain is broken in boto; the rest require custom params
skip = {
'connect_cloudsearchdomain',
'connect_ec2_endpoint',
'connect_gs',
'connect_euca',
'connect_ia',
'connect_walrus',
}
connect_funcs = [
func for name, func in getmembers(boto)
if isfunction(func) and name.startswith('connect_') and name not in skip
]
connect_funcs += [
partial(boto.connect_ec2_endpoint, 'https://ec2.amazonaws.com',
**credentials),
partial(boto.connect_gs, gs_access_key_id='', gs_secret_access_key=''),
partial(boto.connect_euca, host=None, **credentials),
partial(boto.connect_ia, ia_access_key_id='', ia_secret_access_key=''),
partial(boto.connect_walrus, host='s3.amazonaws.com', **credentials),
]
for connect_func in connect_funcs:
if isfunction(connect_func):
connect_func(**credentials)
else:
connect_func()
@@ -0,0 +1,43 @@
# -----------------------------------------------------------------------------
# Copyright (c) 2005-2020, PyInstaller Development Team.
#
# Distributed under the terms of the GNU General Public License (version 2
# or later) with exception for distributing the bootloader.
#
# The full license is in the file COPYING.txt, distributed with this software.
#
# SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
# -----------------------------------------------------------------------------
# Enchant hook test. Tested with PyEnchant 1.6.6.
import sys
import enchant
print(80 * '-')
print('PYTHONPATH: %s' % sys.path)
# At least one backend should be available
backends = [x.name for x in enchant.Broker().describe()]
if len(backends) < 1:
raise SystemExit('Error: No dictionary backend available')
print(80 * '-')
print('Backends: ' + ', '.join(backends))
# Usually en_US dictionary should be bundled.
languages = enchant.list_languages()
dicts = [x[0] for x in enchant.list_dicts()]
if len(dicts) < 1:
raise SystemExit('No dictionary available')
print(80 * '-')
print('Languages: %s' % ', '.join(languages))
print('Dictionaries: %s' % dicts)
print(80 * '-')
# Try spell checking if English is availale
language = 'en_US'
if language in languages:
d = enchant.Dict(language)
print('d.check("hallo") %s' % d.check('hallo'))
print('d.check("halllo") %s' % d.check('halllo'))
print('d.suggest("halllo") %s' % d.suggest('halllo'))
@@ -0,0 +1,54 @@
# -----------------------------------------------------------------------------
# Copyright (c) 2014-2020, PyInstaller Development Team.
#
# Distributed under the terms of the GNU General Public License (version 2
# or later) with exception for distributing the bootloader.
#
# The full license is in the file COPYING.txt, distributed with this software.
#
# SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
# -----------------------------------------------------------------------------
import os
fnames_to_track = [
'lextab.py',
'yacctab.py',
]
def fnames_found():
return [fname for fname in fnames_to_track if os.path.isfile(fname)]
if __name__ == '__main__':
# Confirm no files exist before we start.
if fnames_found():
raise SystemExit('FAIL: Files present before test.')
# Minimal invocation that generates the files.
from pycparser import c_parser
parser = c_parser.CParser()
# Were the files generated?
fnames_generated = fnames_found()
# Try to remove them, if so.
for fname in fnames_generated:
try:
os.unlink(fname)
except OSError:
pass
# Did we fail at deleting any file?
fnames_left = fnames_found()
# Fail if any file was generated.
if fnames_generated:
if fnames_left:
raise SystemExit('FAIL: Files generated and not removed.')
else:
raise SystemExit('FAIL: Files generated but removed.')
# Success.
@@ -0,0 +1,36 @@
# ------------------------------------------------------------------
# Copyright (c) 2020 PyInstaller Development Team.
#
# This file is distributed under the terms of the GNU General Public
# License (version 2.0 or later).
#
# The full license is available in LICENSE.GPL.txt, distributed with
# this software.
#
# SPDX-License-Identifier: GPL-2.0-or-later
# ------------------------------------------------------------------
import os
# Force CPU
os.environ['CUDA_VISIBLE_DEVICES'] = '-1'
# Display only warnings and errors
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
# Begin test - import tensorflow after environment variables are set
import tensorflow as tf # noqa: E402
# Input data: batch of four 28x28x3 images
input_shape = (4, 28, 28, 3)
x = tf.random.normal(input_shape)
# Convolution with 3x3 kernel, two output filters
y = tf.keras.layers.Conv2D(
2,
(3, 3),
activation='relu',
input_shape=input_shape[1:]
)(x)
assert y.shape == (4, 26, 26, 2), "Unexpected output shape!"
@@ -0,0 +1,66 @@
# ------------------------------------------------------------------
# Copyright (c) 2020 PyInstaller Development Team.
#
# This file is distributed under the terms of the GNU General Public
# License (version 2.0 or later).
#
# The full license is available in LICENSE.GPL.txt, distributed with
# this software.
#
# SPDX-License-Identifier: GPL-2.0-or-later
# ------------------------------------------------------------------
import sys
import os
# Force CPU
os.environ['CUDA_VISIBLE_DEVICES'] = '-1'
# Display only warnings and errors
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
# tensorflow 2.16 and keras 3.0 upgraded the interactive progress bar (displayed during dataset download, during model
# fitting, etc.) with fancier version that uses Unicode arrows (←). For this to work, `sys.stdout` must be using utf-8
# encoding. As per https://docs.python.org/3/library/sys.html#sys.stdout, on Windows, python defaults to using utf-8
# for the console device. However, non-character devices such as pipes use the system locale encoding (i.e. the ANSI
# codepage). PyInstaller's `pyi_builder` test fixture runs the build executable via `subprocess.Popen` with stdout
# and stderr redirected to pipes, so the embedded interpreter in the frozen test application ends up using system
# locale encoding (e.g., cp1252) instead of utf-8 for `sys.stdout` and `sys.stderr`. In contrast to unfrozen python,
# the encoding cannot be overridden by the calling process via `PYTHONIOENCODING` environment variable when starting
# the application (sub)process. However, we can reconfigure the encoding on the stream objects here, in the application
# itself. Which, everything considered, is the sanest place to do so.
if sys.stdout.encoding != 'utf8':
sys.stdout.reconfigure(encoding='utf-8')
if sys.stderr.encoding != 'utf8':
sys.stderr.reconfigure(encoding='utf-8')
# Begin test - import tensorflow after environment variables are set
import tensorflow as tf # noqa: E402
# Load and normalize the dataset
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
# Define model...
model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(input_shape=(28, 28)),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Dense(10)
])
# ... and loss function
loss_fn = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)
# Train
model.compile(optimizer='adam', loss=loss_fn, metrics=['accuracy'])
model.fit(x_train, y_train, epochs=1, verbose=1)
# Evaluate
results = model.evaluate(x_test, y_test, verbose=1)
# Expected accuracy after a single epoch is around 95%, so use 90%
# as a passing bar
assert results[1] >= 0.90, "Resulting accuracy on validation set too low!"