yaml file not getting copied when installing from setup.py - python-2.7

for my distutils package the yaml file along with python files is not getting copied
setup.py
from distutils.core import setup
files = ["*.yaml", "package/*"]
setup(name = "mypackage",
version = "0.1",
description = "description",
author = "Ciasto",
author_email = "me#email.com",
packages = ['package'],
package_data = {'package' : files },
scripts = ["scripts/runner"],
)
this is the project directory structure:
$ tree package/
|____
| |______init__.py
| |____command.py
| |____constants.py
| |____controller.py
| |____utils.py
| |____model.py
| |____products.yaml

package_data is used to add package's data to eggs (dropped in favor) and wheels (not with distutils). You're probably generating source distribution (sdist).
For sdist you need file MANIFEST.in (create it besides setup.py). In your case it should be enough to have one line in it:
include package/*.yaml
See the docs at https://docs.python.org/3/distutils/sourcedist.html#specifying-the-files-to-distribute
and
https://packaging.python.org/guides/using-manifest-in/#using-manifest-in
If you're not going to create wheels you can safely remove files and package_data from setup.py.

Related

Using the linear algebra library Eigen imported by the workspace in a package

I am using Bazel (version 0.25.2).
I have the following directory structure (one main folder called EigenDemo and a subfolder called Core containing some files):
EigenDemo
|-Core
| |- BUILD
| |- main.cpp
|- eigen.BUILD
|- WORKSPACE
The contents of the files look like this:
Core/main.cpp
#include <iostream>
#include <Eigen/Dense>
using Eigen::MatrixXd;
int main()
{
MatrixXd m(2, 2);
m(0, 0) = 3;
m(1, 0) = 2.5;
m(0, 1) = -1;
m(1, 1) = m(1, 0) + m(0, 1);
std::cout << m << std::endl;
}
WORKSPACE
workspace(name = "EigenDemo")
load("#bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
# Eigen
http_archive(
name = "eigen",
build_file = "//:eigen.BUILD",
sha256 = "3a66f9bfce85aff39bc255d5a341f87336ec6f5911e8d816dd4a3fdc500f8acf",
url = "https://bitbucket.org/eigen/eigen/get/c5e90d9.tar.gz",
strip_prefix="eigen-eigen-c5e90d9e764e"
)
Core/BUILD
cc_binary(
name = "EigenDemo",
srcs = ["main.cpp"],
copts = ["-Iexternal/eigen"],
deps = [
"#eigen",
],
)
eigen.BUILD (I use the one provided by tensorflow)
When I try to build (bazel build //...) I get the following error:
PS E:\dev\BazelDemos\EigenDemo> bazel build //...
Starting local Bazel server and connecting to it...
INFO: An error occurred during the fetch of repository 'eigen'
INFO: Call stack for the definition of repository 'eigen':
- E:/dev/bazeldemos/eigendemo/WORKSPACE:6:1
INFO: Repository 'eigen' used the following cache hits instead of downloading the corresponding file.
* Hash '3a66f9bfce85aff39bc255d5a341f87336ec6f5911e8d816dd4a3fdc500f8acf' for https://bitbucket.org/eigen/eigen/get/c5e90d9.tar.gz
If the definition of 'eigen' was updated, verify that the hashes were also updated.
ERROR: E:/dev/bazeldemos/eigendemo/Core/BUILD:1:1: no such package '#eigen//': Traceback (most recent call last):
File "C:/users/admin/_bazel_admin/u7yxnnij/external/bazel_tools/tools/build_defs/repo/http.bzl", line 56
workspace_and_buildfile(ctx)
File "C:/users/admin/_bazel_admin/u7yxnnij/external/bazel_tools/tools/build_defs/repo/utils.bzl", line 64, in workspace_and_buildfile
ctx.symlink(ctx.attr.build_file, "BUILD.bazel")
Unable to load package for //:eigen.BUILD: BUILD file not found in any of the following directories.
- E:/dev/bazeldemos/eigendemo and referenced by '//Core:EigenTest'
ERROR: Analysis of target '//Core:EigenTest' failed; build aborted: no such package '#eigen//': Traceback (most recent call last):
File "C:/users/admin/_bazel_admin/u7yxnnij/external/bazel_tools/tools/build_defs/repo/http.bzl", line 56
workspace_and_buildfile(ctx)
File "C:/users/admin/_bazel_admin/u7yxnnij/external/bazel_tools/tools/build_defs/repo/utils.bzl", line 64, in workspace_and_buildfile
ctx.symlink(ctx.attr.build_file, "BUILD.bazel")
Unable to load package for //:eigen.BUILD: BUILD file not found in any of the following directories.
- E:/dev/bazeldemos/eigendemo
INFO: Elapsed time: 10.959s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (9 packages loaded, 33 targets configured)
When I place all files in one folder everything works fine. I guess I have to change the deps field in the BUILD file:
deps = [
"#eigen",
],
But I do not know how ("//:eigen" does not work).
Add an empty BUILD file to EigenDemo directory:
EigenDemo
|-Core
| |- BUILD
| |- main.cpp
|- BUILD <-------------------- New empty BUILD file
|- eigen.BUILD
|- WORKSPACE

How to get ansible.module_utils to resolve my custom directory

Certain variables in ansible.cfg seem to not be taking affect.
Ansible 2.2.1.0
Python 2.7.10
Mac OS Version 10.12.5
We have created a custom class that will be used in our custom Ansible module. The class lives here:
/sites/utils/local/ansible/agt_module_utils/ldapData.py
/sites/utils/local/ansible/agt_module_utils/init.py
The class inside ldapData.py is named:
class ldapDataClass(object):
In all cases, init.py is a zero byte file.
Our Ansible module is located here:
/sites/utils/local/ansible/agt_modules/init.py
/sites/utils/local/ansible/agt_modules/agtWeblogic.py
The import statement in atgWeblogic looks as follows:
from ansible.module_utils.ldapData import ldapDataClass
I have also tried:
from ldapData import ldapDataClass
The config file has the following lines:
library = /sites/utils/local/ansible/att_modules
module_utils = /sites/utils/local/ansible/att_module_utils
When running our module, the modules directory IS resolved but the module_utils directory is not resolved. When the include is "from ansible.module_utils.ldapData import ldapDataClass" the failure is before ansible even connects to the remote machine. When the include is "from ldapData import ldapDataClass" the failure is on the remote machine. Below I am showing the failure "on the remote machine" (scroll right to see full error):
nverkland#local>ansible ecomtest37 -m agtWeblogic -a "action=stop instances=tst37-shop-main" -vvv
ecomtest37 | FAILED! => {
"changed": false,
"failed": true,
"invocation": {
"module_name": "agtWeblogic"
},
"module_stderr": "",
"module_stdout": "Traceback (most recent call last):\r\n File \"/tmp/ansible_FwHCmh/ansible_module_attWeblogic.py\", line 63, in <module>\r\n from ldapData import ldapDataClass\r\nImportError: No module named ldapData\r\n",
"msg": "MODULE FAILURE"
}
If I move the ldapData.py file into the "ansible installed" module_utils directory (/Library/Python/2.7/site-packages/ansible/module_utils/ on my Mac) the module runs fine. What have I done incorrectly in my config file that has prevented the use of my "custom" module_utils directory?
Thanks.
module_utils path is configurable since Ansible 2.3: changelog, PR.
I guess you have to upgrade or refactor the module.
Update: working example
Project tree:
.
├── ansible
│   └── ansible.cfg
├── module_utils
│   └── mycommon.py
└── modules
└── test_module.py
ansible.cfg:
[defaults]
library = ../modules
module_utils = ../module_utils
mycommon.py:
class MyCommonClass(object):
#staticmethod
def hello():
return 'world'
test_module.py:
#!/usr/bin/python
from ansible.module_utils.basic import *
from ansible.module_utils.mycommon import MyCommonClass
module = AnsibleModule(
argument_spec = dict()
)
module.exit_json(changed=True, hello=MyCommonClass.hello())
Execution:
$ ansible localhost -m test_module
[WARNING]: Host file not found: /etc/ansible/hosts
[WARNING]: provided hosts list is empty, only localhost is available
localhost | SUCCESS => {
"changed": true,
"hello": "world"
}
Ansible version:
$ ansible --version
ansible 2.3.1.0
config file = /<masked>/ansible/ansible.cfg
configured module search path = [u'../modules']
python version = 2.7.10 (default, Feb 7 2017, 00:08:15) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)]
Konstantin's notes helped. I managed to solve the riddle.
In my config file I had:
module_utils = /sites/utils/local/ansible/agt_module_utils
This causes Ansible to think that my class is found at:
import ansible.agt_module_utils.ldapData (working)
until now I was attempting to find the class at:
import ansible.module_utils.ldapData (broken)

making unit test binaries using scons with g++ and gtest

I am not able sucessfully build the the project using scons, g++ and gtest. I want to use gtest as unit test. My project looks like below:
project
| -SConstruct
| -src
| -name.hh
| -name.cc
| -main.cc
| -gtest
| -/src/gtest_name.hh
| -/src/gtest_name.cc
| -/src/gtest_main.cc
Inside SConstruct for project building, I have following code:
program_srcs = ['name.cc']
cpppath = ['./src']
libpath = ['.', 'path_to_third_party_lib']
libs = ['thirdlib']
pro_env = Environment()
env.Append(CPPPATH = cpppath)
env.Append(LIBS = libs)
env.Append(LIBPATH = libpath)
env.Library('name', program_srcs)
libpath.append('name')
env.Append(LIBPATH = libpath)
env.Program(target = 'NAME', source = [ './src/main.cc']
test_src = ['./gtest/src/gtest_name.cc']
test_env = Environment()
test_env['LIBPATH'] = ['.']
test_env.Program("unit_test", test_src, LIBS=['name'])
Inside gtest_name.cc
include"name.hh"
TEST_F(TESTNAME, testmethod) {
Name name;
ASSERT_EQ(name.get_surname, "MIKE");
}
When I tried to compile and build, it gave following errors for gtest.
g++ -o gtest/src/gtest_name.o -c gtest/src/gtest_name.cc
gtest/src/gtest_name.cc:10:29: error: name.hh: No such file or directory
When I checked for library 'name', it was already constructed. Could you please tell me what the problem is?
You have added the required include search path "src" to the variable CPPPATH, for the environment "env".
But you build the library with the environment "test_env" which doesn't have CPPPATH defined.
That's why the "-I" directive is missing in your compiler call.
Note, that SCons offers a Clone() method for environments. It copies over all current definitions (and builders for example) from one environment to create a new one...this might come in handy here.

Creating a small python program with cx_Freeze and pyGTK

I'm writing a small test-program that using python 2.7 and pygtk.
I will use Glade too
I need freeze this with cx_freeze.
This is my little program:
import gtk
win = gtk.Window()
win.connect("delete-event", gtk.main_quit)
win.show_all()
gtk.main()
And this is my setup:
from cx_Freeze import setup, Executable
import os, site, sys
## Get the site-package folder, not everybody will install
## Python into C:\PythonXX
site_dir = site.getsitepackages()[1]
include_dll_path = os.path.join(site_dir, "gnome")
## Collect the list of missing dll when cx_freeze builds the app
missing_dll = ['libgtk-win32-2.0-0.dll',
'libgdk-win32-2.0-0.dll',
'libatk-1.0-0.dll',
'libcairo-gobject-2.dll',
'libgdk_pixbuf-2.0-0.dll',
'libjpeg-8.dll',
'libpango-1.0-0.dll',
'libpangocairo-1.0-0.dll',
'libpangoft2-1.0-0.dll',
'libpangowin32-1.0-0.dll'
# 'libgnutls-26.dll',
# 'libgcrypt-11.dll',
# 'libp11-kit-0.dll'
]
## We also need to add the glade folder, cx_freeze will walk
## into it and copy all the necessary files
glade_path = os.path.join(site_dir, "gtk-2.0\\runtime\include\libglade-2.0\\")
glade_folder = 'glade'
# glade_folder = os.path.join(site_dir, "gtk-2.0\\")
# glade_folder += "runtime\include\libglade-2.0\glade"
## We need to add all the libraries too (for themes, etc..)
gtk_libs = ['etc', 'lib', 'share']
## Create the list of includes as cx_freeze likes
include_files = []
for dll in missing_dll:
include_files.append((os.path.join(include_dll_path, dll), dll))
## Let's add glade folder and files
include_files.append((glade_path, glade_folder))
## Let's add gtk libraries folders and files
for lib in gtk_libs:
include_files.append((os.path.join(include_dll_path, lib), lib))
base = None
## Lets not open the console while running the app
if sys.platform == "win32":
base = "Win32GUI"
executables = [
Executable("hello.py",
base=base
)
]
buildOptions = dict(
compressed=False,
includes=["gi"],
packages=["gi"],
include_files=include_files
)
setup(
name="test_gtk3_app",
author="my name",
version="1.0",
description="GTK 3 test",
options=dict(build_exe=buildOptions),
executables=executables
)
I run this command:
python setup_fr.py build
So, a folder called "build" is created with various files and directories. But, when I run the program "hello.exe", this error occurs:
Traceback (most recent call last): File "C:\Python27\lib\site-packages\cx_freeze-4.3.3-py2.7-win32.egg\cx_Freeze\initscripts\Console.py", line 27, in <module>
exec(code, m.__dict__) File "hello.py", line 1, in <module> File "C:\Python27\lib\site-packages\gtk-2.0\gtk\__init__.py", line 30, in <module>
import gobject as _gobject File "C:\Python27\lib\site-packages\gobject\__init__.py", line 26, in <module>
from glib import spawn_async, idle_add, timeout_add, timeout_add_seconds, \ File "C:\Python27\lib\site-packages\glib\__init__.py", line 22, in <module>
from glib._glib import * File "ExtensionLoader_glib__glib.py", line 22, in <module> File "ExtensionLoader_glib__glib.py", line 14, in __bootstrap__ ImportError: DLL load failed: Could not find the specified module.
I've looked at the "Build" folder to see if missing something related to gobject and found the "gobject._gobject.pyd" "libcairo-gobject-2.dll" and "GObject-2.0.typelib" files. I do not know exactly which file is still missing.
Can anyone help me figure out what is wrong?
Go to the gnome dir, which by itself is in the site-packages dir and manually copy all the .dll files (not the nested one) from this dir to your build/your-application-dir/ dir.
And it will work.

Bundling GTK3+ with cx_freeze

Platform is Windows 7 64bit using python 2.7 and GTK3 installed from
http://games.2g2s.de/?page_id=223 and PyGobject from here
http://sourceforge.net/projects/pygobjectwin32/files/?source=navbar
I used the script provided on wiki:
from cx_Freeze import setup, Executable
import os, site, sys
## Get the site-package folder, not everybody will install
## Python into C:\PythonXX
site_dir = site.getsitepackages()[1]
include_dll_path = os.path.join(site_dir, "gtk")
## Collect the list of missing dll when cx_freeze builds the app
missing_dll = ['libgtk-3-0.dll',
'libgdk-3-0.dll',
'libatk-1.0-0.dll',
'libcairo-2.dll',
'libcairo-gobject-2.dll',
'libgdk_pixbuf-2.0-0.dll',
'libpango-1.0-0.dll',
'libpangocairo-1.0-0.dll',
'libpangoft2-1.0-0.dll',
'libpangowin32-1.0-0.dll',
'libffi-6.dll',
'libfontconfig-1.dll',
'libfreetype-6.dll',
'libgio-2.0-0.dll',
'libglib-2.0-0.dll',
'libgmodule-2.0-0.dll',
'libgobject-2.0-0.dll',
'libpng15-15.dll',
]
## We also need to add the glade folder, cx_freeze will walk
## into it and copy all the necessary files
glade_folder = 'glade'
## We need to add all the libraries too (for themes, etc..)
gtk_libs = ['etc', 'lib', 'share']
## Create the list of includes as cx_freeze likes
include_files = []
for dll in missing_dll:
include_files.append((os.path.join(include_dll_path, dll), dll))
## Let's add glade folder and files
include_files.append((glade_folder, glade_folder))
## Let's add gtk libraries folders and files
for lib in gtk_libs:
include_files.append((os.path.join(include_dll_path, lib), lib))
base = None
## Lets not open the console while running the app
if sys.platform == "win32":
base = "Win32GUI"
executables = [
Executable("materii.py",
base=base
)
]
buildOptions = dict(
compressed = False,
includes = ["gi"],
packages = ["gi"],
include_files = include_files
)
setup(
name = "test_gtk3_app",
author = "Gian Mario Tagliaretti",
version = "1.0",
description = "GTK 3 test",
options = dict(build_exe = buildOptions),
executables = executables
)
The exe is compiled but fails to run, due to this
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\cx_Freeze\initscripts\Console.py", in <module>
exec code in m.__dict__
File "materii.py", line 2, in <module>
File "C:\Python27\lib\site-packages\gi\__init__.py", line 27, in <module>
from ._gi import _API
File "ExtensionLoader_gi__gi.py", line 22, in <module>
File "ExtensionLoader_gi__gi.py", line 14, in __bootstrap__
ImportError: DLL load failed: The specified module could not be found.
Line 2 from materii.py is
from gi.repository import Gtk
Can you help me please?
Go to the gnome dir, which by itself is in the site-packages dir and manually copy all the .dll files (not the nested one) from this dir to your build/your-application-dir/ dir. And it will work.