I have a private repo on GitHub containing a Poetry package which I install with
poetry add git+https://github.com/<USERNAME>/<REPO>.git#<BRANCH>
This project's structure is (assume it's called package_1)
├── README.md
├── package_1
│ ├── __init__.py
│ ├── subpackage_1
│ │ ├── __init__.py
│ │ └── subpackage_1.py
│ ├── subpackage_2
│ │ ├── __init__.py
│ │ └── subpackage_2.py
│ └── subpackage_3
│ ├── __init__.py
│ └── subpackage_3.py
├── poetry.lock
├── pyproject.toml
└── tests
├── __init__.py
└── test_package_1.py
package_1/init.py is just __version__ = "0.3.3"
When I run poetry add git+https://github.com/<USERNAME>/<REPO>.git#<BRANCH> on a new package, the package_1 package is correctly installed but two things happen which I don't understand:
1: The new package's pyproject.toml file shows package_1's version as 0.2.0 when clearly the version is 0.3.3 as mentioned above;
2: The poetry.lock file looks like this after I install package_name
[[package]]
name = "package-name"
version = "0.2.0"
...
Why is the name package-name instead of package_name (notice the _ and -)?
Related
Here's my project structure:
├── compute_completeness_service
│ ├── __init__.py
│ ├── app.py
│ ├── tests
│ │ ├── integration
│ │ │ ├── __init__.py
│ │ │ └── test__init__.py
│ │ └── unit
│ │ ├── __init__.py
│ │ ├── __pycache__
│ │ └── test_utils.py
│ └── utils
│ ├── __init__.py
│ └── __pycache__
├── data_quality
│ ├── __init__.py
│ ├── app.py
│ ├── helpers
│ │ ├── __init__.py
│ └── tests
│ └── unit
│ ├── __init__.py
│ ├── __pycache__
│ └── test_helpers.py
I can run these commands from compute_completeness_service and data_quality's root directory:
python3 -m unittest discover -v -s ./compute_completeness_service/tests -p "test_*.py"
python3 -m unittest discover -v -s ./data_quality/tests -p "test_*.py"
but is there one command to run both of them? Because when I run this command, I get no tests:
python3 -m unittest discover -v -t . -p "test_*.py"
----------------------------------------------------------------------
Ran 0 tests in 0.000s
TIA!
Thanks to #MrBean Bremen's comment, I realized that I forgot to add __init__.py to the tests directories
Once added the test discovery worked as expected.
I have package structure like this:
└── src
├── my_program.py
├── mynamespace-packageone
│ ├── mynamespace
│ │ └── subpackage_one
│ │ ├── __init__.py
│ │ └── first.py
│ ├── mynamespace_packageone.egg-info
│ │ ├── PKG-INFO
│ │ ├── SOURCES.txt
│ │ ├── dependency_links.txt
│ │ └── top_level.txt
│ └── setup.py
└── mynamespace-packagetwo
├── mynamespace
│ └── subpackage_two
│ ├── __init__.py
│ └── second.py
├── mynamespace_packagetwo.egg-info
│ ├── PKG-INFO
│ ├── SOURCES.txt
│ ├── dependency_links.txt
│ └── top_level.txt
└── setup.py
in setup.py in subpackage_one,
from setuptools import setup, find_namespace_packages
PACKAGE = "mynamespace-packageone"
VERSION = "0.1"
setup(
name=PACKAGE,
version=VERSION,
packages=find_namespace_packages(include=["mynamespace.*"]),
description="subpackage_one"
)
in in setup.py in subpackage_two,
from setuptools import setup, find_namespace_packages
PACKAGE = "mynamespace-packagetwo"
VERSION = "0.1"
setup(
name=PACKAGE,
version=VERSION,
packages=find_namespace_packages(include=["mynamespace.*"]),
description="subpackage_two"
)
I use pip to install these two packages in edit mode
pip install -e src/mynamespace-packageone/
pip install -e src/mynamespace-packagetwo/
in my_program.py
I was trying to import mynamespace.subpackage_one
import mynamespace.subpackage_one
but the syntax shows cannot find module mynamespace.
I cannot figure out what is wrong.
Please help.
Thanks,
Arthur
I have this project architecture and I want to make my_package pip installable. The project doesn't only contain stuff to package but also simple scripts (the quick and dirty kind) and over things that are important in my project but not for the package (external data for example).
my_project
├── code
│ ├── data #<-- I don't want to package this
│ │ └── make_dataset.py
│ ├── script #<-- I don't want to package this
│ │ └── make_experiment.py
│ └── my_package #<-- This is the module I want to package
│ ├── core.py
│ ├── utils.py
│ └── __init__.py
├── data
│ └── some_data.txt
├── references
│ └── reference_paper.pdf
├── reports
│ └── report.tex
├── LICENSE
├── README.md
├── requirements.txt
└── setup.py
I would like the setup.py file to be in the top-level directory so that people can do the usual
git clone gitinstance.com/my_project
cd my_project
pip install .
and get my_package module installed in their environment so they can already do python -c import my_package; print(my_package.__version__) and it works.
The question is: How can I make my_package pip-installable without putting setup.py inside the code directory?
Usually, the setup.py would look like this:
from setuptools import find_packages, setup
setup(
name='my_package',
packages=find_packages(),
version='0.1.0',
description='Research project',
author='Name',
license='MIT',
)
But it wouldn't work here because setup.py can't find my_package.
I found an example in the documentation of setuptools that more or less fit my use-case.
The solution is in the packages and package_dir arguments of the setup function that allows to specify where to find the packages to install. This is usually hidden because it defaults to the current working directory.
In my simple case, the setup.py transforms to:
from setuptools import find_packages, setup
setup(
name='my_package',
packages=find_packages(where="code"),
package_dir={'': "code"},
version='0.1.0',
description='Research project',
author='Name',
license='MIT',
)
I'm writing a python module and want to install it. The structure is as follows:
look-up
├── look-up
│ ├── utilities
│ │ ├── __init__.py
│ │ ├── validator.py
│ └── __init__.py
├── README.md
├── requirements.txt
├── setup.py
└── MANIFEST.in
setup.py looks like this:
from setuptools import setup, find_packages
from codecs import open
from os import path
here = path.abspath(path.dirname(__file__))
with open(path.join(here, 'README.md'), encoding='utf-8') as f:
long_description = f.read()
setup(
name = 'look_up',
version = '0.0.1',
packages = find_packages(),
)
Afte i run:
python setup.py develop
and try to import it it I get the error:
No module named 'look_up'
Can someone help me what I'm doing wrong?
I have installed aldryn-segmentation using pip and am trying to install aldryn-country-segment using pip install https://github.com/aldryn/aldryn-country-segment/archive/master.zip as the documentation suggests.
However I get an error that it could not find a version that satisfies the requirement aldryn-geoip.
Collecting aldryn-geoip (from aldryn-country-segment==0.7.2)
Could not find a version that satisfies the requirement aldryn-geoip (from aldryn-country-segment==0.7.2) (from versions: )
No matching distribution found for aldryn-geoip (from aldryn-country-segment==0.7.2)
or when downloading file and running python setup.py install it gives me this: (after lots of other text)
Processing dependencies for aldryn-country-segment==0.7.2
Searching for aldryn-geoip
Reading https://pypi.python.org/simple/aldryn-geoip/
Couldn't find index page for 'aldryn-geoip' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading https://pypi.python.org/simple/
No local packages or download links found for aldryn-geoip
error: Could not find suitable distribution for Requirement.parse('aldryn-geoip')
Is there an obvious workaround to this?
Download and save the file somewhere in your system.
Then unzip it and cd to the directory. You'll get something like this:
.
├── addon.json
├── aldryn_config.py
├── country_segment
│ ├── cms_plugins.py
│ ├── __init__.py │ ├── locale
│ │ └── fr
│ │ └── LC_MESSAGES
│ │ ├── django.mo
│ │ └── django.po
│ ├── middleware
│ │ ├── __init__.py
│ │ └── resolve_country_code_middleware.py
│ ├── migrations
│ │ ├── 0001_initial.py
│ │ └── __init__.py
│ ├── models.py
│ └── south_migrations
│ ├── 0001_initial.py
│ └── __init__.py
├── LICENSE.txt
├── README.md
├── schemamigration.py
└── setup.py
7 directories, 17 files
Then run sudo python setup.py install and python will install the package to your system.
You may need to install aldryn-geoip as dependency too. (using the same way)