Skip to content

Commit

Permalink
Fix UTF-8 encoding issue (#900)
Browse files Browse the repository at this point in the history
* Force UTF-8 generation.

* Rebuilt UTF-8 clean.

* Force reading in utf-8.
  • Loading branch information
emeryberger authored Jan 12, 2025
1 parent ff76178 commit b810460
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 20 deletions.
1 change: 1 addition & 0 deletions scalene/scalene-gui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"process": "^0.11.10",
"stream-browserify": "^3.0.0",
"stream-http": "^3.2.0",
"terser-webpack-plugin": "^5.3.11",
"url": "^0.11.4",
"util": "^0.12.5",
"webpack": "^5.96.1",
Expand Down
3 changes: 2 additions & 1 deletion scalene/scalene-gui/scalene-gui-bundle.js

Large diffs are not rendered by default.

48 changes: 31 additions & 17 deletions scalene/scalene-gui/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const path = require('path');
const webpack = require('webpack');
const TerserPlugin = require('terser-webpack-plugin');

module.exports = {
entry: './scalene-gui.js',
Expand All @@ -11,30 +12,43 @@ module.exports = {
},
resolve: {
fallback: {
"crypto": require.resolve("crypto-browserify"),
"stream": require.resolve("stream-browserify"),
"buffer": require.resolve("buffer"),
"util": require.resolve("util"),
"assert": require.resolve("assert"),
"os": require.resolve("os-browserify/browser"),
"http": require.resolve("stream-http"),
"https": require.resolve("https-browserify"),
"url": require.resolve("url/"),
"zlib": require.resolve("browserify-zlib"),
"path": require.resolve("path-browserify"),
"fs": false,
crypto: require.resolve('crypto-browserify'),
stream: require.resolve('stream-browserify'),
buffer: require.resolve('buffer'),
util: require.resolve('util'),
assert: require.resolve('assert'),
os: require.resolve('os-browserify/browser'),
http: require.resolve('stream-http'),
https: require.resolve('https-browserify'),
url: require.resolve('url/'),
zlib: require.resolve('browserify-zlib'),
path: require.resolve('path-browserify'),
fs: false,
},
},
plugins: [
new webpack.ProvidePlugin({
process: 'process/browser',
}),
new webpack.DefinePlugin({
'process.env.LANG': JSON.stringify('en_US.UTF-8'),
}),
],
optimization: {
minimize: true, // Enable minimization
usedExports: false, // Disable tree shaking
sideEffects: false, // Include all files, assuming they have side effects
concatenateModules: false, // Disable module concatenation (scope hoisting)
innerGraph: false, // Disable inner graph analysis
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
output: {
ascii_only: true, // Escape non-ASCII characters
},
},
}),
],
usedExports: false,
sideEffects: false,
concatenateModules: false,
innerGraph: false,
},
devtool: 'source-map', // Enable debugging via source maps
};
18 changes: 16 additions & 2 deletions scalene/scalene_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,26 @@ def read_file_content(
directory: str, subdirectory: str, filename: str
) -> str:
file_path = os.path.join(directory, subdirectory, filename)
return pathlib.Path(file_path).read_text()
file_content = ""
try:
file_content = pathlib.Path(file_path).read_text(encoding="utf-8")
except UnicodeDecodeError as e:
raise UnicodeDecodeError(
f"Failed to decode file {file_path}. Ensure the file is UTF-8 encoded."
) from e
return file_content

try:
# Load the profile
profile_file = pathlib.Path(profile_fname)
profile = profile_file.read_text()
profile = ""
try:
profile = profile_file.read_text(encoding="utf-8")
except UnicodeDecodeError as e:
raise UnicodeDecodeError(
f"Failed to decode file {profile_file}. Ensure the file is UTF-8 encoded."
) from e

except FileNotFoundError:
assert profile_fname == "demo"
profile = ""
Expand Down

0 comments on commit b810460

Please sign in to comment.