简体   繁体   中英

Python setuptools: How can I add a private repository (gitlab) in my setup.py?

I have 2 package uploaded which are in my gitlab repository, if I want to install them in my system using pip, it's easy because gitlab helps you:

https://docs.gitlab.com/ee/user/packages/pypi_repository/index.html

pip install <package-name> --extra-index-url https://<username>:<your_personal_token>@gitlab.com/api/v4/projects/<project ID>/packages/pypi/simple

the name of those two package:

  • core_1
  • service_1

What I want it's to create other package where it download those two private package and I need to configurate in setup.py:

this is my setup.py

from setuptools import setup, find_packages

setup(
name='my_project',
version='0.1.0',
packages=find_packages(),
package_data = {
    'config':['*.yaml']
    },
include_package_data=True,
install_requires=[
    'click', 
    'colorama',
    'core_1 --extra-index-url https://joelbarrantespalacios:<personal_token>@gitlab.com/api/v4/projects/<project_ID>/packages/pypi/simple',
    'service_1 --extra-index-url https://joelbarrantespalacios:<personal_token>@gitlab.com/api/v4/projects/<project_ID>/packages/pypi/simple'
],
entry_points={
    'console_scripts': [
        'darit = core_project.cli:start',
    ],
},

)

of course, <personal_token> and <project_ID> needs to be add however I'm not giving you because it's a private package.

joelbarrantespalacios : it's my username

this is what I found in setuptools's Documentation where it shows how to create a Dependencies that aren't in PyPI, but it's not clear for me

https://setuptools.pypa.io/en/latest/userguide/dependency_management.html

I really need you helps guys, give me some hope.

You should add the index/authentication information to a pip.cfg file or ~/.pypirc file.

Using a ~/.pypirc file:

[gitlab]
repository = https://gitlab.example.com/api/v4/projects/<project_id>/packages/pypi
username = <username>
password = <token>

Where <token> is an API token with API scope. Alternatively, provide the index/auth information to pip when installing your packages.

Your setup.py dependencies should simply declare the name of the package. eg

# ...
install_requires=[
    'core_1',
    'service_1',
#...

pip will resolve it from the configured registries in your pip.cfg or .pypirc file (or pip CLI options) automatically.

Your setup.py gets bundled with your package when it is uploaded to the registry and is downloaded by its users, so it obviously shouldn't contain sensitive information like your passwords/tokens anyhow!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM