python pdoc the whole project - python

lately i've started using pdoc3 to document my whole project,
right now i have a problem generating a HTML that contain the whole project in 1 command, and not going every.py file one by one
the project structure is like this:
--pythonProject
| file_a.py
| file_b.py
--folder
| file_c.py
| file_d.py
--docs
i tried the following command : pdoc --html .\file_a.py --output-dir docs --force and it genetrates the following file in docs folder -> file_a.html
and when using this pdoc --html .\ --output-dir docs --force i receive error for pytest library that not even in the project
i wanted to know if there is a command to generate the whole project (im using PyCharm)
thanks alot :)

Related

Google Cloud Buildpack custom source directory for Python app

I am experimenting with Google Cloud Platform buildpacks, specifically for Python. I started with the Sample Functions Framework Python example app, and got that running locally, with commands:
pack build --builder=gcr.io/buildpacks/builder sample-functions-framework-python
docker run -it -ePORT=8080 -p8080:8080 sample-functions-framework-python
Great, let's see if I can apply this concept on a legacy project (Python 3.7 if that matters).
The legacy project has a structure similar to:
.gitignore
source/
main.py
lib
helper.py
requirements.txt
tests/
<test files here>
The Dockerfile that came with this project packaged the source directory contents without the "source" directory, like this:
COPY lib/ /app/lib
COPY main.py /app
WORKDIR /app
... rest of Dockerfile here ...
Is there a way to package just the contents of the source directory using the buildpack?
I tried to add this config to the project.toml file:
[[build.env]]
name = "GOOGLE_FUNCTION_SOURCE"
value = "./source/main.py"
But the Python modules/imports aren't set up correctly for that, as I get this error:
File "/workspace/source/main.py", line 2, in <module>
from source.lib.helper import mymethod
ModuleNotFoundError: No module named 'source'
Putting both main.py and /lib into the project root dir would make this work, but I'm wondering if there is a better way.
Related question, is there a way to see what project files are being copied into the image by the buildpack? I tried using verbose logging but didn't see anything useful.
Update:
The python module error:
File "/workspace/source/main.py", line 2, in <module>
from source.lib.helper import mymethod
ModuleNotFoundError: No module named 'source'
was happening because I moved the lib dir into source in my test project, and when I did this, Intellij updated the import statement in main.py without me catching it. I fixed the import, then applied the solution listed below and it worked.
I had been searching the buildpack and Google cloud function documentation, but I discovered the option I need on the pack build documentation page: option --path.
This command only captures the source directory contents:
pack build --builder=gcr.io/buildpacks/builder --path source sample-functions-framework-python
If changing the path, the project.toml descriptor needs to be in that directory too (or specify with --descriptor on command line).

Python Package path management

I am trying to create a simple package for my python code. Here is the structure I have created:
.test_dive_software
| measurements
| mytxt.txt
| mycode
| __init__.py
| mycode.py
| README.txt
| setup.py
Now, the mycode.py file when executed needs to access the mytxt.txt file to load some data.
The process I am doing to build the package is pip install . and then I run the command I have set (mycode-exec) in the setup.py file as the entry point (I am using setuptools).
My problem is this:
In order to access the txt file from mycode.py, I use the command path=str(os.getcwd()).
When I try to run my code (after I have built the package) by double clicking the mycode.py icon, the path=str(os.getcwd()) command returns the .test_dive_software\mycode directory, from where I can access the measurements folder.
When I execute my program as described above, through the mycode-exec command, the path=str(os.getcwd()) returns the current directory I happen to be in, and not that of the mycode.py file.
Is there a way to achieve consistency in my program, so that it can work fine, no matter how it is executed?

ModuleNotFoundError - Import module from specific directory

I have the following folder structure for my Python project (in Pycharm):
Tool
|___Script
|___logs
|___ tests
| |___setA
| |___setB
| |___setC
| |___testSetC.py
|___ __init__.py
|______script.py
and I'm trying to import methods defined in script.py in testSetC.py.
I have from Script.script import * at the top of testSetC.pyand the script runs without any issues inside Pycharm. However, when I tried to run the same from the command line, it failed with the error message ModuleNotFoundError: No module named 'Script'.
I poked around and found that Pycharm's run configuration automatically adds the Tool directory to PYTHONPATH essentially masking the error.
What is the correct way to do this without manually amending sys.path in every test script? It looks hackish IMO.

Sphinx autodoc not importing anything?

I'm trying to use sphinx (in conjunction with autodoc and numpydoc) to document my module, but after the basic setup, running make html produces just the basic html with nothing from the docstrings included. I'm running Python 3.3, the outline of the project structure is as follows:
Kineticlib
|--docs
| |--build
| |--source
| | |--conf.py
|--src
| |--kineticmulti
| | |--__init__.py
| | |--file1.py
| | |--file2.py
|--setup.py
__init__.py is empty, and in conf.py in the docs/source directory I've added sys.path.insert(0, os.path.abspath('../..'))
Running make html in the docs directory gives the following output:
sphinx-build -b html -d build/doctrees source build/html
Running Sphinx v1.2.2
loading pickled environment... done
building [html]: targets for 0 source files that are out of date
updating environment: 0 added, 0 changed, 0 removed
looking for now-outdated files... none found
no targets are out of date.
Build finished. The HTML pages are in build/html.
So, what am I doing wrong?
Did you run sphinx-apidoc in the docs/source directory? This will generate the .rst files used to make the html. From man sphinx-apidoc,
sphinx-apidoc [options] -o <outputdir> <sourcedir> [pathnames ...]
You'll need to include (at a minimum) the outputdir (where the .rst files will go, ./ should work) and the sourcedir which should point to your package (looks like ../../src/kineticmulti should work)
As it is being said you should do:
sphinx-apidoc [options] -o <outputdir> <sourcedir> [pathnames ...]
Sometime modifying your conf.py to import some source modules are also needed. As well as adding some docs to class in order to load its method docs (can be true only for private classed, but I've been stuck on that).

Add django project to python path when developing with pycharm 3.0 community edition Windows7

I created a new Django project using the cmd line. The directory structure was the following
--src
|___project_name
|
|__project_folder
| |
| |__settings.py etc
|
|__some_app
|
|__another_app
etc...
I opened my Django project using open directory.
But when I am inside an app(lets say some_app) and try to import another_app.models pycharm editor does see it as an error, thus making it red underlined. But when i run it it works fine. I guess I should have openned the project_name directory and not the src directory above. How can i solve this issue?
I went to settings in my project interpreter but won't let me manually add my paths.

Categories