Skip to content

Commit

Permalink
Merge branch '33-add-yapf-configuration' into 'master'
Browse files Browse the repository at this point in the history
Resolve "Add YAPF configuration"

Closes #33

See merge request ShellLogger/ShellLogger!26
  • Loading branch information
jmgate committed Mar 24, 2022
2 parents 5e35357 + 31e16b3 commit 641cfe7
Show file tree
Hide file tree
Showing 12 changed files with 780 additions and 479 deletions.
153 changes: 93 additions & 60 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ after_script:
# Create the virtual environment, install the requirements, and save the
# environment to the cache.
requirements:
stage: prepare
timeout: 10m
before_script:
- conda create --prefix ./shelllogger-env --yes python=3.7 pip
cache:
Expand All @@ -79,6 +77,8 @@ requirements:

# Show the contents of the virtual environment.
- conda list
stage: prepare
timeout: 10m


#-----------------------------------------------------------------------
Expand All @@ -88,24 +88,22 @@ requirements:

# Test building a distribution.
wheel:
stage: install
timeout: 5m
cache:
<<: *global_cache
policy: pull
script:
- pip wheel --no-deps -w dist .
artifacts:
name: "shelllogger-dist"
paths:
- dist/shelllogger*.whl
expire_in: 6 weeks
cache:
<<: *global_cache
policy: pull
script:
- pip wheel --no-deps -w dist .
stage: install
timeout: 5m


# Test installation of the package.
install:
stage: install
timeout: 5m
cache:
<<: *global_cache
script:
Expand All @@ -115,19 +113,61 @@ install:

# Show the contents of the virtual environment to ensure it's there.
- conda list
stage: install
timeout: 5m


#-----------------------------------------------------------------------
# Stage: Test
#-----------------------------------------------------------------------


# Execute the unit tests.
pytest:
# Ensure the examples run without problems.
examples:
artifacts:
paths:
- examples/log*
- examples/*.html
cache:
<<: *global_cache
policy: pull
script:
- cd examples
- python3 ./hello_world_html.py
- cp -L log_hello_world_html/Hello_World_HTML.html .
- python3 ./hello_world_html_and_console.py
- cp -L log_hello_world_html_and_console/Hello_World_HTML_and_Console.html
.
- python3 ./hello_world_html_with_stats.py
- cp -L log_hello_world_html_with_stats/Hello_World_HTML_with_Stats.html .
- python3 ./build_flex.py
- cp -L log_build_flex/Build_Flex.html .
stage: test
timeout: 5m


# Ensure we pass the `flake8` linter.
flake8:
cache:
<<: *global_cache
script:
- python3 -m flake8
--exclude=shelllogger-env
stage: test
timeout: 5m


# Execute the unit tests.
pytest:
artifacts:
paths:
- tests/htmlcov
reports:
cobertura: tests/coverage.xml
junit: tests/coverage.xml
cache:
<<: *global_cache
coverage: '/TOTAL\s*[0-9]*\s*[0-9]*\s*[0-9]*\s*[0-9]*\s*(\d+%)/'
script:
- python3 -m pytest
--cov=src.shelllogger
Expand All @@ -137,48 +177,41 @@ pytest:
--cov-report=xml
--full-trace
tests/
coverage: '/TOTAL\s*[0-9]*\s*[0-9]*\s*[0-9]*\s*[0-9]*\s*(\d+%)/'
artifacts:
paths:
- tests/htmlcov
reports:
cobertura: tests/coverage.xml
junit: tests/coverage.xml


# Ensure we adhere to PEP8.
flake8:
stage: test
timeout: 5m
cache:
<<: *global_cache
script:
- python3 -m flake8
--exclude=shelllogger-env


# Ensure the examples run without problems.
examples:
stage: test
timeout: 5m
# Ensure we adhere to our style guide.variables:
yapf:
artifacts:
expire_in: 1 week
paths:
- yapf.diff.txt
when: on_failure
cache:
<<: *global_cache
policy: pull
script:
- cd examples
- python3 ./hello_world_html.py
- cp -L log_hello_world_html/Hello_World_HTML.html .
- python3 ./hello_world_html_and_console.py
- cp -L log_hello_world_html_and_console/Hello_World_HTML_and_Console.html
.
- python3 ./hello_world_html_with_stats.py
- cp -L log_hello_world_html_with_stats/Hello_World_HTML_with_Stats.html .
- python3 ./build_flex.py
- cp -L log_build_flex/Build_Flex.html .
artifacts:
paths:
- examples/log*
- examples/*.html
- set +e
- python3 -m yapf
--style .style.yapf
--diff
--recursive
examples/
src/
tests/
> yapf.diff.txt
- |-
if [[ "$(wc -l yapf.diff.txt | awk '{print $1}')" != "0" ]]; then
echo "----------"
echo "Your code does not match our Python style guide."
echo -n "Run 'yapf --style .style.yapf --in-place --recursive "
echo "examples/ src/ tests/' in the repository root to fix it."
echo "The offending files are:"
grep "^+++.*(reformatted)$" yapf.diff.txt | awk '{print $2}'
exit 1
fi
stage: test
timeout: 5m


#-----------------------------------------------------------------------
Expand All @@ -188,16 +221,16 @@ examples:

# Generate the documentation.
sphinx:
stage: documentation
timeout: 5m
artifacts:
paths:
- doc/html
cache:
<<: *global_cache
script:
- cd doc
- bash make_html_docs.sh
artifacts:
paths:
- doc/html
stage: documentation
timeout: 5m


#-----------------------------------------------------------------------
Expand All @@ -207,8 +240,9 @@ sphinx:

# Publish coverage data and documentation (if on the main branch).
pages:
stage: deploy
timeout: 5m
artifacts:
paths:
- public
cache:
<<: *global_cache
policy: pull
Expand All @@ -219,9 +253,8 @@ pages:
- mv tests/htmlcov public/.
- mv doc/html/* public/.
- mv examples/*.html public/examples/.
artifacts:
paths:
- public
stage: deploy
timeout: 5m


#-----------------------------------------------------------------------
Expand All @@ -231,12 +264,12 @@ pages:

# Test that uninstalling from a virtual environment works.
uninstall:
stage: finish
timeout: 5m
cache:
<<: *global_cache
script:
- pip uninstall -y shelllogger

# Show the contents of the virtual environment.
- conda list
stage: finish
timeout: 5m
18 changes: 18 additions & 0 deletions .style.yapf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# YAPF Style Configuration

# See: /~https://github.com/google/yapf#knobs for available options

[style]
# Base style
based_on_style = pep8

# Customizations
arithmetic_precedence_indication = True
blank_line_before_nested_class_or_def = True
coalesce_brackets = True
dedent_closing_brackets = True
join_multiple_lines = False
split_all_comma_separated_values = True
split_before_arithmetic_operator = True
split_before_dot = True
split_complex_comprehension = True
64 changes: 45 additions & 19 deletions examples/build_flex.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,50 @@
from pathlib import Path
from shelllogger import ShellLogger

sl = ShellLogger("Build Flex",
Path.cwd() / f"log_{Path(__file__).stem}")
sl.print("This example demonstrates cloning, configuring, and building the "
"Flex tool.")
sl.log("Clone the Flex repository.",
"git clone --depth 1 --branch flex-2.5.39 "
"/~https://github.com/westes/flex.git flex-2.5.39", live_stdout=True,
live_stderr=True)
sl.log("Run `autogen`.", "./autogen.sh", cwd=Path.cwd()/"flex-2.5.39",
live_stdout=True, live_stderr=True)
sl.log("Configure flex.", "./configure --prefix=$(dirname $(pwd))/flex",
cwd=Path.cwd()/"flex-2.5.39", live_stdout=True, live_stderr=True,
measure=["cpu", "memory", "disk"])
sl.log("Build `libcompat.la`.", "make libcompat.la",
cwd=Path.cwd()/"flex-2.5.39/lib", live_stdout=True, live_stderr=True,
measure=["cpu", "memory", "disk"])
sl.log("Build & install flex.", "make install-exec",
cwd=Path.cwd()/"flex-2.5.39", live_stdout=True, live_stderr=True,
measure=["cpu", "memory", "disk"])
sl = ShellLogger("Build Flex", Path.cwd() / f"log_{Path(__file__).stem}")
sl.print(
"This example demonstrates cloning, configuring, and building the Flex "
"tool."
)
FLEX_VERSION = "flex-2.5.39"
sl.log(
"Clone the Flex repository.",
f"git clone --depth 1 --branch {FLEX_VERSION} "
f"/~https://github.com/westes/flex.git {FLEX_VERSION}",
live_stdout=True,
live_stderr=True
)
sl.log(
"Run `autogen`.",
"./autogen.sh",
cwd=Path.cwd() / FLEX_VERSION,
live_stdout=True,
live_stderr=True
)
measure = ["cpu", "memory", "disk"]
sl.log(
"Configure flex.",
"./configure --prefix=$(dirname $(pwd))/flex",
cwd=Path.cwd() / FLEX_VERSION,
live_stdout=True,
live_stderr=True,
measure=measure
)
sl.log(
"Build `libcompat.la`.",
"make libcompat.la",
cwd=Path.cwd() / f"{FLEX_VERSION}/lib",
live_stdout=True,
live_stderr=True,
measure=measure
)
sl.log(
"Build & install flex.",
"make install-exec",
cwd=Path.cwd() / FLEX_VERSION,
live_stdout=True,
live_stderr=True,
measure=measure
)
sl.finalize()
print(f"Open {sl.html_file} to view the log.")
16 changes: 10 additions & 6 deletions examples/hello_world_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
from pathlib import Path
from shelllogger import ShellLogger

sl = ShellLogger("Hello World HTML",
Path.cwd() / f"log_{Path(__file__).stem}")
sl.print("This example demonstrates logging information solely to the HTML "
"log file.")
sl = ShellLogger("Hello World HTML", Path.cwd() / f"log_{Path(__file__).stem}")
sl.print(
"This example demonstrates logging information solely to the HTML log "
"file."
)
sl.log("Greet everyone to make them feel welcome.", "echo 'Hello World'")
sl.log("Tell everyone who you are, but from a different directory.", "whoami",
cwd=Path.cwd().parent)
sl.log(
"Tell everyone who you are, but from a different directory.",
"whoami",
cwd=Path.cwd().parent
)
sl.finalize()
print(f"Open {sl.html_file} to view the log.")
29 changes: 21 additions & 8 deletions examples/hello_world_html_and_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,26 @@
from pathlib import Path
from shelllogger import ShellLogger

sl = ShellLogger("Hello World HTML and Console",
Path.cwd() / f"log_{Path(__file__).stem}")
sl.print("This example demonstrates logging information both to the HTML log "
"file and to the console simultaneously.")
sl.log("Greet everyone to make them feel welcome.", "echo 'Hello World'",
live_stdout=True, live_stderr=True)
sl.log("Tell everyone who you are, but from a different directory.", "whoami",
cwd=Path.cwd().parent, live_stdout=True, live_stderr=True)
sl = ShellLogger(
"Hello World HTML and Console",
Path.cwd() / f"log_{Path(__file__).stem}"
)
sl.print(
"This example demonstrates logging information both to the HTML log file "
"and to the console simultaneously."
)
sl.log(
"Greet everyone to make them feel welcome.",
"echo 'Hello World'",
live_stdout=True,
live_stderr=True
)
sl.log(
"Tell everyone who you are, but from a different directory.",
"whoami",
cwd=Path.cwd().parent,
live_stdout=True,
live_stderr=True
)
sl.finalize()
print(f"Open {sl.html_file} to view the log.")
Loading

0 comments on commit 641cfe7

Please sign in to comment.