Why are `__init__.py` and `BUILD` needed inside TensorFlow's `models/tutorials/rnn/translate`? - tensorflow

Inside the tensorflow/models/tutorials/rnn/translate folder, we have a few files including __init__.py and BUILD.
Without __init__.py and BUILD files, the translate script can still manage to run.
What is the purpose of __init__.py and BUILD here? Are we supposed to install or build it using these two files?

The BUILD file supports using Bazel for hermetic building and testing of the model code. In particular a BUILD file is present in that directory to define the integration test translate_test.py and its dependencies, so that we can run it on continuous integration system (e.g. Jenkins).
The __init__.py file causes Python to treat that directory as a package. See this question for a discussion of why __init__.py is often present in a Python source directory. While this file is not strictly necessary to invoke translate.py directly from that directory, it is necessary if we want to import the code from translate.py into a different module.
(Note that when you run a Python binary through Bazel, the build system will automatically generate __init__.py files if they are missing. However, TensorFlow's repositories often have explicit __init__.py files in Python source directories so that you can run the code without invoking Bazel.)

Related

Meson: how to copy subproject file to build directory?

I'm using Meson build system to build a simple executable app.
Problem is: the executable needs to have access to file file.txt which is located in the separate utils repository. The executable app reads this file at runtime and can't work without accessing it.
I have pulled in the utils repository as a Meson subproject, but I am not sure how would I copy the subprojects/utils/file.txt to a builddirdirectory where the executable is built. Currently the app is built without problems, but when I run it, it fails to find file.txt.
How do I copy the subprojects/utils/file.txt to builddir?

Dart library: export a file from the test folder

My library's structure is:
mylib
lib
mylib.dart
src
example.dart
test
utilities.dart
I'd like to export some helper functions I've written in this library so they can be used in the test files of other libraries.
In mylib.dart, which contains exports for the other classes in the library (e.g. export 'src/example.dart';, the following line causes an error:
export '../test/utilities.dart';
The error is:
Target of URI doesn't exist: '../test/utilities.dart'.
It seems I can only export files under the lib folder. I imagine this is a security thing, so I don't go exporting files from just anywhere on my computer.
Is it possible to export a file that contains utility functions for tests, if that file lives under the test folder? Or should I put those utility functions in a file under the lib folder, even though they only pertain to testing, and should only be used in other libraries' tests?
If you have test code that you want to share in tests for other packages, you should put your code in the lib/ directory (or in its own package) and expect that non-testing code would just not bother importing it.
If you have test code that you want to share in tests in the same package, you can leave it in your test/ directory (or in a subdirectory), and test files in test/ can import it via the relative path.

python: converting an egg-info directory to dist-info

I am working on an existing python application inside of a virtualenv environment. It is already set up to use wheel within its deployment.
I have added another module which my application now needs, and this module only exists in egg format. It is currently installed among all the other modules within ./env/lib/python3.6/site-packages, and an egg-info directory exists for it.
My question is this: how do I convert this one egg-info directory to wheel format, so that it gets included in the application's deployment when I do the following? ...
python3 setup.py bdist_wheel upload -r XXXXXXXX
Assuming I have installed a module under ./env/lib/python3.6/site-packages/the-module-1.2.3.egg-info, what are the steps to convert that module to dist-info?
Note that I don't see any *.egg file for that module, only the egg-info directory.
Thank you.

How can I separate generated artifacts from the main build with semantic UI?

I am trying to figure out how to integrate Semantic UI with my gulp-based frontend toolchain.
The npm artifact semantic-ui includes an interactive installer that will write a semantic.json file to the root of my project and install the less files, gulp tasks and some configuration into my project. All of these files will be put in subdirectories of a single base directory specified in semantic.json.
I do not want any dependency implementation files or any generated files in the git repository for my project because this will pollute revision history and lead to unneccessary merge conflicts. I would very much prefer to provide semantic.json only and .gitignore the semantic base directory. On npm install, the Semantic installer should install everything to the base directory specified in semantic.json. When building, I want the artifacts generated into a separate dist directory that does not reside under the semantic base directory.
However, if I do this, the installer will fail with a message stating that it cannot find the directories to update and drop me into the interactive installer instead. This is not what I want, because it means my build is no longer non-interactive (which will cause the CI build to fail).
How can I integrate Semantic UI into my build without having to commit Semantic and its generated artifacts into my git repository?
This is what we did in our similar scenario. The following are true:
Everything Semantic UI generates is in .gitignore. Therefore, the only Semantic UI files we have in our repo are:
semantic.json
semantic/src folder (this is where our theme modifications actually are)
semantic/tasks folder (probably doesn't need to be on git, but since it's needed for building, everything is simpler if we keep it in our repo)
We never need to (re)run the Semantic UI installer, everything is integrated in our own gulpfile.js.
Semantic UI outputs in our assets folder which is not in the same folder as its sources.
Semantic UI is updated automatically using npm as per the rules in my package.json.
Here are the steps needed to achieve this:
Install Semantic UI. By this I assume that you either used npm or cloned it from git (using npm is highly recommended), either way, you have semantic.json in your project's main folder and a semantic folder with gulpfile.js, src and tasks.
Make sure Semantic UI can be built. Navigate to semantic/ and run gulp build. This should create a dist folder in your semantic/ directory. Delete it and also delete Semantic UI's gulpfile.js since you'll no longer need it.
Edit semantic.json. You need to edit two lines:
Change "packaged": "dist/", to the path where you'd like to output semantic.css and semantic.js relative to Semantic UI's folder. In our case, it was "packaged": "../../assets/semantic/",
Change "themes": "dist/themes/" in the same way, since the themes/ folder contains fonts and images Semantic UI uses so it needs to be in the same folder as semantic.css. In our case, it was "themes": "../../assets/semantic/dist/themes/".
Edit your gulpfile.js so that it uses Semantic UI's build task. Add var semanticBuild = require('./semantic/tasks/build'); (if semantic/ is in the same folder as your gulpfile.js) and then simply register a task that depends on it, for example gulp.task('semantic', semanticBuild);.
Optionally, create a clean task. We used del for that.
gulp.task('clean:semantic', function(cb) {
del(['assets/semantic'], cb);
});

CMAKE for a build a simple framework

I have my mind crashing with cmake. After this answer I have tried to make a simple example and put it in github because there are a lot of file inside directories and could be boring copy everything here.
What I'd like to do is to build a simple frameworks for handling my qt/opencv/opengl experiments. What I like to have is a repository with those directories:
root*
|-apps
|---test1*
|
|-build
|-cmake*
|
|-modules
|---foo*
(The * signed directory are the ones with some cmake files like CmakeLists.txt or FindXXModule.cmake)
In modules i can write the modules (for example a module for face recognition, a module for draw a red cube in opengl, a module that contains my personal qt widget extension).
Than I need an easy way for create an application and link some modules on it. For that I thought to create a cmake directory where to put the FindXXModule.cmake and in the apps just say: find_package(XXModule).
Note that for now I don't care about installing this repository and the tree structure must be this one (so if I am in a apps/test2 I know I can refer to the cmake directory as ../../cmake or the module directory is ../../modules)
I have wrote a little example with the app named test1 that uses the module foo and i put it in a github repository.
For now I can compile the application test1 with cmake calling cmake path_to_test1_CmakeLists.txt and I am happy about that. But if I try to launch cmake path_to_root_CmakeLists.txt it does not work because the file Findfoo.cmake is read two time (and i did't be able to use some if for not reading it twice).
Then, if i run the test1 cmake a foo directory with cmake cache etc are created in root/cmake and I don't want it. I want all file cmake has to generate are in root/build directory.
So, those are my 2 question:
How create a CmakeLists.txt that can build all the apps and all the future test i will write in the modules directory
How avoid that launching cmake of a single app will create files in the cmake directory.
Sorry if my english and my idea of how cmake works are not good.. i hope it is clear.
EDIT:
One more thing. In Findfoo.cmake I have a bad hack: for adding the real CMakeLists.txt inside a modules/foo when I call the cmake from test1 I have to add a subdirectory that is not in the tree.. Maybe this kind of hack could be deleted reviewing the enteire structure..
As you say you want to put the whole directory structure into source control. This means these folder structure is same on every location where you do a checkout. So why creating the Findfoo.cmake if you have a relative path the the foo directory?
I suggest to put a CMakelists.txt file in to root that adds all subdirectories. To reduce confusion between files generated by CMake and original files, you should create a folder called ./build (or even ../build) and run CMake in that directory with the root directory as first argument. This creates all CMake generated files in the ./build directory and gives you the possibility to clean it up easily. This way of working is called out-of-source build and its highly recommended to use cmake in this way. See this question for an example.