8000 add branching and submodule imports by rmorshea · Pull Request #1 · ellisonbg/antipackage · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

add branching and submodule imports #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 47 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
7fc4cd7
add ability to select branches and trace subpackages to reach a file …
rmorshea Dec 18, 2014
7b31500
update for branching and subpackages
rmorshea Dec 18, 2014
3cc0745
small bug fix for error handling
rmorshea Dec 18, 2014
2a2fe5d
asd
rmorshea Dec 18, 2014
fce3022
unexpected error
rmorshea Dec 18, 2014
9e9e909
add explanitory markdown for error
rmorshea Dec 18, 2014
6807e90
create GitHubBrancher which inherits from the standard GitHubImporter
rmorshea Jan 14, 2015
e243217
function name change
rmorshea Jan 14, 2015
89b3bde
file for documentation purposes
rmorshea Jan 14, 2015
3dbc017
none
rmorshea Jan 14, 2015
5265c90
formating
rmorshea Jan 14, 2015
05e31a0
none
rmorshea Jan 14, 2015
f354763
remove Testing.ipynb
rmorshea Jan 14, 2015
b7fb637
quick instruction on using the Brancher for branching and submodule a…
rmorshea Jan 14, 2015
0f8fc5c
new info on branching and submodules
rmorshea Jan 15, 2015
0387537
corrections
rmorshea Jan 15, 2015
8eba7b9
error message fix
rmorshea Jan 20, 2015
0c15230
add ability to switch from brancher to importer
rmorshea Jan 25, 2015
631bc4c
trip functions
rmorshea Apr 6, 2015
2c15c0b
revamp importer, include pins, package restructure
rmorshea Apr 30, 2015
49855cb
revamp importer, include pins, package restructure
rmorshea Apr 30, 2015
2502733
update usage info
rmorshea Apr 30, 2015
2fe8cb4
update usage info
rmorshea Apr 30, 2015
7e7d71f
move pinning setup
rmorshea Apr 30, 2015
b01f465
check if pin already exists
rmorshea Apr 30, 2015
d4d503c
general update
rmorshea Apr 30, 2015
f8e30c5
general update
rmorshea Apr 30, 2015
71d1822
update setup
rmorshea Apr 30, 2015
d3aca0b
update output
rmorshea Apr 30, 2015
d12aa90
description edits
rmorshea Apr 30, 2015
a8c3901
description edits
rmorshea Apr 30, 2015
893df9c
description edits
rmorshea Apr 30, 2015
3ef40a0
description edits
rmorshea Apr 30, 2015
cdb08c8
description edits
rmorshea Apr 30, 2015
e373771
renaming and rework _base_dir
rmorshea May 4, 2015
1fbdf30
object oriented restructure
rmorshea May 9, 2015
26db3e2
doc updates
rmorshea May 9, 2015
704d11d
add utilities and streamline objs
rmorshea May 12, 2015
7c003ff
finalize object orgastructure and fix/name import_replacement
rmorshea May 19, 2015
5e73577
update for rebase
rmorshea May 19, 2015
2305809
small doc edits
rmorshea May 20, 2015
3ca059c
small edit in main docstring
rmorshea May 20, 2015
bd96127
remove redundant import
rmorshea Jun 17, 2015
a53342b
bugfix branch updates
rmorshea Jul 17, 2015
8789d43
update to PY3
rmorshea Mar 10, 2017
1feaddc
Update README.md
rmorshea Apr 6, 2019
c5c6004
Update antipackage.py
rmorshea Apr 6, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 85 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
AntiPackage
===========

Automagically import single file Python modules from GitHub.
Automagically import lightweight Python packages from GitHub.

## Installation

The `antipackage` package can be installed from GitHub using `pip`:
`antipackage` can be installed from GitHub using `pip`:

```
pip install git+https://github.com/ellisonbg/antipackage.git#egg=antipackage
pip install git+https://github.com/rmorshea/antipackage.git#egg=antipackage
```

## Usage
## Basic Usage

Enable `antipackage` by simply importing it:

```python
import antipackage
import antipackage as apkg
```

Once `antipackage` has been imported you can simply import modules from GitHub using the syntax:
Expand All @@ -25,16 +25,88 @@ Once `antipackage` has been imported you can simply import modules from GitHub u
from github.username.repo import module
```

When you do this, the import hook will automatically download and install single file
Python modules into the location `~/.antipackage/github/username/repo/module.py`. If the
module every changes on GitHub it will be updated next time you import it.
When you do this, the import hook will automatically download and install the whole GitHub repository
into the location `~/.antipackage/github/username/repo`. Thus antipackage can support modules with
relatively lightweight dependancies. If the repository ever changes on GitHub it will be updated the
next time you import it.

## Absolute imports
## Pinning

The `antipackage` package is written looking forward to the days when Python 2 is no longer
supported. Because of this, the import hooks used in `antipackage` assume that relative imports
are not used in the single file modules that are being imported. To enable this behavior for Python 2,
add the following line at the top of your modules:
The alternate way to import with antipackage is with pins. Pinning allows for a repo to be retrieved
from a particular branch, tag, or commit during all future imports. By default antipackage will tag a
repo with a branch pin to 'master'. Marking a repo with a branch pin will cause antipackage to pull
from the most recent version found on that branch. However marking a repo with a sha or tag pin will
force antipackage to draw on the version of the repository which corrisponds to that particular commit.

To enable this functionality, use `pin` by giving a path along with a pin type and value:

```python
apkg.pin('github/username/repo', sha='0158d2c0824e7162c1721174cb967d9efbfbbdb0')
```

Similarly, you access pinning data using `data` by giving a path to the information you need.
Thus paths can also retrieve specific data attributes by extending it into the pin itself:

```python
# returns all pinning data
apkg.data()
```

or

```python
# returns the pin for a repo
apkg.data('github/username/repo)

# the path to 'sha' holds the sha string
# the repo is currently associated with
apkg.data('github/username/repo/commit/sha')

# the path to 'url' holds the url which
# the sha string was sourced from
apkg.data('github/username/repo/commit/url')

# the 'branch' and 'tag' paths hold the
# branch or tag name respectively if
# that's what the repo is associate with
apkg.data('github/username/repo/tag')
apkg.data('github/username/repo/branch')
```

If no data is present at the given path then an empty dictionary will be returned without an error.

## Import Replacements
The method `import_replacement` allows for substitutions in import statements. This resolves an issue
where one might want to download a repository whose name includes a reserved character. For example,
the following import statement is invalid due to the inclusion of the "-" character:

```python
import github.jdfreder.ipython-d3networkx
```

To get around this problem we make an import replacement along with a revised import statement:

```python
apkg.import_replacement('ipython_d3networkx','ipython-d3networkx')
import github.jdfreder.ipython_d3networkx
```

The method `import_replacement` substitutes the value, `'ipython-d3networkx'`, in for **all** instance
of the key, `'ipython_d3networkx'`, in subsiquent import statements until the rule is removed by calling:

```python
apkg.import_replacement('ipython_d3networkx', remove=True)
```

Thus import statements which would normally require reserved characters can be made valid while
still pointing to the intended repository. It should be noted that the sweeping application of the
method means specific replacements should be made a habbit.

## Absolute Imports
`antipackage` is written looking forward to the days when Python 2 is no longer
supported. Because of this, the import hooks used in `antipackage` assume that relative imports are not
used in the single file modules that are being imported. To enable this behavior for Python 2, add the
following line at the top of your modules:

```python
from __future__ import absolute_import
Expand Down
Loading
0