Is tensorflow a package or a module? - tensorflow

I'm new to Python and I'm trying to understand TensorFlow terminology. When I code import tensorflow as tf, I can call functions like tf.constant. This implies that tensorflow is a module.
When I look at the files in the installation directory, I see that tensorflow/contrib/learn has an init.py file, which means it's a package. A module can't contain a package, so that implies tensorflow is a package.
I'm sure this is obvious to many, but I can't decide whether tensorflow is a module or package. Any thoughts?

According to https://docs.python.org/3/tutorial/modules.html, TensorFlow qualifies as a package- a directory-organized set of modules to structure its namespace. It’s composed of modules:
A module is a file containing Python definitions and statements.
This doesn’t mean that you can’t (as you’ve observed) import a package. And that package’s __init__.py can expose definitions from subpackages and modules at the package-level namespace.

The difference between modules and packages in python is how the source code is organized:
Any file containing python code is a module
Any directory containing a file called __init__.py is a package. In addition, a package directory may contain any number of python source files (i.e. submodules of the package) and any number of directories which are themselves packages (i.e. subpackages).
Both modules and packages can be imported, and once imported they behave roughly the same. So for example you can use the . operator to access the contents of a module (module.thing) or a package (package.thing).

Related

Importing from the contrib library fails

I'm following the TDD book in Idris 2, and the online documentation gives the following advice:
For the VList view in the exercise 4 after Chapter 10-2 import Data.List.Views.Extra from contrib library.
So I put this import in a source file (example.idr)
import Data.List.Views.Extra
But running idris2 example.idr fails with
Error: Module Data.List.Views.Extra not found
I believe the contrib library is correctly installed, because contrib (0.5.1) appears in the list printed by idris2 --list-packages.
How can Idris 2 be made to accept imports from the contrib library?
In addition to explicitly providing -p on the command line (as in this answer), you can also define a package for your project, using an IPKG file, wherein you can specify your dependencies.
Minimal example, to be placed in the top-level directory of your project:
package type-driven-development
depends = contrib
Then you can invoke Idris 2 with idris2 --find-ipkg Example.idr, and all of the depends will be included as if you had specified -p for each one.
The Idris 2 CLI also can generate a template IPKG file for you. The idris2 --init command will provide you with interactive prompts in order to fill in some basic values.
The idris2 binary accepts a --package or -p argument to add a package as a dependency.
Invoking the interpreter with idris2 -p contrib example.idr allows the import to be resolved correctly.

Is it possible to apply dbt seed configurations to all projects that use a given package?

I built a dbt package for internal use. I'd like to specify the seed configurations in the dbt_project.yml of that package, and have those configurations apply to all projects that use the package. So far, I'm not sure if there's an issue with my syntax or if this just isn't possible.
The package dbt_project.yml includes the following:
seeds:
seed_name:
+quote_columns: false
+column_types:
column_name: varchar(127)
In a project that uses this package, there is a file data/seed_name.csv. When I run dbt seed for that project, I want the configuration defined in the package to apply to this seed. Instead, it seems to be ignored. To be clear, the .csv is included in the project that uses the package, not in the package itself.
It works if I move the above code out of the package and into the project-specific dbt_project.yml. However, this would mean that anyone using my package needs to copy that code into their file, which I'd prefer to avoid.

Python setuptools help on windows. Dll dependencies not identified

I wrote a pybind11 wrapper over a shared c++ library (.dll) on Windows.
I wanted to make a distributable package using setuptools.
I wrote a setup.py file and it generated the pyd file for the wrapper.
But when I try to run a script which imports the wrapper package python crashes.
It only succeeds only if I place all the dll dependencies in the script folder.
I found a temporary solution to the above problem.
I created an init.py file which adds the DLL directory in the beginning of the environment path variable.

How do I tell ReadTheDocs to build my project packages from a sub-directory?

I have a repository that contains three python packages: a main package, and two addon packages, with shared documentation. Each project is in its own directory, with its own setup.py, as so:
Repository
Main Project
setup.py
Addon One
setup.py
Addon Two
setup.py
Documentation
RST files, RTD conf, etc.
Previously, I was using setuptools.find_packages() to build my packages, but was having issues with the contents of the packages bleeding together, as they shared namespaces. So I switched to specifying the packages I wanted to build, such as
packages=["Main Package"]
However, this broke my ReadTheDocs auto-build, where I had specified
- method: setuptools
path: Main Project
in .readthedocs.yml, with RTD now complaining my package (inside the Main Project directory) doesn't exist, as it attempts to build it.
In my project, I use a script to build the packages, where I move into each directory, run its setup, then move out. Works fine, my packages and documentation all build locally. However, it looks like RTD is only using the defined path to prepend my setup.py script, and therefore not finding the source package as the working directory is the parent directory (but I could be wrong!).
I've read through the documentation, including https://github.com/readthedocs/readthedocs.org/issues/4354 where the feature was originally added, but I have not been able to find a solution myself yet.
How can I tell RTD to change directory before building the packages, or is there an alternative approach that will support my repo structure?
Repository in question is here.
I found a solution:
I changed my local build script to use the root project directory, as per-RTD. I then added the directive package_dir={"": "[directory]"} to the setuptools.setup() calls in each project's setup.py.

RequireJS extract list of all modules

How can one extract a list of all modules from a project using RequireJS? I am interested in getting the structure of the project, looking at modules and their dependencies.
I found an NPM package called Madge that can do exactly that. You can extract your RequireJS module dependencies and graph them using Graphviz.