Why can't I add a package (module) I created in Julia? - visual-studio-code

I am having trouble installing a module I created in Julia. I am running the Julia plugin under Visual Studio Code. If I run the file below with Ctrl+F5 I get a message
ERROR: LoadError: ArgumentError: Package Utils not found in current path:
- Run `import Pkg; Pkg.add("Utils")` to install the Utils package.
This is the file:
module demo
using Utils
greet() = print("Hello World!")
end # module
If I follow the advice on the error message I get another error message:
ERROR: LoadError: The following package names could not be resolved:
* Utils (not found in project, manifest or registry)
I also tried inserting this line:
import Pkg; Pkg.add(path="C:/Dropbox/Code/Julia/demo/src/Utils.jl")
and got this message (although the path definitely exists):
ERROR: LoadError: Path `C:/Dropbox/Code/Julia/demo/src/Utils.jl` does not exist.
The files demo.jl and Utils.jl are in C:\Dropbox\Code\Julia\demo\src\ and the demo project has been activated as can be seen in the REPL. The OS is Windows 10 Pro.
Any help will be greatly appreciated. Lots of time wasted trying to make this work.

Module and packages are not the same things. In short, packages are modules plus a set of metadata that make it easy for the package to be found and interact well with other packages. See here for a tutorial to write Julia packages:
https://syl1.gitbook.io/julia-language-a-concise-tutorial/language-core/11-developing-julia-packages
In your case, if you want to load a local module, just type include("fileWhereThereIsTheModule.jl") followed by a using Main.MyModule or using .MyModule. Note the dot... without it, Julia would indeed look for a package and to let it find your Demo or Util module you would have to either change an environmental variable or place your module file in certain predefined folders. Using include followed by the "absolute or relative position" of the module you don't have to do either.

Related

Data.Vector module Cannot Be Found

I start a new project library with cabal. here is the .cabal file
cabal-version: 2.4
library
exposed-modules: MyLib
build-depends: base ^>=4.14.3.0
, vector
hs-source-dirs: src
default-language: Haskell2010
I then use some Data.Vector functions inside my code. Here is the MyLib source
module MyLib (someFunc) where
import qualified Data.Vector as V
func :: [a] -> V.Vector a
func a = V.fromList a
But Data.Vector module remains underlined in red and this error is shown inside Vcode:
Could not load module ‘Data.Vector’
It is a member of the hidden package ‘vector-0.13.0.0’.
the func function works when in cabal repl
when I try cabal install vector this error appears:
Wrote tarball sdist to
/home/. .. .tar.gz
Resolving dependencies...
cabal: Cannot build the executables in the package vector because it does not
contain any executables. Check the .cabal file for the package and make sure
that it properly declares the components that you expect.
I don't understand what I am doing wrong? I told I understood the workings of cabal: I import a module as a dependency in .cabal, and I should be able to use it? why VSC does tell me he can't find it?

Distributing pybind11 extension linked to third party libraries

I'm working on a pybind11 extension written in C++ but I'm having a hard time understanding how should it be distributed.
The project links to a number of third party libraries (e.g. libpng, glew etc.).
The project builds fine with CMAKE and it generates a .so file. Now I am not sure what is the right way of installing this extension. The extension seems to work, as if I try copy the file into the python lib directories it is picked up (I can import it, and it works correctly). However, this is clearly not the way to go I think.
I also tried the setuptools route (from https://pybind11.readthedocs.io/en/stable/compiling.html) by creating a setup.py files like this:
import sys
# Available at setup time due to pyproject.toml
from pybind11 import get_cmake_dir
from pybind11.setup_helpers import Pybind11Extension, build_ext
from setuptools import setup
from glob import glob
files = sorted(glob("*.cpp"))
__version__ = "0.0.1"
ext_modules = [
Pybind11Extension("mylib",
files,
# Example: passing in the version to the compiled code
define_macros = [('VERSION_INFO', __version__)],
),
]
setup(
name="mylib",
version=__version__,
author="fab",
author_email="fab#fab",
url="https://github.com/pybind/python_example",
description="mylib",
long_description="",
ext_modules=ext_modules,
extras_require={"test": "pytest"},
cmdclass={"build_ext": build_ext},
zip_safe=False,
python_requires=">=3.7",
)
and now I can build the extension by simply calling
pip3 install
however it looks like all the links are broken because whenever I try importing the extension in Python I get linkage errors, as if setuptools does not link correctly the extension with the 3rd party libs. For instance errors in linking with libpng as in:
>>> import mylib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: /home/fabrizio/.local/lib/python3.8/site-packages/mylib.cpython-38-x86_64-linux-gnu.so: undefined symbol: png_sig_cmp
However I have no clue how to add this link info to setuptools, and don't even know if that's possible (it should be the setuptools equivalent of CMAKE's target_link_libraries).
I am really at a loss after weeks of reading documentation, forum threads and failed attempts. If anyone is able to point me in the right way or to clear some of the fog it would be really appreciated!
Thanks!
Fab
/home/fabrizio/.local/lib/python3.8/site-packages/mylib.cpython-38-x86_64-linux-gnu.so: undefined symbol: png_sig_cmp
This line pretty much says it clearly. Your local shared object file .so can't find the libpng.so against which it is linked.
You can confirm this by running:
ldd /home/fabrizio/.local/lib/python3.8/site-packages/mylib.cpython-38-x86_64-linux-gnu.so
There is no equivalent of target_link_libraries() in setuptools. Because that wouldn't make any sense. The library is already built and you've already linked it. This is your system more or less telling you that it can't find the libraries it needs. And those most likely need to be installed.
This is also one of the reasons why Linux distributions provide their own package managers and why you should use the developer packages provided by said distributions.
So how do you fix this? Well your .so file needs to find the other .so files against which you linked to understand how this works I will refer you to this link.
My main guess is based on the fact that when you manually copy the files it works - That during the build process you probably specify the rpath to a local directory. Hence what you most likely need to do is specify to your setuptools that it needs to copy those files when installing.

colcon build error on Ros2 Foxy Unity-Robotics-Hub example

I am following ROS–Unity Integration tutorial for ROS2. I coppied unity_robotics_demo and unity_robotics_demo_msgs to my src folder from here. When building unity_robotics_demo_msgs gives me an error. I did source install/setup.bash and colcon build. Error:
CMake Error at CMakeLists.txt:7 (find_package):
By not providing "Findrosidl_default_generators.cmake" in CMAKE_MODULE_PATH
this project has asked CMake to find a package configuration file provided
by "rosidl_default_generators", but CMake did not find one.
Could not find a package configuration file provided by
"rosidl_default_generators" with any of the following names:
rosidl_default_generatorsConfig.cmake
rosidl_default_generators-config.cmake
Add the installation prefix of "rosidl_default_generators" to
CMAKE_PREFIX_PATH or set "rosidl_default_generators_DIR" to a directory
containing one of the above files. If "rosidl_default_generators" provides
a separate development package or SDK, be sure it has been installed.
I am not sure how to add the installation prefix. In foxy/share there is rosidl_default_generators:

How to debug unit test while developping a package in Julia

Say I develop a package with a limited set of dependencies (for example, LinearAlgebra).
In the Unit testing part, I might need additional dependencies (for instance, CSV to load a file). I can configure that in the Project.toml all good.
Now from there and in VS Code, how can I debug the Unit tests? I tried running the "runtests.jl" in the debugger; however, it unsurprisingly complains that the CSV package is unavailable.
I could add the CSV package (as a temporary solution), but I would prefer that the debugger run with the configuration for the unit testing; how can I achieve that?
As requested, here is how it can be reproduced (it is not quite minimal, but instead I used a commonly used package as it give confidence the package is not the problem). We will use DataFrames and try to execute the debugger for its unit tests.
Make a local version of DataFrames for the purpose of developing a feature in it. I execute dev DataFrames in a new REPL.
Select the correct environment (in .julia/dev/DataFrames) through the VS-code user interface.
Execute the "proper" unit testing by executing test DataFrames at the pkg prompt. Everything should go smoothly.
Try to execute the tests directly (open the runtests.jl and use the "Run" button in vs-code). I see some errors of the type:
LoadError: ArgumentError: Package CategoricalArrays not found in current path:
- Run `import Pkg; Pkg.add("CategoricalArrays")` to install the CategoricalArrays package.
which is consistent with CategoricalArrays being present in the [extras] section of the Project.toml but not present in the [deps].
Finally, instead of the "Run" command, execute the "Run and Debug". I encounter similar errors here is the first one:
Test Summary: | Pass Total
merge | 19 19
PASSED: index.jl
FAILED: dataframe.jl
LoadError: ArgumentError: Package DataStructures not found in current path:
- Run `import Pkg; Pkg.add("DataStructures")` to install the DataStructures package.
So I can't debug the code after the part requiring the extras packages.
After all that I delete this package with the command free DataFrames at the pkg prompt.
I see the same behavior in my package.
I'm not certain I understand your question, but I think you might be looking for the TestEnv package. It allows you to activate a temporary environment containing the [extras] dependencies. The discourse announcement contains a good description of the use cases.
Your runtest.jl file should contain all necessary imports to run tests.
Hence you are expected to have in your runtests.jl file lines such as:
using YourPackageName
using CSV
# the lines with tests now go here.
This is a standard in Julia package layout. For an example have a look at any mature Julia such as DataFrames.jl (https://github.com/JuliaData/DataFrames.jl/blob/main/test/runtests.jl).

Can't import the Svg library in elm?

Trying to use Svg and Svg.Attributes. Getting the error message
I cannot find module 'Svg'.
Module 'Main' is trying to import it.
Potential problems could be:
* Mispelled the module name
* Need to add a source directory or new dependency to elm-package.json
I'm certain that there aren't any spelling errors because I copy and pasted the imports from a tutorial. Where do I install this library?
The tutorial I'm going through is the one elm-lang.org, specifically the section on time.
You need the elm-lang/svg package as a dependency in your elm-package.json. Run elm package install elm-lang/svg in the project directory.