Reputation: 1765
I have a private python package, hidden
. In that package, I'd like to use another private package of mine, zempy
.
In hidden's requirements, there is a line
git+https://gitlab.com/group/[email protected]#egg=zempy
...which I've also tried writing as:
-e git+https://gitlab.com/group/[email protected]#egg=zempy
And I'm installing hidden with python3 -m pip install .
or python3 -m pip install -e .
(in hidden's main directory)
But I got an error:
error in hiddenco setup command: 'install_requires' must be a string or list of strings containing valid project/version requirement specifiers; Parse error at "'-e git+h'": Expected W:(abcd...)
This seemed like working before. Suddenly it stopped working. Anyone has an idea? I have tried nearly everything in that requirements line. It's installing without that line. But I need zempy in hidden.
I have double checked install_requires parameter in setup. It is a list of string.
The setup.py
in hidden:
"""Setuptools for hidden package."""
from glob import glob
from os.path import basename, splitext
import setuptools
from setuptools import setup
def readme():
"""Return readme as string."""
with (open('README.md')) as f:
return f.read()
def get_requirements():
"""
Return requirements as list.
package1==1.0.3
package2==0.0.5
"""
with open('requirements.txt') as f:
return [line.replace('\n', '') for line in f.readlines()]
setup(
name='hiddenco',
long_description=readme(),
packages=setuptools.find_packages('src'),
package_dir={'': 'src'},
install_requires=get_requirements(),
py_modules=[splitext(basename(path))[0] for path in glob('src/*.py')],
include_package_data=True,
zip_safe=False,
python_requires='>=3.6, !=3.9.*, !=3.10.*'
)
And the requirements.txt
:
coloredlogs
pymongo >=3.7.2
fasttext==0.9.2
pytest >=6.1.2
pandas <=1.5.0
numpy >=1.16.1, <=1.19.5
-e git+https://gitlab.com/group/[email protected]#egg=zempy
Upvotes: 3
Views: 2790
Reputation: 189387
Your get_requirements
function needs to return just a list of package names and (optional) versions. install_requires
merely documents which packages and versions are required; it does not support specifying where or how to obtain them.
A quick and dirty fix is to just discard the extra information you crammed in there.
def get_requirements():
"""
Return requirements as list.
package1==1.0.3
package2==0.0.5
"""
with open('requirements.txt') as f:
packages = []
for line in f:
line = line.strip()
# let's also ignore empty lines and comments
if not line or line.startswith('#'):
continue
if 'https://' in line:
tail = line.rsplit('/', 1)[1]
tail = tail.split('#')[0]
line = tail.replace('@', '==').replace('.git', '')
packages.append(line)
return packages
This pulls out .../[email protected]
and converts it to zempy==0.4.7
.
Upvotes: 5