In my local package, there is a tree of modules, like this:
# source/main.py
from source import worker
def run():
return worker.func()
# source/worker.py
def func():
return 'hello'
I want to demonstrate this package with PyScript (before my package needs to be installed), but do not want to rewrite the whole package for the sake of PyScript. This "index.htm" calls the main.run(). It is OK until the main wants to import the worker module so that it can call its func().
<head>
..
<py-env>
paths:
- source/main.py
- source/worker.py
</py-env>
</head>
<body>
<py-script>
import main
main.run()
</py-script>
</body>
The "import worker" would work, but as I stated above, it is "from source import worker" and cannot be changed just to make it work in PyScript.
Could I define somehow that the root for the local module imports is above "source", and imports like "import source.module.py" should work?
It is not possible to do
from source import worker
because source is not a module, it is a folder. Pyscript is not same as python. The whole context is different. There is no need for it also. You can have it all together working and reachable if you declare nodes py-env and py-script like below.
index.html in application root folder:
<html>
<head>
<link rel="stylesheet" pyscript.css" />
<script defer src="pyscript.js"></script>
<!--<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js" onerror=scriptLoadFailure('pyscr ipt.js')></script> -->
<py-env>
paths:
./source/worker.py
./source/main.py
</py-env>
</head>
<body>
<py-script src="./source/worker.py"></py-script>
<py-script src="./source/main.py"></py-script>
</body>
</html>
The modules in py-env are declared with exactly 4 spaces indentation (no tab char) and starting from application root folder ( ./ ) folowed by subfolder and module. In body section both modules are declared as src attribute of py-script nodes. This way they are like unioned and operational without import one or other nor from one import something. You can just call the function from wherever you need to.
The modules are both in the source subfolder (though I prefer puting main in the app root along with index.html). There is just one change in main.py where I put the call of run() function for it was excluded from html.
Modules in ./source/ subfolder are
#
# source/main.py
def run():
return func()
run()
#
#
# source/worker.py
def func():
return 'hello'
Open it in browser and you'll see hello (tested with Chrome & Edge) meaning that run() command from main.py has called func() function from worker.py without importing anything.
And if you realy need to keep those imports all I can suggest is to do a replace of those imports to end up like below. It can be done with any editor and it will work both with python and pyscript.
try:
from source import worker
except:
pass
Regards...
Since the current PyScript does not do such, I created a patched version and proposed the PyScript project to pull it into a future version. See the ticket with my comment and the attached zip containing the solution:
Add Local Package Loading to Py-Env #519
Related
I have updated OpenUI5 of my project from 1.42.7 to 1.60.12 (LTS)
If I try to run the app with the new version, I have this error:
Uncaught Error: failed to load 'sap/ui/core/library.js' from resources/sap/ui/core/library.js: 404 - Not Found**
The tree structure of my project has OpenUI5 files into resources/openui path:
In index.html, I set src in this mode:
<script id="sap-ui-bootstrap"
src="resources/openui/sap-ui-core.js"
data-sap-ui-theme="sap_belize"
data-sap-ui-xx-bindingSyntax="complex"
data-sap-ui-libs="sap.m"
data-sap-ui-preload=""
data-sap-ui-resourceroots='{
"ui5bp": "./",
"model": "./model"
}'
></script>
It seems that the first call of sap-ui-core.js finishes correctly (from Webcontent/resources/openui) but then the call of library.js is called from Webcontent/resources/, not from Webcontent/resources/openui.
In 1.42 version, all works fine.
Note: if I try to retrieve OpenUI5 resources from CDN, all works fine...
src="https://openui5.hana.ondemand.com/1.60.12/resources/sap-ui-core.js"
Option 1 (recommended)
Move the UI5 resources to the resources folder directly underneath.
˅ 📂resources
˃ 📁openui
˅ 📂sap
˃ 📁base
˃ 📁f
˃ 📁m
...
...
sap-ui-core.js
According to the topic Bootstrapping: Loading and Initializing - Initialization Process, UI5 will try to fetch library resources from the following path by default:
Library bootstrap file /<context-path>/resources/<library-name>/library(-preload).js
Having a deviating path (/resources/openui/<library-name>/ in between) makes fetching the library files incompatible with default settings.
Option 2 (without changing the folder structure)
Define a new default base URL in index.html as early as possible. E.g. via the global configuration object:
<script>
window["sap-ui-config"] = {
resourceRoots: {
"": "./resources/openui/", // <-- new base URL
"ui5bp": "./",
// ...
},
libs: "sap.ui.core, sap.m",
async: true,
theme: "sap_belize",
compatVersion: "edge",
// ...
};
</script>
<script id="sap-ui-bootstrap" src="resources/openui/sap-ui-core.js"></script>
This one works too as resolving "" will always work as a fallback
Note that the empty prefix ("") will always match and thus serves as a fallback for any search. source
I've looked around and I'm sure this is common but can't seem to get the right answer.
I've just recently set up a Codeigniter 3 project on my localhost and a migrating some Codeigniter 2 code.
The index.php file is a bit different.
I can get the project up and running except the main folders references in the index.php file such as APPLICATION and others I've added like "ASSETS" etc are loading like this:
<link href="http://[::1]/projectOne/E:\public_html\projectOne\assets\css\style.php?1537317115" rel="stylesheet" type="text/css" >
Even when I set a base_url:
<link href="http://localhost/projectOne/E:\public_html\projectOne\assets\css\style.php?1537317115" rel="stylesheet" type="text/css" >
I've checked it wasn't just the folders I added by echoing out the APPPATH variable:
define('APPPATH', $application_folder.DIRECTORY_SEPARATOR);
echo APPPATH;
Which produces:
E:\public_html\projectOne\application\
What am I missing here?
How do I get my paths to folder set in the index.php to just use the project root, and not the whole filepath on the computer?
Figured it out. For anyone else that hits this issue.
This new part in CI3:
if (($_temp = realpath($application_folder)) !== FALSE)
{
$application_folder = $_temp;
}
Allows you to more securely/easily have your application folder outside of the website root.
My additional ASSETS folder was then showing the full web path which you obviously don't want.
So commenting out this part leaving only:
$application_folder = strtr(
rtrim($application_folder, '/\\'),
'/\\',
DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR
);
And then setting you base_url value in the config.php file gives your CSS, JS and IMAGES proper site relative paths.
In my directory I have:
shop.rb (App < Sinatra::Base)
lib directory - Ruby models inside
views directory - erb files inside
Gemfile
Where should I place my style.css ? I tried every place possible, I created public folder and tried with also every possible place, but my styles doesn't work.
In layout I have:
<link rel="stylesheet" href="/style.css"/>
I tried also with:
<link rel="stylesheet" href="style.css"/>
It might be because the app is not configured to find the public directory/ First make sure the public directory exists relative to the main entry file of your application (assuming shop.rb) and use the following configuration:
class Shop < Sinatra::Base
configure do
set :public_folder, File.expand_path('../public', __FILE__)
set :views , File.expand_path('../views', __FILE__)
set :root , File.dirname(__FILE__)
end
get '/' do
erb :index
end
end
Once set up, Sinatra should now know where to find your public directory and you can just include the asset file like this:
CSS:
<link rel="stylesheet" href="/style.css"/>
Image:
<img src="/img/background.png" alt="Image" />
JavaScript:
<script src="/js/main.js"></script>
I am using doxygen 1.8.9.1 and want to use AsciiMath in the hmtl output. It requires me to use a new config file, i.e. http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=AM_HTMLorMML. However, the configuration "MATHJAX_RELPATH" can only set the root path of mathjax.
How could I change the config to mathjax? Thanks for any suggestions.
EDIT:
I have tried to use MATHJAX_CODEFILE to change the config file "config: ["local/local.js","MMLtoHTML.js"]", but don't work for me. The URL should be modified, not just the configuration files. (i.e. MathJax.js?config=AM_HTMLorMML).
BTW: The render html should be change from \[sum_(i=1)^n i^3=((n*(n+1))/2)^2\] to `sum_(i=1)^n i^3=((n*(n+1))/2)^2`.
One solution is to modify MATHJAX section of footer.html in the Doxygen folder.
For example, use this to modify the url to MathJax.js?config=local/local.js
<!-- BEGIN MATHJAX-->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
jax: ["input/TeX","output/HTML-CSS"],
});
</script><script type="text/javascript" src="../mathjax/MathJax.js?config=local/local.js"></script>
<!-- END MATHJAX-->
The $mathjax line of header.html should also be deleted.
I have a dart application using Polymer.dart, i replace the dart.js file by the boot.js (in my index.html), an now i want to deploy this application in order to have a working javascript one.
But, when i launch the build.dart, i have :
Total time spent on web/index.html -- 504 ms
Total time -- 555 ms
but nothing is created, no more "out" folder.
And when I do Pub Deploy, it create a "deploy" folder, but that version is not working (because the build.dart doesn't properly work i think).
Have you any idea?
Right now, it's a two step process. I suspect this will get easier. In the meantime:
Create a build.dart that looks like this:
import 'package:polymer/builder.dart';
main() {
build(entryPoints: ['web/index.html'], options: parseOptions(['--deploy']));
}
Take note, currently, a lot of warnings and hints are produced. You can ignore them for right now.
For the current version i have done these steps :
type on your console:
dart build.dart --deploy
dart2js out/web/index.html_bootstrap.dart -oout/web/index.html_bootstrap.dart.js
index.html:
<!DOCTYPE html>
<html>
<head>
...
<link rel="import" href="clickcounter.html">
<script type="application/dart">export 'package:polymer/init.dart';</script>
<script src="packages/browser/dart.js"></script>
</head>
<body>
...
<div id="sample_container_id">
<click-counter count="5"></click-counter>
</div>
</body>
</html>
build.dart:
import 'package:polymer/builder.dart';
main(args) {
build(entryPoints: ['web/aaa.html'],
options: parseOptions(args));
}