Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

In a Python file, can I import something from a file in a completely separate repo?

I have a method/function in a file in repo A, and I'm trying to import it in a file in repo B. So at the top of the file in repo B, I have:

from repo_A.folder.folder.File_name import Method

And then I call the method. Will this work, or is there a better way to get it to work?

1 answer

1 accepted

0 votes
Answer accepted

Python imports care about your directory structure. As long as the file is found in the given reference, the import will work.

The recommended approach is to keep your repo (or repos structure) aligned with the directory structure you need, so you can just clone/checkout once and build your project on any machine, including other developers' machines and CI machines.

If your repo_A is depended on repo_B, consider one of the following options:

1. Merge the repos into one.

2. Use git sub-module or sub-tree.

3. Include repo_B's artifact as a dependency in repo_A - download the binary from artifactory or other binary server. In this option the `import` will be a bit different.  

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events