I've done a bit of searching and can't find any examples that match my scenario.
I'm trying to create a x-lang module to return some data that we use internally.
My git repo would contain both the powershell and python version of the module, and each module would reference the static data.
I'm struggling to package it in a way that doesn't have a wierd folder structure and works from a python packaging point of view:
the folder structure looks like this (anonymised)
<Root of Repo>
│ .gitignore
│ MANIFEST.in
│ pyproject.toml
│ README.md
│ requirements.txt
│ setup.py
│
├───data
│ 1.json
│ 2.json
│ 3.json
│ 4.json
│
├───src
│ ├───powershell
│ │ │ readme.md
│ │ │ test.ps1
│ │ │ xlangTest.psd1
│ │ │
│ │ ├───classes
│ │ ├───private
│ │ │ get-something1.ps1
│ │ │
│ │ └───public
│ │ Get-DataExample.ps1
│ │
│ └───python
│ │ 1.py
│ │ 2.py
│ │ 3.py
│ │ 4.py
│ │ 5.py
│ │ 6.py
│ │ 7.py
│ │ 8.py
│ │ 9.py
│ │ __init__.py
│ │
│ └───ff.ff.ff.egg-info
│ dependency_links.txt
│ PKG-INFO
│ SOURCES.txt
│ top_level.txt
│
├───tests
│ ├───powershell
│ │ Get-DataExample.tests.ps1
│ │ get-something1.tests.ps1
│ │
│ └───python
and my setup.py looks like this:
import setuptools
with open("README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()
setuptools.setup(
name="ff.ff.ff",
version="0.0.1",
author="ffff",
author_email="david.wallis#fff.fff",
description="An xlang module test",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://ffff/ffff",
project_urls={
"Bug Tracker": "https://ffff/ffff",
},
classifiers=[
"Programming Language :: Python :: 3",
"Operating System :: OS Independent",
],
package_dir={"": "src"},
# data_files={
# "data":['data/*.json'],
# },
# include_package_data = True,
# package_data = {
# "data" : ["../data/*.json"]
# },
packages=setuptools.find_packages(where="src"),
# install_requires=[
# 'readContent',
# 'json',
# ],
python_requires=">=3.6",
)
manifest.IN contains:
graft data
when I package it I end up with the following in the tar file within the tar.gz
C:.
│ ff.ff.ff-0.0.1.tar
│
└───ff.ff.ff-0.0.1
│ #PaxHeader
│
└───ff.ff.ff-0.0.1
│ MANIFEST.in
│ PKG-INFO
│ pyproject.toml
│ README.md
│ setup.cfg
│ setup.py
│
├───data
│ 1.json
│ 2.json
│ 3.json
│ 4.json
│
└───src
├───python
│ 1.py
│ 2.py
│ 3.py
│ 4.py
│ 5.py
│ 6.py
│ 7.py
│ 8.py
│ 9.py
│ __init__.py
│
└───ff.ff.ff.egg-info
dependency_links.txt
PKG-INFO
SOURCES.txt
top_level.txt
I guess what I'm looking for is a sanity check, is this ok, or can I some how flatten the src/python in the distribution or even rename to the module name?
and I suppose the key point here is that I want the data to be common across the two modules. and ultimatley I want to do the same for test cases next.
Related
I am struggling with the implementation of unittest for subdirectories. I have the following project
project
│ README.md
│ __init__.py
│
└───common
│ __init__.py
│ └───my_func
│ │ __init__.py
│ │ func1.py
│ │ func2.py
│
└───scripts
│ __init__.py
│ └───folder_1
│ │ __init__.py
│ │ code1.py
│ │ code2.py
│
│ └───folder_2
│ │ __init__.py
│ │ code3.py
│ │ code4.py
│ │
│ └───tests
│ │ └───test1
│ │ │ __init__.py
│ │ │ test_code3.py
│ │ │ test_code4.py
│ │ │
│ │ └───test2
│ │ │ __init__.py
│ │ │ test_code3.py
│ │ │ test_code4.py
I set the working directory to be ./project. In my code1.py file I import common.my_func.func1 and it runs normally.
Now, I am trying to implement some unittest functions in ./project/scripts/tests. To do so, I am using the coverage package and running the command: coverage run --source=scripts -m unittest discover scripts/tests. However, when doing so, I get the following error:
ModeluNotFoundError: No module named common.my_func
Weirdly speaking, the scripts works perfectly when I try to run it for one test folder only, and not the whole folder coverage run --source=scripts -m unittest discover scripts/tests/test1.
I tried multiple combinations of removing the source, getting more specific with the folder and on. Have any of you faced similar problems with python 3.8?
Thank you very much in advance,
I am trying to generate Sphinx documentation for my Python application. Originally I had a complex structure as follows...
venv
docs
├───source
├───├───_static
├───├───_templates
├───├───conf.py
├───├───index.rst
├───├───modules.rst
├───├───...
├───build
├───make.bat
├───Makefile
├───MyCode
├───├───Utilities
│ │ └───class1.py
├───├───Configurations
│ │ ├───Archive
│ │ ├───API1_Configurations
│ │ │ ├───Config1.ini
│ │ ├───API2_Configurations
│ │ │ ├───Config2.ini
│ │ ├───API3_Configurations
│ │ │ ├───Config3.ini
│ │ ├───API4_Configurations
│ │ │ ├───Config4.ini
├───├───APIs
│ │ ├───API1
│ │ │ ├───Class1.py
│ │ │ ├───Class2.py
│ │ ├───API2
│ │ │ ├───Class1.py
│ │ │ ├───Class2.py
│ │ │ ├───Supporting
│ │ │ │ └───Class1.py
│ │ ├───API3
│ │ │ ├───Support
│ │ │ │ ├───SupportPackage1
│ │ │ │ ├───Support Package2
│ │ │ │ │ └───Class1.py
│ │ │ │ └───__pycache__
│ │ │ └───Class1.py
In this case, my source code exists in ./docs/MyCode.
I am using...
Python 3.8
Sphinx 4.2 (although I've tried with many versions)
NumPy docstrings
I have...
Added the following extensions
sphinx.ext.autodoc
sphinx.ext.apidoc
sphinx.ext.napoleon
Pointed conf.py to my code using both a relative path and absolute path (relative path being ../MyCode).
For some reason, the closest I can get to actually populating the HTML pages with my documentation is simply having the classes in the index toctree. They link out to blank html pages without my Python docstrings.
Does anyone have any idea why it won't grab my docstrings??
Ok... feeling pretty dumb about this, but it was just cause of the warnings.
Sphinx requires that the package is a fully installable package in the sense that when it is placed in the sphinx package, it should be able to compile. I had some absolute references in my import statements which caused my program to fail. As such, the actual docstrings in my program could not be pulled while the names of the classes still showed in my sphinx html.
Basically make sure your code compiles when trying to throw it in Sphinx.
I am converting my python project into packages, with sub-packages, with modules. The tree structure is as shown below (sorry for the long tree). When I run run.py, it imports MyEnvironment.environment which in turn has statements like from station import Station. It is at this stage that I get an error saying ModuleNotFoundError: No module named 'station'. I am not able to figure why this is happening. Note that it work when I do sys.append('.\Environment'), but it should work without it since I already added __init__.py. Could someone help here?
C:.
├───.vscode
│ settings.json
│
└───DRLOD-Package
│ run.py
│ __init__.py
│
├───MyEnvironment
│ │ agv.py
│ │ environment.py
│ │ job.py
│ │ job_queue.py
│ │ parent_area.py
│ │ path_finding.py
│ │ pdnode.py
│ │ policy.py
│ │ request.py
│ │ station.py
│ │ stats.py
│ │ test.py
│ │ __init__.py
```
In environment.py use from .station import Station
For some reason brew install ffmpeg downloads python 3.9 as dependence
==> Installing dependencies for ffmpeg: gnutls, python#3.9, glib, cairo, gobject-introspection, harfbuzz, libass and libvpx
As I can see here https://formulae.brew.sh/formula/ffmpeg there is no dependence on python 3.9
How can I install ffmpeg for my current python Python 3.7.7?
Update:
Maybe something is broken in my python installation?
brew info python
python#3.9: stable 3.9.0 (bottled)
Interpreted, interactive, object-oriented programming language
https://www.python.org/
/usr/local/Cellar/python/3.7.7 (4,165 files, 64.0MB) *
Poured from bottle on 2020-04-03 at 20:11:58
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/python#3.9.rb
License: Python-2.0
==> Dependencies
Build: pkg-config ✔
Required: gdbm ✔, openssl#1.1 ✔, readline ✔, sqlite ✔, xz ✔
==> Caveats
Python has been installed as
/usr/local/bin/python3
Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
/usr/local/opt/python#3.9/libexec/bin
You can install Python packages with
pip3 install <package>
They will install into the site-package directory
/usr/local/lib/python3.9/site-packages
See: https://docs.brew.sh/Homebrew-and-Python
==> Analytics
install: 588,344 (30 days), 666,372 (90 days), 666,373 (365 days)
install-on-request: 104,126 (30 days), 105,703 (90 days), 105,705 (365 days)
build-error: 0 (30 days)
brew info shows python#3.9 but actually it's 3.7.7:
/usr/local/bin/python3 -V
Python 3.7.7
Using brew deps --tree ffmpeg shows the dependancy tree;
Here you can find that the package glib requires python#3.9.
There are some bug reports mentioning this.
You could install ffmpeg without any deps after you manually installed any required deps;
brew install --ignore-dependencies ffmpeg
ffmpeg
├── ...
├── libass
│ ├── freetype
│ │ └── libpng
│ ├── fribidi
│ └── harfbuzz
│ ├── cairo
│ │ ├── fontconfig
│ │ │ └── freetype
│ │ │ └── libpng
│ │ ├── freetype
│ │ │ └── libpng
│ │ ├── glib
│ │ │ ├── gettext
│ │ │ ├── libffi
│ │ │ ├── pcre
│ │ │ └── python#3.9
│ │ │ ├── gdbm
│ │ │ ├── openssl#1.1
│ │ │ ├── readline
│ │ │ ├── sqlite
│ │ │ │ └── readline
│ │ │ └── xz
│ │ ├── libpng
│ │ ├── lzo
│ │ └── pixman
│ ├── freetype
│ │ └── libpng
│ ├── glib
│ │ ├── gettext
│ │ ├── libffi
│ │ ├── pcre
│ │ └── python#3.9
│ │ ├── gdbm
│ │ ├── openssl#1.1
│ │ ├── readline
│ │ ├── sqlite
│ │ │ └── readline
│ │ └── xz
│ ├── gobject-introspection
│ │ ├── cairo
│ │ │ ├── fontconfig
│ │ │ │ └── freetype
│ │ │ │ └── libpng
│ │ │ ├── freetype
│ │ │ │ └── libpng
│ │ │ ├── glib
│ │ │ │ ├── gettext
│ │ │ │ ├── libffi
│ │ │ │ ├── pcre
│ │ │ │ └── python#3.9
│ │ │ │ ├── gdbm
│ │ │ │ ├── openssl#1.1
│ │ │ │ ├── readline
│ │ │ │ ├── sqlite
│ │ │ │ │ └── readline
│ │ │ │ └── xz
│ │ │ ├── libpng
│ │ │ ├── lzo
│ │ │ └── pixman
│ │ ├── glib
│ │ │ ├── gettext
│ │ │ ├── libffi
│ │ │ ├── pcre
│ │ │ └── python#3.9
│ │ │ ├── gdbm
│ │ │ ├── openssl#1.1
│ │ │ ├── readline
│ │ │ ├── sqlite
│ │ │ │ └── readline
│ │ │ └── xz
│ │ ├── libffi
│ │ ├── pkg-config
│ │ └── python#3.9
│ │ ├── gdbm
│ │ ├── openssl#1.1
│ │ ├── readline
│ │ ├── sqlite
│ │ │ └── readline
│ │ └── xz
│ ├── graphite2
│ └── icu4c
├── ...
in Django, my model.py is out of my App modules I want to import all the classes from that model.py to all modules. I searched a lot I didn't get anything can anyone help me
here is my directory
C:
│ manage.py
│ **models.py**
│ mysqlclient-1.4.6-cp39-cp39-win_amd64.whl
│
│
├───myshop
│ │ asgi.py
│ │ settings.py
│ │ urls.py
│ │ wsgi.py
│ │ __init__.py
│ │
├───products
│ │ admin.py
│ │ apps.py
│ │ tests.py
│ │ views.py
│ │ __init__.py
│ │
│ ├───migrations
│ │ │ __init__.py