Skip to content

Commit

Permalink
Implement initial features (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
douglaslassance authored Mar 20, 2022
1 parent 4c280db commit 2ef6c25
Show file tree
Hide file tree
Showing 33 changed files with 1,793 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true

# Python
[*.py]
indent_style = space
indent_size = 4
max_line_length = 88

# YAML
[*.yaml]
indent_style = space
indent_size = 2

# JSON
[*.json]
indent_style = space
indent_size = 4
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length = 88
exclude = .git,__pycache__,docs/source/conf.py,old,build,dist
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: ["douglaslassance"]
27 changes: 27 additions & 0 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: CD

on:
release:
types: [created]

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.x"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Publish on PyPI
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload --verbose dist/*
37 changes: 37 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
name: Test
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install requirements
run: |
python -m pip install --upgrade pip
pip install --editable ".[ci]"
- name: Lint with flake8
run: |
flake8 . --count --show-source --statistics
- name: Test with pytest
run: |
pytest --cov=gitalong
- name: Document with sphinx
run: |
sphinx-build ./docs/source ./docs/build
- name: Upload report on CodeCov
run: |
bash <(curl -s https://codecov.io/bash)
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,12 @@ dmypy.json

# macOS
.DS_Store

# VS Code
.vscode/

# IntelliJ IDEA
.idea/

# pytest-profiling
/prof/
14 changes: 14 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[MASTER]

ignore=docs, __pycache__
disable=
no-member,
too-many-arguments,
too-few-public-methods,
logging-format-interpolation,
missing-module-docstring


[FORMAT]

max-line-length=88
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Playsthetic

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
72 changes: 72 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# gitalong-python

[![PyPI version](https://badge.fury.io/py/gitalong-python.svg)](https://badge.fury.io/py/gitalong-python)
[![Documentation Status](https://readthedocs.org/projects/gitalong-python/badge/?version=latest)](https://gitalong-python.readthedocs.io/en/latest)
[![codecov](https://codecov.io/gh/douglaslassance/gitalong-python/branch/main/graph/badge.svg?token=5267NA3EQQ)](https://codecov.io/gh/douglaslassance/gitalong-python)

A Python API allowing to interact with Gitalong features on a Git repository.
More about Gitalong in this [medium article]().

## Pre-requisites

- [Git >=2.35.1](https://git-scm.com/downloads)

## Installation

```
pip install gitalong
```

## Usage

```python
from pprint import pprint

from gitalong import Gitalong, GitalongNotInstalled

try:
gitalong = Gitalong(managed_repository_path)
except GitalongNotInstalled:
# Gitalong stores its data in its own repository therefore we need to pass that repository URL.
gitalong = Gitalong.install(managed_repository_path, data_repository_url)

# Now we'll get the last commit for a given file.
# This could return a dummy commit representing uncommitted changes.
last_commit = gitalong.get_file_last_commit(filename)
pprint(last_commit)

spread = gitalong.get_commit_spread(commit)
if commit_spread & CommitSpread.LOCAL_UNCOMMITTED == CommitSpread.LOCAL_UNCOMMITTED:
print("Commit represents our local uncommitted changes."
if commit_spread & CommitSpread.LOCAL_ACTIVE_BRANCH == CommitSpread.LOCAL_ACTIVE_BRANCH:
print("Commit is on our local active branch."
if commit_spread & CommitSpread.LOCAL_OTHER_BRANCH == CommitSpread.LOCAL_OTHER_BRANCH:
print("Commit is in one ore more of our other local branches."
if commit_spread & CommitSpread.REMOTE_MATCHING_BRANCH == CommitSpread.REMOTE_MATCHING_BRANCH:
print("Commit is on the matching remote branch."
if commit_spread & CommitSpread.REMOTE_OTHER_BRANCH == CommitSpread.REMOTE_OTHER_BRANCH:
print("Commit is one ore more other remote branches."
if commit_spread & CommitSpread.CLONE_OTHER_BRANCH == CommitSpread.CLONE_OTHER_BRANCH:
print("Commit is on someone else's clone non-matching branch."
if commit_spread & CommitSpread.CLONE_MATCHING_BRANCH == CommitSpread.CLONE_MATCHING_BRANCH:
print("Commit is on another clone's matching branch."
if commit_spread & CommitSpread.CLONE_UNCOMMITTED == CommitSpread.CLONE_UNCOMMITTED:
print("Commit represents someone else's uncommitted changes."

# To update tracked commit with the ones based on local changes.
gitalong.update_tracked_commits()

# To update permissions of tracked files.
gitalong.update_binary_permissions()
```

# Development

This projects requires the following:

- [Python >=3.7](https://www.python.org/downloads/)
- [virtualenwrapper](https://pypi.org/project/virtualenvwrapper/) (macOS/Linux)
- [virtualenwrapper-win](https://pypi.org/project/virtualenvwrapper-win/) (Windows)

Make sure your `WORKON_HOME` environment variable is set on Windows, and create a `gitalong-python` virtual environment with `mkvirtualenv`.
Build systems for installing requirements and running tests are on board of the SublimeText project.
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build

if "%1" == "" goto help

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
Loading

0 comments on commit 2ef6c25

Please sign in to comment.