Skip to content

Lint changes from a specific branch #97

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

Open
wants to merge 4 commits into
base: adds-support-for-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ exceptions:
- Multi-line docstrings: The first line of text (summary line) appears on the same line as the opening three double-quotes.
- Base Class Inheritance
- If a class or nested class inherits from no other base classes, explicitly inherit from object.
- This won't be enforced for our pure Python 3 code, but we will enforce for Python 2 and 2/3 compatbile code.
- This won't be enforced for our pure Python 3 code, but we will enforce for Python 2 and 2/3 compatible code.
- Variable/module-name collisions: Variable names may be suffixed with an underscore to avoid collisions with imported modules (an extension of the [PEP-8 convention](https://www.python.org/dev/peps/pep-0008/#descriptive-naming-styles) for collisions with builtins).


Expand All @@ -29,7 +29,7 @@ exceptions:
Projects that are producing libraries to be used in other projects should choose their release version numbers using [Semantic Versioning 2.0.0](http://semver.org/spec/v2.0.0.html), i.e.

> Given a version number MAJOR.MINOR.PATCH, increment the:
>
>
> MAJOR version when you make incompatible API changes,
> MINOR version when you add functionality in a backwards-compatible manner, and
> PATCH version when you make backwards-compatible bug fixes.
Expand Down
20 changes: 10 additions & 10 deletions shopify_python/git_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ class GitUtilsException(Exception):
pass


def _remote_origin_master(git_repo):
# type: (repo.Repo) -> head.Head
remote_master = git_repo.heads.master.tracking_branch()
if not remote_master or not remote_master.is_valid():
raise GitUtilsException("Unable to locate remote branch origin/master")
return remote_master
def _remote_origin_branch(git_repo, branch):
# type: (repo.Repo, str) -> head.Head
remote_branch = git_repo.heads[branch].tracking_branch()
if not remote_branch or not remote_branch.is_valid():
raise GitUtilsException("Unable to locate remote branch origin/{}".format(branch))
return remote_branch


def _modified_in_branch(git_repo, other_ref):
Expand Down Expand Up @@ -48,12 +48,12 @@ def _file_is_python(path):
return False


def changed_python_files_in_tree(root_path):
# type: (str) -> typing.List[str]
def changed_python_files_in_tree(root_path, base='master'):
# type: (str, typing.Optional[str]) -> typing.List[str]

git_repo = repo.Repo(root_path)
remote_master = _remote_origin_master(git_repo)
modified = _modified_in_branch(git_repo, remote_master)
remote_branch = _remote_origin_branch(git_repo, base)
modified = _modified_in_branch(git_repo, remote_branch)
abs_modified = [os.path.join(git_repo.working_dir, x) for x in modified]
return [mod for (mod, abs_mod) in zip(modified, abs_modified)
if os.path.exists(abs_mod) and os.path.isfile(abs_mod) and _file_is_python(abs_mod)]
Expand Down
2 changes: 1 addition & 1 deletion tests/shopify_python/test_git_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ def test_detects_changed_python_files(main_repo, python_file, python_script):
main_repo.create_head('foo').checkout()
main_repo.index.add([python_file, python_script])
main_repo.index.commit("adding python files")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the deletion?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good question. Gonna remove this

changed_files = git_utils.changed_python_files_in_tree(main_repo.working_dir)

assert sorted(changed_files) == [
os.path.basename(python_script),
os.path.basename(python_file),
Expand Down