adamz88
adamz88

Reputation: 319

Where to place custom packages that are being developed in github?

I want to get started developing my own packages. I am also adding version control via Github. I mainly develop on my Mac and a Windows laptop, but there is potential for me to develop on other machines down the line. My IDE of choice is PyCharm. I need to figure out where to place my packages both on Github and on my local machines so that my packages are always in sync regardless of where I am developing. Help??

Upvotes: 0

Views: 666

Answers (1)

Gino Mempin
Gino Mempin

Reputation: 29600

First, let's clarify that git is the version control system, and Github is a platform for hosting git repositories (there are many other platforms aside from Github). You use git commands to manage your codes, and Github is where you store a copy of your codes.

By adding version control and putting a copy on Github, you've already taken the first step in managing your codes on different machines. All you need to do is to make sure the codes on Github is always the latest updated or maintained version.

Here's a sample workflow:

  1. On machine 1 (Mac), clone a copy of the Github repo
  2. Develop on machine 1
  3. When you are satisfied with your changes, push your codes from machine 1 to Github
  4. On machine 2 (Windows), clone a copy of the Github repo
  5. Develop on machine 2
  6. When you are satisfied with your changes, push your codes from machine 2 to Github
  7. On machine 1, do a fetch to check for updates to the code
  8. If there are updates, pull those changes to machine 1
  9. Again, when done making changes, push them from machine 1 to Github
  10. On machine 2 again, fetch and pull changes
  11. Repeat this fetch-pull-push- cycle for all machines

Basically, you'll need to make sure that on wherever machine you are, when you are done, you should always push those changes to the remote (Github). So that other machines, can fetch and pull those changes and continue where you left off.


UPDATE (based on comment):

Once you've got the workflow for your package source codes, next is to package them like any other regular Python package and install them to your site-packages (either directly for your system or preferably in a virtual environment).

I recommend taking a look at the Python docs on Packaging Python Projects which uses setuptools to make your package compatible with pip.

Here's a sample workflow:

  1. git clone <[email protected]> # or git pull if you already cloned it before
  2. cd mypackage
  3. pip install -r requirements.txt
  4. pip install -e . or pip install --user -e .

That last step will install your package to your site-packages folder, like any other pip-compatible package (assuming you've setup your setup.py file properly). If you are using virtual environments, you'll have to activate the virtual env first, then install your package there.

If you are not going to do any modification on the source code, and you just want to install the package on a specific machine, then you can also specify the Github URL to pip:

$ pip install -e git+https://git.repo/some_pkg.git#egg=SomeProject # from git

Lastly, if you are planning to upload this package to PyPi, check out the docs on Uploading the distribution archives. This just adds an extra step to your workflow of uploading your package to PyPi and then doing pip install from there next time.

Upvotes: 1

Related Questions