Skip to content

Commit

Permalink
Merge pull request #477 from cclauss/GitHub-Actions-on-dev
Browse files Browse the repository at this point in the history
Add GitHub Actions on dev branch
  • Loading branch information
bennr01 authored Mar 15, 2023
2 parents 759c2fd + 38f3560 commit 4f771f6
Show file tree
Hide file tree
Showing 17 changed files with 83 additions and 28 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/check-code-and-run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Check code and run tests

on:
push:
branches:
- dev
- master
pull_request:
branches:
- dev
- master

jobs:
ruff:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- run: pip install --user ruff
- run: ruff --ignore=E401,E402,E701,E722,E731,E741,F401,F403,F405,F523,F524,F811,F841
--format=github --line-length=2793 --show-source --target-version=py37 .

build:
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
python-version: ["2.7", "3.6"] # TODO: Add for Pythonista v3.4 -- , "3.10"]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip wheel setuptools
pip install ".[testing]"
- name: Analysing the code with flake8
run: |
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=88 --statistics
- name: Running tests
run: |
pytest --version
# make install test work...
export PYTHONPATH=$(python -m site --user-site)
# TODO: Get test_runtime and sp_test working again
pytest --ignore=tests/system/data/ --ignore=tests/system/test_runtime.py --ignore=lib/mlpatches/tests/sp_test.py \
--showlocals --verbose --show-capture=all --log-level=debug
8 changes: 4 additions & 4 deletions bin/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def call(*args, **kwargs):

if AUTODOWNLOAD_DEPENDENCIES:
libpath = os.path.join(os.environ['STASH_ROOT'], 'lib')
if not libpath in sys.path:
if libpath not in sys.path:
sys.path.insert(1, libpath)
download_dulwich = False

Expand Down Expand Up @@ -381,10 +381,10 @@ def git_reset(args):
commit = ns.commit
# first arg was really a file
paths = ns.paths or []
if not commit in repo and os.path.exists(commit): #really specified a path
if commit not in repo and os.path.exists(commit): #really specified a path
paths = [commit] + paths
commit = None
elif not commit in repo and not commit in repo.branches and not commit in repo.remote_branches and not os.path.exists(
elif commit not in repo and commit not in repo.branches and commit not in repo.remote_branches and not os.path.exists(
commit):
raise Exception('{} is not a valid commit or file'.format(commit))
if not commit:
Expand Down Expand Up @@ -429,7 +429,7 @@ def get_config_or_prompt(repo, section, name, prompt, save=None):
value = config.get(section, name)
except KeyError:
value = input(prompt).encode()
if save == None:
if save is None:
reply = input('Save this setting? [y/n]')
save = reply == 'y'
if save:
Expand Down
2 changes: 1 addition & 1 deletion bin/httpserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def deal_post_data(self):
remainbytes = int(self.headers['content-length'])
line = self.rfile.readline()
remainbytes -= len(line)
if not boundary in line:
if boundary not in line:
return (False, "Content NOT begin with boundary")
line = self.rfile.readline()
remainbytes -= len(line)
Expand Down
2 changes: 1 addition & 1 deletion bin/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def send(self, sendto='', subject='', attach='', body=' '):
)
args = ap.parse_args()
smail = Mail(CONFIG, args.verbose)
if args.e == True:
if args.e is True:
smail.edit_cfg()
elif args.message or args.file and args.sendto:
if args.message == '-':
Expand Down
2 changes: 1 addition & 1 deletion bin/mount.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def list_mounts():
else:
manager.enable_patches()

if not ns.type in FILESYSTEM_TYPES:
if ns.type not in FILESYSTEM_TYPES:
print(_stash.text_color("Error: Unknown Filesystem-Type!", "red"))
sys.exit(1)

Expand Down
2 changes: 1 addition & 1 deletion bin/ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def verbose_ping(dest_addr, timeout=2, count=4, interval=1.0):
print("failed. (socket error: '%s')" % e[1])
break

if delay == None:
if delay is None:
print("failed. (timeout within %ssec.)" % timeout)
else:
time.sleep(min(0, interval - delay))
Expand Down
4 changes: 2 additions & 2 deletions bin/pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def update_req_index(pip_info_file=PIP_INFO_FILE, site_packages=SITE_PACKAGES_FO
requires = []
try:
for req in info['requires_dist']:
if not ';' in req:
if ';' not in req:
#Remove package version
requires.append(req.split(' ')[0])
except TypeError:# some package may have no require
Expand Down Expand Up @@ -782,7 +782,7 @@ def _run_setup_file(self, filename, extras=[]):
if self.verbose:
print("Handling commandline script: {s}".format(s=script))
cmdname = script.replace(os.path.dirname(script), "").replace("/", "")
if not "." in cmdname:
if '.' not in cmdname:
cmdname += ".py"
scriptpath = os.path.join(source_folder, script)
with open(scriptpath, "r") as fin:
Expand Down
2 changes: 1 addition & 1 deletion bin/sed.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ def get_regexp(self, delim, address=True):
elif self.sed.sed_compatible:
# in sed a ^ not at the beginning of
# a regexp must be taken literally
if char == '^' and not (last_pychr in ['(', '|', '']):
if char == '^' and last_pychr not in ['(', '|', '']:
pychr = '\\^'
elif char == '$':
# remember this dollar sign's position in py_pattern
Expand Down
4 changes: 2 additions & 2 deletions docs/porting_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The porting process can be divided into the following parts:

You will need to find a way to accurately detect if StaSh runs on the target platform. This must be done using the standard library and must work with both py2 and py3.

For example, StaSh sets `ON_TRAVIS = "TRAVIS" in os.environ` to detect if we are running on Travis CI. In this case, a stub UI will be loaded.
For example, StaSh sets `ON_CI = "CI" in os.environ` to detect if we are running on GitHub Actions CI. In this case, a stub UI will be loaded.

## Porting the UI

Expand Down Expand Up @@ -190,7 +190,7 @@ Please ensure that you have a way to identify your target platform.
StaSh uses a file called `libdist.py` for os-specific interactions and values.

1. edit `stash/lib/libdist.py`
2. add your check at the top of the file (near `ON_TRAVIS = ...`)
2. add your check at the top of the file (near `ON_CI = ...`)
3. See the large top-level `if ... elif ... else` consturct there? add a `elif <mycondition>:` there.
4. implement the functions and define the values used in the other cases. In the next subsection is an overview of these definitions.
5. save
Expand Down
4 changes: 2 additions & 2 deletions lib/git/git-branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def format_tracking_branch_desc(repo, branchname):
def edit_branch_description(branchname, description=None):
description = description or input('enter description:')
config = _get_repo().repo.get_config()
if not branchname in _get_repo().branches:
if branchname not in _get_repo().branches:
GitError('{} is not an existing branch'.format(branchname))
config.set(('branch', branchname), 'description', description)
config.write_to_path()
Expand Down Expand Up @@ -284,7 +284,7 @@ def create_branch(new_branch, base_rev, force=False, no_track=False):
#handle tracking, only if this was a remote
tracking, remote_branch = (['origin'] + base_rev.split('/'))[-2:] #branch-> origin/branch. remote/branch stays as is
qualified_remote_branch = os.path.sep.join([tracking, remote_branch])
if qualified_remote_branch in repo.remote_branches and not base_rev in repo.branches:
if qualified_remote_branch in repo.remote_branches and base_rev not in repo.branches:
if not no_track:
add_tracking(new_branch, tracking, remote_branch)
else:
Expand Down
11 changes: 6 additions & 5 deletions lib/libdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


IN_PYTHONISTA = sys.executable.find('Pythonista') >= 0
ON_TRAVIS = "TRAVIS" in os.environ
ON_CI = "CI" in os.environ


# ========================== PYTHONISTA =======================
Expand Down Expand Up @@ -118,12 +118,12 @@ def quicklook(path):
"""
console.quicklook(path)

# ======================== DEFAULT / PC / travis =========================
# ======================== DEFAULT / PC / GitHub Actions =========================
else:

# ------------- clipboard --------------
# travis is a variation of PC
if not ON_TRAVIS:
# ON_CI is a variation of PC
if not ON_CI:
# use pyperclip
import pyperclip

Expand All @@ -146,7 +146,8 @@ def clipboard_set(s):
pyperclip.copy(s)
else:
# use fake implementation
global _CLIPBOARD; _CLIPBOARD = u""
global _CLIPBOARD
_CLIPBOARD = u""

def clipboard_get():
"""
Expand Down
2 changes: 1 addition & 1 deletion lib/stashutils/mount_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def mount_fsi(self, path, fsi, readonly=False):
def unmount_fsi(self, path, force=False):
"""unmounts a fsi."""
path = os.path.abspath(path)
if not path in self.path2fs:
if path not in self.path2fs:
raise MountError("Nothing mounted there.")
fsi, readonly = self.path2fs[path]
if not force:
Expand Down
6 changes: 3 additions & 3 deletions system/shui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

from stash.system.shcommon import IN_PYTHONISTA

# check if running on travis
ON_TRAVIS = "TRAVIS" in os.environ
# check if running on GitHub Actions CI
ON_CI = "CI" in os.environ


def get_platform():
Expand All @@ -18,7 +18,7 @@ def get_platform():
# platform specific UIs
if IN_PYTHONISTA:
return "pythonista"
elif ON_TRAVIS:
elif ON_CI:
return "stub"

# attempt to fall back to tkinter
Expand Down
4 changes: 2 additions & 2 deletions tests/install/test_getstash.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import time
import shutil

from stash.tests.stashtest import StashTestCase, ON_TRAVIS
from stash.tests.stashtest import StashTestCase, ON_CI



Expand Down Expand Up @@ -168,6 +168,6 @@ def test_install_setup(self):
zp = self.create_stash_zipfile()
td = self.get_new_tempdir()
sd = os.path.join(td, "stash")
asuser = (not ON_TRAVIS)
asuser = (not ON_CI)
self.run_getstash(zippath=zp, dist="setup", asuser=asuser, dryrun=True)

3 changes: 3 additions & 0 deletions tests/pip/test_pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""tests for the 'pip' command."""
import sys
import unittest
import pytest

from six.moves import reload_module

Expand Down Expand Up @@ -134,6 +135,7 @@ def test_install_pypi_nobinary(self):
raise AssertionError("Could not import installed module: " + repr(e))

@requires_network
@pytest.mark.xfail(sys.version_info < (3, 0), reason="rsa v4.7.1 binary is not available on Py2")
def test_install_pypi_onlybinary(self):
"""test 'pip install --only-binary :all: <pypi_package>'."""
output = self.run_command("pip --verbose install --only-binary :all: rsa", exitcode=0)
Expand All @@ -147,6 +149,7 @@ def test_install_pypi_onlybinary(self):
raise AssertionError("Could not import installed module: " + repr(e))

@requires_network
@pytest.mark.xfail(sys.version_info < (3, 0), reason="rsa v4.7.1 raises SyntaxError on Py2")
def test_install_command(self):
"""test 'pip install <package>' creates commandline scripts."""
# 1. test command not yet installed
Expand Down
2 changes: 1 addition & 1 deletion tests/stashtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from stash.system.shcommon import _STASH_ROOT, PY3


ON_TRAVIS = "TRAVIS" in os.environ
ON_CI = "CI" in os.environ


def network_is_available():
Expand Down
2 changes: 1 addition & 1 deletion tools/pythonista_reinstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def remove_stash():


def install_stash(repo="ywangd", branch="master"):
if not "TMPDIR" in os.environ:
if "TMPDIR" not in os.environ:
os.environ["TMPDIR"] = tempfile.gettempdir()
ns = {"_owner": repo, "_br": branch}
exec(requests.get("https://bit.ly/get-stash").content, ns, ns)
Expand Down

0 comments on commit 4f771f6

Please sign in to comment.