scons -u and variantdirs - python

I've been working with SCons for a while now and I'm facing a problem that I can't manage to resolve, I hope someone can help me. I created a dummy project that compiles a basic helloWorld (in main.cpp). What I want to do is compile my binary from 'test' folder using the scons -u command. All of my build is done in a variant dir that will eventually be created at the root of the project (build folder).
Here's my folder tree :
+sconsTest
-SConstruct
+ test
-SConscript
+test2
-SConscript
-main.cpp
+build (will eventually be created by scons)
Following is the SConstruct code:
env = Environment()
env.SConscript('test/SConscript', {'env' : env})
Following is test/SConscript code:
Import('env')
env = env.Clone()
env.SConscript('test2/SConscript', {'env' : env}, variant_dir="#/build", duplicate=0)
Following is test2/SConscript code:
Import('env')
env = env.Clone()
prog = env.Program('main', 'main.cpp')
After placing myself in 'sconsTest/test' folder, I type in scons -u, I expect it to build my program, however all it says is 'test' is up to date. When nothing is compiled. I noticed something, when I remove both variant_dir and duplicate args from test/SConscript, the scons -u works.
Furthermore, I noticed it was possible for me to compile the program using the command
scons -u test2
However, I'm using scons on a large scale project and I don't like giving a relative path as an argument to compile my project. I want scons -u to automatically build everything it finds in subdirs.
Do anyone have any idea on how to resolve this issue?

Please check the MAN page again. The -u option will only build default targets at or below the current directory. This excludes your folder sconsTest/build when you're in sconsTest/test.
What you are looking for is the -U option (with the capital "U") instead. It builds all default targets that are defined in the SConscript(s) in the current directory, regardless of what directory the resultant targets end up in.

Related

ta-lib replit python install problem, ERROR: No matching distribution found for talib-binary

I use it on my windows machine by downloading its binary. I also use it in Heroku from its herokus build pack. I don't know what operating system replit use. But I try every possible commed like.
!pip install ta-lib
!pip install talib-binary
It's not working with replit. I thought it work like google co-lab but its not the same.
can anyone use TA-LIB with replit. if so. How you install it?
Getting TA-Lib work on Replit
(by installing it from sources)
Create a new replit with Nix toolset with a Python template.
In main.py write:
import talib
print (talib.__ta_version__)
This will be our test case. If ta-lib is installed the python main.py (executed in Shell) will return something like:
$ python main.py
b'0.6.0-dev (Jan 1 1980 00:00:00)'
We need to prepare a tools for building TA-Lib sources. There is a replit.nix file in your project's root folder (in my case it was ~/BrownDutifulLinux). Every time you execute a command like cmake the Nix reports that:
cmake: command not installed. Multiple versions of this command were found in Nix.
Select one to run (or press Ctrl-C to cancel):
cmake.out
cmakeCurses.out
cmakeWithGui.out
cmakeMinimal.out
cmake_2_8.out
If you select cmake.out it will add a record about it into the replit.nix file. And next time you call cmake, it will know which cmake version to launch. Perhaps you may manually edit replit.nix file... But if you're going to add such commands in a my way, note that you must execute them in Shell in your project root folder as replit.nix file is located in it. Otherwise Nix won't remember your choice.
After all my replit.nix file (you may see its content with cat replit.nix) content was:
{ pkgs }: {
deps = [
pkgs.libtool
pkgs.automake
pkgs.autoconf
pkgs.cmake
pkgs.python38Full
];
env = {
PYTHON_LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
# Needed for pandas / numpy
pkgs.stdenv.cc.cc.lib
pkgs.zlib
# Needed for pygame
pkgs.glib
# Needed for matplotlib
pkgs.xorg.libX11
];
PYTHONBIN = "${pkgs.python38Full}/bin/python3.8";
LANG = "en_US.UTF-8";
};
}
Which means I executed libtool, autoconf, automake and cmake in Shell. I always choose a generic suggestion from Nix, without a specific version. Note: some commands may report errors as we executing them in a wrong way just to add to a replit.nix.
3.
Once build tools are set up we need to get and build TA-Lib C library sources. To do that execute in Shell:
git clone https://github.com/TA-Lib/ta-lib.git
then
cd ta-lib/
libtoolize
autoreconf --install
./configure
If configure script is completed without any problems, build the library with:
make -j4
It will end up with some compilation errors, but they are related to some additional tools which are used to add new TA-Lib indicators and build at the end, but not the library itself. The library will be successfully compiled and you should be able to see it with:
$ ls ./src/.libs/
libta_lib.a libta_lib.lai libta_lib.so.0
libta_lib.la libta_lib.so libta_lib.so.0.0.0
Now we have our C library built, but we can't install it to a system default folders. So we have to use the library as is from the folders where it was build. All we need is just one more additional preparation:
mkdir ./include/ta-lib
cp ./include/*.h ./include/ta-lib/
This will copy a library headers to a subfolder, as they are designed to be used from a such subfolder (which they don't have due to impossibility to perform the installation step).
4.
Now we have TA-Lib C library built and prepared to be used locally from its build folders. All we need after that - is to compile the Python wrapper for it. But Python wrapper will look for a library only in system default folders, so we need to instruct it where our library is.
To do this, execute pwd and remember the absolute path to your project's root folder. In my case it was:
/home/runner/FormalPleasedOffice
Then adjust the paths (there are two) in a following command to lead to your project path:
TA_INCLUDE_PATH=/home/runner/FormalPleasedOffice/ta-lib/include/ TA_LIBRARY_PATH=/home/runner/FormalPleasedOffice/ta-lib/src/.libs/ pip install ta-lib
This is one line command, not a two commands.If the paths would be shorter it would look like:
TA_INCLUDE_PATH=/path1/ TA_LIBRARY_PATH=/path2/ pip install ta-lib.
After execution of this command the wrapper will be installed with two additional paths where it will look for a library and its header files.
That's actually all.
An alternative way would be to clone the wrapper sources, edit its setup.py and install wrapper manually. Just for the record this would be:
cd ~/Your_project
git clone https://github.com/mrjbq7/ta-lib.git ta-lib-wrapper
cd ta-lib-wrapper
Here edit the setup.py. Find the lines include_dirs = [ and library_dirs = [ and append your paths to these lists. Then you just need to:
python setup.py build
pip install .
Note the dot at the end.
5.
Go to the project's folder and try our python script:
$python main.py
b'0.6.0-dev (Jan 1 1980 00:00:00)'
Bingo!
The #truf answer is correct.
after you add the
pkgs.libtool
pkgs.automake
pkgs.autoconf
pkgs.cmake
in the replit.nix dippendancies.
git clone https://github.com/TA-Lib/ta-lib.git
cd ta-lib/
libtoolize
autoreconf --install
./configure
make -j4
mkdir ./include/ta-lib
cp ./include/*.h ./include/ta-lib/
TA_INCLUDE_PATH=/home/runner/FormalPleasedOffice/ta-lib/include/ TA_LIBRARY_PATH=/home/runner/FormalPleasedOffice/ta-lib/src/.libs/ pip install ta-lib
Note : FormalPleasedOffice should be your project name
Done.
Here is the youtube video :
https://www.youtube.com/watch?v=u20y-nUMo5I

cd command in python

I am new to python and
I am trying to test syntaxnet in python using this github repo.
and in the section "how to run the parser" is as following :
git clone https://github.com/spoddutur/syntaxnet.git
cd <syntaxnet-git-clone-directory>
python main.py
That's it!! It prints syntaxnet dependency parser output for given input english sentence
through some research, I understood that first one indicates that I need to install the syntaxnet package in my cmd so I did and the package was successfully installed.
but I don't understand how to perform the second one
what does cd do, and where and how should I use it?
also in main.py,
from my_parser_eval import SyntaxNetProcess
from my_parser_eval import _write_input
from my_parser_eval import _read_output
from my_parser_eval import pretty_print
eclipse cannot find those imports, even after I created a package/module named my_parser_eval that includes all necessary codes from the reference
The CD command means Change Directory.
Once you have finished cloning Syntaxnet Github Repository, you should enter its directory. That's why you have to enter CD command.
But have in mind that CD takes one parameter - the directory you want to enter.
In order to solve your problem you must write cd syntaxnet resulting in:
git clone https://github.com/spoddutur/syntaxnet.git
cd syntaxnet
python main.py
First command:
Second command

How to (hermetically) include Python interpreter in Bazel to build Python library (sdist)

How can I (hermetically) include python as an (executable) input to my genrule?
Conceptually, I'm aware of the following approaches:
include a python interpreter in the source repo at third_party/python
have Bazel fetch python ala rules-go
There also seem to be a couple methods for doing so:
py_runtime
py_toolchain (doesn't seem to be available yet)
py_distribution_package (doesn't seem to be available yet)
genrules.tools
genrules.toolchains
Example:
I have a python library:
myproject
- setup.py
- mylibrary
- __init__.py
- myfunction.py
I'd like to produce a pip install-able distribution with Bazel so that I can do:
pip install <path/to/distribution>
python
>>> from mylibrary.myfunction import helloworld
>>> helloworld()
I added a (empty) WORKSPACE file at myproject/WORKSPACE and followed the example in this medium article:
# myproject/BUILD
genrule(
name = "mylibrary_sdist",
srcs = glob(["**/*.py"]),
outs = ["mylibrary.tar.gz"],
cmd = "python setup.py sdist && mv dist/mylibrary*.tar.gz $(location mylibrary.tar.gz)"
)
This works (ie. produces bazel-genfiles/mylibrary.tar.gz), but I'm shelling out to python.
How can I (hermetically) include python as an (executable) input to my genrule?
Unless I'm misunderstanding your question, this should just be a matter of passing the actual path to your target python executable. I would check the python executable into the third_party dir and instead of invoking your genrule using simply python I'd pass the relative path to that executable relative to WORKSPACE.

Mac OS X error: directory that is not on PYTHONPATH and which Python does not read ".pth" files from

I'm getting an error while trying to install FEnicS on Mac OS X 10.11.6. I've read the responses to similar questions on this website, and have tried the suggested solutions, but I must be doing something wrong.
On running the command:
curl -s https://fenicsproject.org/fenics-install.sh | bash
I get an error while the cython package is being installed:
[cython] Building cython/e2t4ieqlgjl3, follow log with:
[cython] tail -f /Users/sophiaw/.hashdist/tmp/cython-e2t4ieqlgjl3-1/_hashdist/build.log
[cython|ERROR] Command '[u'/bin/bash', '_hashdist/build.sh']' returned non-zero exit status 1
[cython|ERROR] command failed (code=1); raising.
The message from build.log is:
Checking .pth file support in
/Users/sophiaw/.hashdist/bld/cython/e2t4ieqlgjl3/lib/python2.7/site-packages/
/Users/sophiaw/.hashdist/bld/python/pf77qttkbtzn/bin/python -E -c pass
TEST FAILED:
/Users/sophiaw/.hashdist/bld/cython/e2t4ieqlgjl3/lib/python2.7/site-packages/
does NOT support .pth files error: bad install directory or
PYTHONPATH
You are attempting to install a package to a directory that is not on
PYTHONPATH and which Python does not read ".pth" files from. The
installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:
/Users/sophiaw/.hashdist/bld/cython/e2t4ieqlgjl3/lib/python2.7/site-packages/
and your PYTHONPATH environment variable currently contains:
'/Users/sophiaw/.hashdist/bld/cython/e2t4ieqlgjl3/Python.framework/Versions/2.7/lib/python2.7/site-packages:'
Here are some of your options for correcting the problem:
You can choose a different installation directory, i.e., one that is on PYTHONPATH or supports .pth files
You can add the installation directory to the PYTHONPATH environment variable. (It must then also be on PYTHONPATH whenever you run Python
and want to use the package(s) you are installing.)
You can set up the installation directory to support ".pth" files by using one of the approaches described here:
https://pythonhosted.org/setuptools/easy_install.html#custom-installation-locations
Please make the appropriate changes for your system and try again.
I've tried adding this to the bash_profile, but get the same error:
export PYTHONPATH=/Users/sophiaw/.hashdist/bld/cython/e2t4ieqlgjl3/lib/python2.7/site-packages:$PYTHONPATH.
How can I fix this error?
This was resolved by the fenics support group. to install FEniCS on OS X, Docker is a more convenient option.

SCons Install ignores Default specification within script

This is related to scons - always install after build
With scons 2.3.2, I am trying to get SCons to install the target that gets built into its pre-defined location without running extra commands. The solution proposed in the link above does not work for me. So I am trying to use default targets instead.
Let's say my source is in src/a and I install into /dst-path/a. In src/a SConscript (called from the parent SConscript) I have:
result = env.MyBuild(some_tgt, some_src)
env.Install('/dst-path/a', result)
If I type scons -u in src/a, it builds but does not install. If I type scons -u /dst-path/a in the same location, it builds and installs. I can add env.Alias('install', '/dst-path/a') and then scons -u install would install. This much is described in user guide. But I want to run just scons -u to build AND install.
So my idea is to add /dst-path/a to default targets and only in place that could generate content for that location. So, in that SConscript in src/a, I do
env.Default('/dst-path/a')
from SCons.Script import DEFAULT_TARGETS, BUILD_TARGETS
print "DEFAULT_TARGETS in %s is %s" % (env['MY_SOURCE_DIR'], map(str, DEFAULT_TARGETS))
print " BUILD_TARGETS in %s is %s" % (env['MY_SOURCE_DIR'], map(str, BUILD_TARGETS))
# env['MY_SOURCE_DIR'] tracks current source path and evaluates to 'src/a' in this case
Presumably, this is equivalent to me calling scons -u /dst-path/a Now I delete /dst-path/a, run scons -u while in src/a and see
DEFAULT_TARGETS in src is []
BUILD_TARGETS in src is []
DEFAULT_TARGETS in src/a is ['/dst-path/a']
BUILD_TARGETS in src/a is ['/dst-path/a']
- yet nothing happens!. But if I run scons -u /dst-path/a, I see
DEFAULT_TARGETS in src is []
BUILD_TARGETS in src is ['/dst-path/a']
DEFAULT_TARGETS in src/a is ['/dst-path/a']
BUILD_TARGETS in src/a is ['/dst-path/a']
- and now it builds and installs, just as before. My code had no effect.
So why does it completely ignore my Default specification, even though it even makes it into the BUILD_TARGETS? Is it a bug?
How on earth can I coerce SCons to install the things it builds in one step?
BTW, not sure if it matters much, but I also use VariantDir to separate intermediate files from the source ones.
Ok, I've learned that "-u" affects things. It does not build any Default targets, according to the option help (I think --ignore_defaults option would be a better approach, but oh well...)
So, for SCons to not ignore the Defaults, one should use "-D" or "-U". "-D" picks up the defaults all over the build tree, regardless the current location - that's not what I want. "-U", however, honors the defaults as set according to the current location.
Now the real problem turned out to be the install path! I've tried changing the install location from /dst-path/a to install/a (i.e. within the build tree) and now, magically, everything works! That is even "-u" works as expected (without extra Defaults set), installing the file, when it is not there. And if I set the install path as Default, then "-U" works instead. But with /dst-path/a path, the "-U" says it found no Default targets. If I change nothing but switch the path, then it suddenly finds them and builds.
Basically, this would all work fine from the start had I had install path within the tree. But why would I want to install within the source subtree? This is a crazy limitation. I'd call this a bug.
So this solution only works if you install within the tree, and it works as expected, without any trickery. This still does not answer how to install outside the tree.
...And it does not. You must call the install target/path explicitly in the scons command. Some examples are:
scons -u /dst-path/a # as seen in manual and FAQ
scons -u src/a # if you have Alias('src/a', '/dst-path/a')
# but "scons -u" or "scons -u '.'" from src/a won't work!
Another way to put it: when it comes to external paths, the behavior differs. SCons won't build anything outside top path no matter what you do in Install, Alias, or Default, until that outside path (or its alias) is passed as a target to the scons command. And this has nothing to do with -u/-U, etc.

Categories

Resources