24

How can I define a private GitHub repo as a dependency in the project section of my pyproject.toml file?

[project] dependencies = [ "my_repo_name>=<SSH-address_to_my_private_github_repo>" ] 
2
  • This should help Commented Aug 8, 2022 at 8:26
  • 3
    What is the build back-end used in this project? Setuptools or something else? Commented Sep 1, 2022 at 17:52

1 Answer 1

39

How about something like:

[tool.hatch.metadata] allow-direct-references = true [project] dependencies = [ "my_pkg_name @ git+ssh://[email protected]/my-github-name/my_repo", ] 

Explanation:

@EDG956 and @sinoroc pointed at docs on how to do this if you're using poetry, but I don't think you are: your example has a [project] section rather than a [tool.poetry.dependencies] section, so I'm guessing you're using pyproject.toml with setuptools directly — as described here.

That page refers to PEP 621, whose section on dependencies says:

For dependencies, it is a key whose value is an array of strings. Each string represents a dependency of the project and MUST be formatted as a valid PEP 508 string.

Then, the "Examples" section of PEP 508 shows an example which I've used as the basis of my suggestion above.

(As usual, you can use @<tag> or @<sha>, or #<branch_name> suffixes, etc.)

Sign up to request clarification or add additional context in comments.

3 Comments

Right, I do not know why I assumed it is about Poetry. Thanks for rectifying. -- If I recall correctly, it should also be noted that such "direct references" will be rejected by PyPI (and maybe some other index servers as well).
Don't forget to add the following settings to the pyproject.toml [tool.hatch.metadata] allow-direct-references = true
added your important suggestion to the answer, @MartijntenHoor - it doesn't work w/o it - thank you!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.