Node(#babel/preset-env) stoped spreading variables while importing - babeljs

Code is written using ES modules, compiled by #babel using #babel/preset-env with too simple config. It stopped spreading variables from a module. It sets every variable by the module value that contains all variables.
It occurred while debugging in VSCode.
For an example:
Trying to import a variable from a module.
import { env } from './src/utils/config';
env contains the following data.
{env: 'Hello, from b!', __esModule: true}
It has to be equal to 'Hello, from b!' only.
I tried WebStorm. it shows that all variables are undefined. But during execution drew the right values...
I did not configure source maps at all. But it leaps line by line correctly.

Related

Why isn't info popping up when the mouse hovers over a function in a package

When the mouse pointer hovers over the name of a function created in my code a box pops up in the editor with information about that function. However, if the function is in a package nothing happens. For example, if the mouse pointer hovers over the word "DataFrame" in the second line of the code below no box with info pops up. This is not specific to package DataFrames.
using DataFrames
DataFrame(:A => [0])
In VSCode Settings the following is set:
Editor > Hover:Delay
200
Editor > Hover:Enabled
Checked
The IDE is Visual Studio Code version 1.71.2 and the OS is Windows 11. The programming language is Julia, version 1.8.1.
It used to work, something changed, I do not know what.
Any hints on why this is happening?
I believe I found the solution. I created a function that adds a package to the environment. It has the package name as its single argument.
function load_package(package_name::String; used = true, report = true)
str_ui = used ? "Using " : "Importing "
report && println(str_ui * "package $package_name")
if used
eval(Meta.parse("using $package_name"))
end
eval(Meta.parse("import $package_name"))
end
It works fine. The package is loaded. For example,
load_package("DataFrames")
does (almost) the same thing as
using DataFrames
The only difference is that Visual Code does not seem to notice that the package was loaded when the package is loaded with the loaded_package function but it does notice it when the package is loaded with the using command.
So to fix the problem I had to load my packages with using and import comands. After doing that the tooltips became visible upon hovering over the function names.
The reason I was using the function load_packages was to load sets of packages whose names were in string vectors.

Configure the backend of Ipython to use retina display mode with code

I am using code to configure Jupyter notebooks because I have a repo with plenty of notebooks and want to keep style consistency across all without having to write lengthy setting at the start of each. This way, what I do is having a method to configure the CSS, one to set up Matplotlib and one to configure Ipython.
The reasons I configure my notebooks this way rather than relying on a configuration file as per docs are two:
I am sharing this repo of notebooks publicly and I want all my configs to be visible
I want to keep these configs specific to just this repo I'm creating
As an example, the method to set the CSS looks like
def set_css_style(css_file_path='../styles_files/custom.css'):
styles = open(css_file_path, "r").read()
return HTML(styles)
and I call it at the start of each notebook with set_css_style(). Similarly, I have this method to configure the specifics of Ipython:
def config_ipython():
InteractiveShell.ast_node_interactivity = "all"
Both the above use imports
from IPython.core.display import HTML
from IPython.core.interactiveshell import InteractiveShell
At the moment, as can be seen, the method to configure Ipython only contains the instruction to make it so that when I type the name of variables in multiple lines in a cell I don't need to add a print to make them all be printed.
My question is how to transform the Jupyter magic command to obtain retina-display quality for figures into code. Such command is
%config InlineBackend.figure_format = 'retina'
From the docs of Ipython I can't find how to call this instruction in a method, namely can't find where InlineBackend lives.
I'd just like to add this configuration line to my config_ipython method above, is it possible?
There is a Python API for this:
from IPython.display import set_matplotlib_formats
set_matplotlib_formats('retina')

What is the full command for gdal_calc in ipython?

I've been trying to use raster calculation in ipython for a tif file I have uploaded, but I'm unable to find the whole code for the function. I keep finding examples such as below, but am unsure how to use this.
gdal_calc.py -A input.tif --outfile=result.tif --calc="A*(A>0)" --NoDataValue=0
I then tried another process by assigning sections, however this still doesn't work (code below)
a = '/iPythonData/cstone/prec_7.tif'
outfile = '/iPythonData/cstone/prec_result.tif'
expr = 'A<125'
gdal_calc.py -A=a --outfile=outfile --calc='expr' --NoDataValue=0
It keeps coming up with can't assign to operator. Can someone please help with the whole code.
Looking at the source code for gdal_calc.py, the file is only about 300 lines. Here is a link to that file.
https://raw.githubusercontent.com/OSGeo/gdal/trunk/gdal/swig/python/scripts/gdal_calc.py
The punchline is that they just create an OptionParser object in main and pass it to the doit() method (Line 63). You could generate the same OptionParser instance based on the same arguments you pass to it via the command-line and call their doit method directly.
That said, a system call is perfectly valid per #thomas-k. This is only if you really want to stay in the Python environment.

Issue with a topjson object in a Meteor app built with coffeescript

Apologies for the lack of precision in the question, but I'm not completely sure which of possibly many things I'm doing wrong here.
I'm relatively new to Coffeescript and also geo applications in general, but here goes:
I've got a working (simple) Meteor (.7.0.1) application utilizing coffeescript in both client and server. The issue I'm having occurs when attempting to utilize TopoJSON encoded files to create a layer of US congressional districts. (the purpose of the app is to help highlight voter suppression in the US)
So, a few things: Typically in a non-Meteor app, I would just load the topoJSON file like so:
$.getJSON('./data/us-congress-113.json', function (data) {
var congress_geojson = topojson.feature(data, data.objects.districts);
congress_layer.addData(congress_geojson);
});
Now of course this won't work in Meteor because its not asynchronous.
One of the things that was recommended here on SO was to not worry about reading the file, and to instead change the json file to .js, and then set the contents (which are of course just an object) equal to a variable.
Here's what I did:
First, I changed the .json file to a .js file in the server directory, and added the "congress =" to the beginning of the file. It's a huge file so forgive me for omitting the whole object.
congress = {"type":"Topology",
"objects":
{"districts":
{"type":"GeometryCollection","geometries":[{"type":"Polygon"
Now here's where everything starts to give me issues:
In the server.coffee, I've created a variable like so to reference the congress object:
#congress_geojson = topojson.feature(congress, congress.objects.districts)
Notice how I'm putting the # symbol there? I've been told this allows a variable in Coffeescript to be globally scoped? I tried to also use a Meteor feature called "share" where I declare the variable as "share.congress_geojson". That led to the same issues which I will describe below.
Now in the client.coffee file, I'm trying to call this variable to load into a Leaflet map.
congress_layer = L.geoJson(null,
style:
color: "#DE0404"
weight: 2
opacity: 0.4
fillOpacity: 0.1
)
congress_layer.addData(#congress_geojson)
This isn't working, and specifically (despite attempts to find other ways, the errors I'm getting in the console are:
Exception from Deps afterFlush function: TypeError: Cannot read property 'features' of undefined
at o.GeoJSON.o.FeatureGroup.extend.addData (http://localhost:3000/packages/leaflet.js?ad7b569067d1f68c7403ea1c89a172b4cfd68d85:39:16471)
at Object.Template.map.rendered (http://localhost:3000/client/client.coffee.js?37b1cdc5945f3407f2726a5719e1459f44d1db2d:213:18)
I have no doubt that I'm missing something stupidly obvious here. Any suggestions or tips for what I'm doing completely wrong would be appreciated. Is it a case where an object globally declared in a .js file isn't available to code in a .coffee file? Maybe I'm doing something wrong on the Meteor side?
Thanks!
Edit:
So I was able to get things working by putting the .js file containing the congress object in a root /lib folder, causing the object to load first, and then calling the congress object from the client. However, I'm still wanting to know how I could simply share this object from the server? What is the "Meteor way" here?
If you are looking for the Meteor way to order the loading of files, use the Meteor.startup function and put the initialization code there. That function is the $.ready of the Meteor world, i.e., it will execute only after all your files have been successfully loaded on the client.
So in your case:
Meter.startup ->
congress_layer.addData(#congress_geojson)

Integrate application in GTK+2 with Nautilus 3 (using GTK+3). Is this possible?

I've an application written using PyGTK (GTK+2). I'd like to integrate it with Nautilus via an extension (something I am trying to learn). My current desktop has GNOME3 and Nautilus 3, which is written in GTK+3 and the extensions for Nautilus uses PyGObject.
Can I integrate my application in GTK+2 with Nautilus 3? (without porting my application to GTK+3, yet). Any hint?
I'm planning to port my application to GTK+3 (PyGObject), but it'll require more time than I have now.
Yes, it is possible. For instance, you can use Nautilus to call your program with the files or directories as arguments. The program you are calling can be written with any toolkit, or even be just a shell script.
A tiny example or an extension:
from gi.repository import Nautilus, GObject
from urllib import unquote
PROGRAM_NAME = '/path/to/your/program'
class MyExtension(GObject.GObject, Nautilus.MenuProvider):
def __init__(self):
pass
def call_my_program(self, menu, files):
# Do whatever you want to do with the files selected
if len(files) == 0:
return
# Strip the URI format to plain file names
names = [ unquote(file.get_uri()[7:]) for file in files ]
argv = [ PROGRAM_NAME ] + names
GObject.spawn_async(argv, flags=GObject.SPAWN_SEARCH_PATH)
def get_file_items(self, window, files):
# Show the menu if there is at least on file selected
if len(files) == 0:
return
# We care only files (local files)
for fd in files:
if fd.is_directory() or fd.get_uri_scheme() != 'file':
return
item = Nautilus.MenuItem(name='MyExtensionID::MyMethodID',
label='Do something with my program...')
item.connect('activate', self.call_my_program, files)
return item,
The extension is written using GObject Introspection (Nautilus 3), and it is generic: you can call any external program you want that accepts files as arguments. The key is GObject.spawn_async().
get_file_items is the method that Nautilus call when the user interacts with files. In that, you can bind a contextual menu (with Nautilus.MenuItem()). Then, you connect that menu with the method that calls your program (call_my_program()).
You can create other filters in the method get_file_items. For instance, to show the contextual menu only if there are text plain files selected (using fd.is_mime_type()). You can do whatever you have in mind. Beware of performing only non-blocking operations, otherwise you could block Nautilus.
To test the extension, you can install it in ~/.local/share/nautilus-python/extensions.
Check Introspection Porting:
Note that you can't do a migration halfway: If you try to import both
gtk and gi.repository.Gtk, you'll get nothing but program hangs and
crashes, as you are trying to work with the same library in two
different ways. You can mix static and GI bindings of different
libraries though, such as dbus-python and gi.repository.Gtk.
So, it depends on how the Nautilus plugins are implemented.