Setting up Sphinx Autodoc with existing project - python-sphinx

I'm am completely new to Sphinx and have watched hours of tutorials, but could not find the answer to my issue
I have a current project structure like the following
-project folder
|-sub folder 1
| |- sub folder 1.a
| | - ...
|-sub folder 2
| |- sub folder 2.a
| | - ...
|-sub folder 3
| |- sub folder 3.a
| | - ...
|- .py files
|...
|- conf.py
|- index.rst
|- Makefile
|- _build/
| |-doctrees/
| |-html/
| |...(all the html files generated by "make html")
I have included the following in my conf.py
extensions = ['autoapi.extension']
# Document Python Code
autoapi_type = 'python'
autoapi_dir = '../project folder'
inside each of the sub folders i have .py files that contain classes, functions, modules, members that all need to be documented. Is there a way that sphinx will parse through the current project folder and all of its subdirectories in search for .py files to autodoc? If so, how would I have to set up my index.rst and conf.py file to make this happen?
The error I am seeing is as follows:
Removing everything under '_build'...
Running Sphinx v1.8.5
making output directory...
Extension error:
You must configure an autoapi_dirs setting
Makefile:19: recipe for target 'html' failed
make: *** [html] Error 2

The error is explicit: You must configure an autoapi_dirs setting. You have a typo in your conf.py setting, omitting the "s" in your setting autoapi_dir. See configuration value of autoapi_dirs for autoapi.

Related

Sphinx is building cross-references with broken paths (singlehtml output)

I have a Sphinx project that has the following structure:
projectRoot
|
|__mainDoc
| |__conf.py
| |__index.rst
|
|__subsections
|__subsectionA.rst
|__subsectionB.rst
In my conf.py, I have set my master_doc variable to "mainDoc/index", and to build the project I run the following command at the projectRoot directory: sphinx-build -c ./mainDoc -b singlehtml . _build
index.rst contains a simple toctree directive that lists the two subsection files like so:
.. toctree::
:numbered:
:hidden:
:maxdepth: 4
:caption: Contents:
../subsections/subsectionA
../subsections/subsectionB
subsectionA.rst:
.. _anchorA:
First Title
===========
This is a sample sentence.
subsectionB.rst:
Second Title
============
Please refer to :ref:`this sentence <anchorA>`
So far everything is pretty straightforward, and I was able to successfully build an HTML file. However, the cross-references are broken. Specifically, if the generated HTML file is in _build/maindoc/index.html, the link in subsectionB.rst points to _build/maindoc/maindoc/index.html#anchora, which is a file that doesn't exist since there's an extra maindoc folder in the path.
What is causing that extra folder to be inserted in the link target, and what can I do to fix that? Thanks in advance.

BAZEL + bash: execute bash/python script to do code generation and use them in bazel system

I am new to Bazel. I have a project which is built with Bazel.
But some of the source files are pre-codegened and then compile them with Bazel.
Now I can run the bash script standalone and run the bazel command:
.
|-- project
| |-- BUILD (will depend on temp_output:codegen)
| |-- scripts
| | |-- codegen.sh (read config.yaml and generate codegen.cpp/hpp and a BUILD.bazel)
| |-- config
| | |-- config.yaml
| |-- temp_output
| | |-- codegen.cpp (not existed before running codegen.sh)
| | |-- codegen.hpp (not existed before running codegen.sh)
| | |-- BAZEL.build (not existed before running codegen.sh)
|-- WORKSPACE
$ ./scripts/codegen.sh
$ bazel build :project
What are done in the codegen.sh:
Read the config.yaml where the contains some other WORKSPACE path and name.
Query the targets in that WORKSPACE.
Create cpp/hpp files to include some headers files.
Create a new BUILD file, adding the depends on those targets.
My goal is to embed the bash script in the bazel system. I tried with rule + action.run. But the failures are for:
sandbox directory is not readable nor writable.
input files cannot be found in sandbox.
Is there a fancy way to do this? Or any examples I can refer to?
The simple way to do this is with genrule. Something like this in project/BUILD:
genrule(
name = "run_codegen",
srcs = [
"codegen.sh",
"config.yaml",
],
outs = [
"codegen.cpp",
"codegen.hpp",
],
cmd = "$(location codegen.sh) --config $(location config.yaml) --cpp $(location codegen.cpp) --hpp $(location codegen.hpp)",
)
cc_library(
name = "codegen",
hdrs = [ "codegen.hpp" ],
srcs = [ "codegen.cpp" ],
)
Some things to note:
Using $(location) to get the paths for the input and output files. If the script uses relative paths, I'd modify it to take the paths as arguments, or write a wrapper script that creates a temporary directory and moves things to/from there based on flags. The only other reliable way to create paths is with "make" variables, but those are generally harder to work with and more brittle with respect to modifications to the genrule.
Not generating a BUILD file. You can only do this from a repository rule, and it gets significantly more complicated. I don't think you need to for this use case, just write the rule in project/BUILD.
If you want to embed this in a rule instead of using genrule for some reason, make sure you're using File.path to get all the paths to embed in the command. That's the equivalent of $(location). It's hard to be more specific about why your rule doesn't work without seeing a copy of it.

how to change default directory of output files of sass-autocompile in atom

using sass-autocompile in atom it works fine, but I need to change output files(file.min.css). minified files saved to current directory. how can I set for target directory as 'currentPath/minifiedFiles' ?
You can change the setting of the package. But this setting will be applied globally.
Goto "Filename pattern for 'compressed' compiled files" you can change the settings there
Say this is the directory structure
\---app
+---css
| main.scss
|
\---dist
main.min.css
In the file name pattern you can give ../dist/$1.min.css This will compile main.scss and export to 'dist' directory automatically.

How do I get PyCharm File Watcher to maintain my directory structure for SCSS output

I am currently working on getting automatic SCSS -> CSS conversion set up using PyCharm's File Watcher functionality. I am able to have the files output to another directory, but I cannot get them to do it relative to a specific directory. Currently, I have the following settings and relevant file tree:
Tree
|media/
|-c/
| |-css/
| |-folder/
| | |-file2.css
| --file.css
--src/
|-css/
|-folder/
| |-file2.scss
--file.scss
File Watcher Settings
Scope is the media/src/css/ directory and all subdirectories recursively
Arguments is --no-cache --update $FileName$:$ProjectFileDir$/media/c/$FileDirRelativeToProjectRoot$/$FileNameWithoutExtension$.css
Working directory is $ProjectFileDir$/media/src/css/
Output paths to refresh is $ProjectFileDir$/media/c/$FileDirRelativeToProjectRoot$/$FileNameWithoutExtension$.css
With these settings, when I update file2.scss, there is an error stating that media/c/media/src/css/folder does not exist, which is not where I want the file anyway.
The issue that I am having is that I would like to have all paths relative to the working directory root preserved (ie. media/src/css/folder -> media/c/css/folder, but all of my source SCSS files are under multiple folder levels from the project root and the tutorial only specifies how to maintain folder structure if you are compiling directly below the root, not a folder below the root. Does anyone know a way that my folder structure could be preserved so that anything under media/src/css would have the same relative output in media/c/css?
The CrazyCoder posted solution in another Question. It is hard to find, so I'm linking it. https://stackoverflow.com/a/15965088/2047157
Quoting:
The trick is to use $FileDirPathFromParent(dir)$ macro:

Add an existing project to solution folder using PowerShell

I'm working on a PowerShell script to dynamically create and add a Visual Studio project with its folders and assets to a solution.
I'm using Visual Studio DTE.
My directory structure on the file system is the following:
C:\Dir1\Dir2\Stuff
|
+--Stuff <-- folder
| |
| `Stuff.csproj <-- existing project, included in sln
|
+--Subfolder <-- Subfolder in which I want to include my new csproj
| +--Project1 <-- folder
| | |
| | `Project1.csproj <-- existing project, included in sln
| |
| +--Project2 <-- folder
| | |
| | `Project2.csproj <-- existing project, included in sln
| |
| `--Project3 <-- this, subs below and csproj are created from my script
| |
| `Project3.csproj
|
`Stuff.sln
My script creates Subfolder\Project3\Project3.csproj correctly, and I can add it to the solution without any problems, using DTE.
I want, however, to add Project3 in the solution folder 'Subfolder', so it looks like this (dummy image, red arrow shows where I want to have Project3):
How can I accomplish this using Powershell (and optionally EnvDTE)? Any example code would be appreciated. Thanks!
The SolutionFolder interface has an "add from file" method:
http://msdn.microsoft.com/en-us/library/envdte80.solutionfolder.addfromfile
Project AddFromFile(
string FileName
)
So you just need to get a handle to the solution folder. I don't know if you are adding the solution folder through the DTE or it already exists.
If you add it with Solution2.AddSolutionFolder
http://msdn.microsoft.com/en-us/library/envdte80.solution2.addsolutionfolder%28v=vs.110%29.aspx
Project AddSolutionFolder(
string Name
)
It returns a reference to the solution folder and you can just call the above method. If it already exists, I think you'll have to use Solution2.FindProjectItem.
http://msdn.microsoft.com/en-us/library/2zszfd26%28v=vs.110%29.aspx
Something like the following should work. I don't have a way to try it out at the minute so tweaking might be necessary.
Solution solution = System.Activator.CreateInstance(Type.GetTypeFromProgID("VisualStudio.Solution")) as EnvDTE.Solution;
Solution2 sol2 = solution as Solution2;
sol2.Create(solutionPath, solutionName);
Project folder = sol2.AddSolutionFolder("Subfolder");
folder.AddFromFile(pathToProject);
First create a 'Solution Folder' with the desired relative path. Note that Visual Studio 2012 does not create a system folder with the same relative path.
Now inside that 'Solution Folder' add a new project, but you must be careful when defining it that the relative path in the system matches the relative path of your new 'Solution Folder'. If the folder you want does not exist, VS 2012 will now create it for the new project.
If you want to add an existing file with the matching relative path, you must first create the file in the matching system relative path, from outside of VS. Then you can 'add existing file' in Visual Studio.

Resources