Anywhere GitHub Repository Importer
Project description
Anywhere GitHub repository import (Agri)
Happen to you that as a researcher, machine learning practitioner, you run multiple versions of your code in different places? like colab, kaggle, your computer. I had the same problem, so I created this package to help me, and maybe us, to overcome this problem by downloading the repository from GitHub (for private you need to provide a token), and work with it. Then if you want to change something, do it on your computer and push it, then update it in the code.
Have an idea?
raise an ISSUE.
Import the package
import agri
agri.authenticate("__token__")
my_repo = agri.import_repo("mmaleki92/test_repo")
print(agri.get_repo_structure("test_repo"))
Happy researching.
Simple Guide
A simple guide to using the repository browser to work with GitHub repositories.
Table of Contents
Quick Start
Here's a simple example to get started:
# Import the library
import agri
# Authenticate with your GitHub token
agri.authenticate("your_github_token")
# Import a repository
my_repo = agri.import_repo("username/repo_name")
# Access a Python file or module
my_module = my_repo.folder.module_name # Automatically looks for module_name.py
# Use functions from the module
result = my_module.some_function()
Basic Operations
Importing a Repository
# Import a repository
my_repo = agri.import_repo("username/repo_name")
# Import a specific branch
dev_branch = agri.import_repo("username/repo_name", branch="development")
Viewing Repository Structure
# Show repository structure during import
my_repo = agri.import_repo("username/repo_name", show_structure=True)
# View structure of an already imported repository
structure = agri.get_repo_structure("username/repo_name")
print(structure)
# List all imported repositories
repos = agri.list_imported_repos()
print(repos)
Exploring Repository Contents
# List top-level folders and files
print(dir(my_repo))
# Navigate through directories
print(dir(my_repo.src))
print(dir(my_repo.src.utils))
Updating a Repository
# Update to get latest changes
updated_repo = agri.update_repo("username/repo_name")
Working with Files
Accessing Python Files
Files are lazily loaded - they're only executed when you access them:
# Access a module (this will execute the Python file)
helper = my_repo.src.utils.helper # Automatically finds helper.py
# Use functions or classes from the module
result = helper.process_data(my_data)
Reading File Contents Without Execution
import os
# Get file path without executing code
file_path = os.path.join(my_repo.__path__, "README.md")
# Read content
with open(file_path, 'r') as f:
content = f.read()
print(content)
Committing Changes
Creating a New File
# Create and commit a new file
agri.create_file_and_commit(
"username/repo_name",
file_content="print('Hello, world!')",
repo_file_path="examples/hello.py",
message="Add hello world example"
)
Committing Local Files
# Commit a single file
agri.commit_files(
"username/repo_name",
local_source="/path/to/local/file.py",
repo_target="src/utils/file.py",
message="Add utility file"
)
# Commit multiple files
agri.commit_files(
"username/repo_name",
local_source={
"/path/to/file1.py": "src/file1.py",
"/path/to/file2.py": "src/file2.py"
},
message="Add multiple files"
)
Deleting Files
# Delete a file or directory
agri.delete_files_and_commit(
"username/repo_name",
repo_file_paths="old_file.py",
message="Remove old file"
)
# Delete multiple files/directories
agri.delete_files_and_commit(
"username/repo_name",
repo_file_paths=["file1.py", "old_folder/"],
message="Remove unused files"
)
Example Workflow
Here's a complete example workflow:
import agri
# Step 1: Authenticate
agri.authenticate("your_github_token")
# Step 2: Import a repository
my_repo = agri.import_repo("username/my-project")
# Step 3: Navigate and use repository contents
config = my_repo.src.config # Access config.py file
settings = config.DEFAULT_SETTINGS # Get a variable from the file
# Step 4: Make changes and commit them
agri.create_file_and_commit(
"username/my-project",
file_content=f"""
# Updated configuration
DEFAULT_SETTINGS = {settings}
DEBUG = True
""",
repo_file_path="src/config.py",
message="Update configuration settings"
)
That's it! This quick guide covers the basics of working with repositories, accessing files, and committing changes.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agri-0.1.2.tar.gz.
File metadata
- Download URL: agri-0.1.2.tar.gz
- Upload date:
- Size: 13.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5f2ecdec0224816021f2e2b5a5e849766ca76f73999e281876f22f3d22bc3c2
|
|
| MD5 |
57483400f885a8313f1a7e7c1422c301
|
|
| BLAKE2b-256 |
0a698c3681871f43b1d1431ca4072b4a4f9d4bf98706312500e85c007e3a9d0b
|
Provenance
The following attestation bundles were made for agri-0.1.2.tar.gz:
Publisher:
python-publish.yml on mmaleki92/agri
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agri-0.1.2.tar.gz -
Subject digest:
e5f2ecdec0224816021f2e2b5a5e849766ca76f73999e281876f22f3d22bc3c2 - Sigstore transparency entry: 209873474
- Sigstore integration time:
-
Permalink:
mmaleki92/agri@47a66ee450c61bb1628b421daacb956246866a93 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/mmaleki92
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@47a66ee450c61bb1628b421daacb956246866a93 -
Trigger Event:
release
-
Statement type:
File details
Details for the file agri-0.1.2-py3-none-any.whl.
File metadata
- Download URL: agri-0.1.2-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9103dc2e556aa27d3e4b6cb9e4e56efc569a289b648678e072eafdb9a821d21b
|
|
| MD5 |
fa751ae1eca92152e0379ad1b49c4e95
|
|
| BLAKE2b-256 |
37ac6b621ab139f0481fd85bfa379dfc5570c4ba367129f3a099b959f0631257
|
Provenance
The following attestation bundles were made for agri-0.1.2-py3-none-any.whl:
Publisher:
python-publish.yml on mmaleki92/agri
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agri-0.1.2-py3-none-any.whl -
Subject digest:
9103dc2e556aa27d3e4b6cb9e4e56efc569a289b648678e072eafdb9a821d21b - Sigstore transparency entry: 209873478
- Sigstore integration time:
-
Permalink:
mmaleki92/agri@47a66ee450c61bb1628b421daacb956246866a93 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/mmaleki92
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@47a66ee450c61bb1628b421daacb956246866a93 -
Trigger Event:
release
-
Statement type: