What's the best way to reload python query module during development? - memgraphdb

I'm working on my first query module for Memgraph. I'm trying to find the best approach.
I have a query module that depends on a local submodule (firstone):
import firstone
import mgp
import importlib
#mgp.read_proc
def procedure(context...):
importlib.reload(firstone)
firstone.call()
If I get it correctly, if firstone module changes, the procedure is still using the previous code. How can I reload the Python query module during development?

You can use the use mg.load to load or reload the given module. The correct syntax is CALL mg.load("py_example");. After loading the module, all dependent Python's submodules that are imported will also be reloaded. The official documentation can be found on Memgraph site.

Related

Why do I get the error "ModuleNotFoundError: No module named 'huggan'"?

I am trying to implement this model from HuggingFace🤗. To run the model I need to import HugGANModelHubMixin with:
from huggan.pytorch.huggan_mixin import HugGANModelHubMixin
but I get:
ModuleNotFoundError: No module named 'huggan'.
I cloned the model locally and try to run it from VSC.
As far I understand is the problem that HugGANModelHubMixin is not available on HuggingFace because search for models returns no results.
How can I find a work around for this issue?

Is there any efficiency issue in duplicated importing in vue.js

I do refactoring some vue code And find duplication like below;
- main.ts
import BootstrapVue from 'bootstrap-vuew';
Vue.use(BootstrapVue);
I know that if main.ts do 'import bootstrap-vue' then other vue file use bootstrap component without importing.
But my co-worker do this meaningless imporing on every vue component.
So i Wonder that is this duplication has any critical efficiency issue?
If yes, it related to velocity of rendering?
Imports themselves aren't a problem. A module is evaluated and included into a bundle only once. It's discarded in production build if imported values aren't used in modules that import them.
It's Vue.use that makes it different. Imported plugin won't be discarded because it's used. A plugin can do side effects that should be applied only once and should have a safeguard against multiple installation. The plugin in question has such safeguard, so this introduces no problems except several bytes of unnecessary code per module.
The necessity of this is doubtful. Vue plugins affect global application behaviour. Vue.use needs to be used only once per plugin, this is commonly done in entry point, but can be done in feature modules as well, the latter can specify their own plugin dependencies for decoupling purposes. It doesn't make sense to use Vue.use in each module where library components are used. Instead they can import components per need basis, this allows to not include the whole library, considering that there's no plugin installation anywhere in the application.
So it's either installing a plugin once or several times globally per application or feature module:
import BootstrapVue from 'bootstrap-vue';
Vue.use(BootstrapVue)
Or using a subset of library locally as many times as needed:
import { DropdownPlugin } from 'bootstrap-vue';
Vue.use(DropdownPlugin)
And/or importing all used components locally as many times as needed:
import { BDropdown, BDropdownItem, ... } from 'bootstrap-vue';
export default {
components: {
BDropdown, BDropdownItem, ...
}
}
It always depends on a library if it's supposed to be used one way or another.
Importing a library in global "main.ts" enough to use in any component throughout the application. But importing multiple times in all components can cause large size build file. So, it's better to use only one import of the library in "main.ts".

How to make graphql work on ObservableHQ?

I am using observablehq for playing around with the graphql js library.
However, I fail at importing it and observable complains about this module.
Any hint? Do we need to modify the library to make it observable friendly?
Observable has a Module require debugger for these situations; given a module name, it can often find a way to make it work. E.g., for GraphQL, it suggests using Skypack, which works for me in a notebook:
graphql = import('https://cdn.skypack.dev/graphql#15.4.0')

Workflow for Google Cloud Functions with Golang

When developing a small Google Cloud Function in Go. I noticed it will throw an error if you have everything in your package main - eg. import "<whatever>" is a program, not an importable package
So the solution is switch it out to its own package, then deploy. If something goes wrong, throw it back into a package main and work on it locally, then switch it back.
Is this the best workflow? The other option i see is possibly making the Cloud Function its own module and importing it into a main.go file.
I was able to create a cli folder in project's top level and then put main.go file using package main and main() function inside it. That allowed me to have separate file cloud_functions.go in root with different package name that has one or more google cloud functions in it.

Get post save event in Odoo

I want to execute a function after some record is saved in the database (something like Signals in Django).
I have tried using Odoo Connector but with no success. connector module is not present in openerp.addons package by default and I could not find a good resource to understand how to install it.
How can I execute a function every time a new record is saved?
I solved it myself.
I manually copied connector module from github to /usr/lib/python2.7/dist-packages/openerp/addons (to make sure it's in my IDE's libraries' path).
Installed the connector from Settings -> Local Modules.
Used the following code (can be anywhere, even in __init__.py of your module)
#on_record_create(model_names=['res.users', 'res.partner'])
#on_record_write(model_names=['res.users', 'res.partner'])
def delay_export(session, model_name, record_id, vals):
"""
Do some real work here.
"""
import ipdb; ipdb.set_trace()
The above code is based on odoo-connector.

Resources