Skip to content

Commit

Permalink
Add ruff config, reformat, resolve lints and
Browse files Browse the repository at this point in the history
  • Loading branch information
brianschubert committed Mar 13, 2024
1 parent edbe1b2 commit 2953932
Show file tree
Hide file tree
Showing 13 changed files with 337 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
name: 6s-archives
urls: |
[
"https://web.archive.org/web/20220912090811if_/https://rtwilson.com/downloads/6SV-1.1.tar",
"https://web.archive.org/web/20220912090811if_/https://rtwilson.com/downloads/6SV-1.1.tar",
"https://web.archive.org/web/20220909154857if_/https://salsa.umd.edu/files/6S/6sV2.1.tar"
]
retention-days: 1
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ jobs:
tag_prefix="refs/tags/v"
pushed_ref="${{ github.ref }}"
expected_version="${pushed_ref#${tag_prefix}}"
echo "::notice:: expected version is ${expected_version} for ref ${pushed_ref}"
for dist_file in ./dist/*; do
dist_version=$(echo ${dist_file%.tar.gz} | cut -d'-' -f2)
echo "::debug:: found version ${dist_version} for file '${dist_file}'"
if [ "${expected_version}" != "${dist_version}" ]; then
echo "::error:: expected ${expected_version}, got ${dist_version} in distribution file '${dist_file}'"
exit 1
Expand Down Expand Up @@ -109,12 +109,12 @@ jobs:
run: |
import packaging.version
import sixs_bin
installed_version = packaging.version.parse(sixs_bin.__version__)
expected_version = packaging.version.parse("${{ github.ref }}".split("/")[-1].removeprefix("v"))
print(f"::notice::{installed_version=} {expected_version=}")
assert installed_version.release == expected_version.release
# Quick final self-check.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
name: 6s-archives
urls: |
[
"https://web.archive.org/web/20220912090811if_/https://rtwilson.com/downloads/6SV-1.1.tar",
"https://web.archive.org/web/20220912090811if_/https://rtwilson.com/downloads/6SV-1.1.tar",
"https://web.archive.org/web/20220909154857if_/https://salsa.umd.edu/files/6S/6sV2.1.tar"
]
retention-days: 1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/web_artifact.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ jobs:
with:
name: ${{ inputs.name }}
path: artifacts
retention-days: ${{ inputs.retention-days }}
retention-days: ${{ inputs.retention-days }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Pre-compiled wheels can be installed from [PyPI](https://pypi.org/project/6s-bin
```shell
$ pip install 6s-bin
```
If you are using [poetry](https://python-poetry.org/), you can add this distribution as a dependency using
If you are using [poetry](https://python-poetry.org/), you can add this distribution as a dependency using
`poetry add`:
```shell
$ poetry add 6s-bin
Expand Down
26 changes: 16 additions & 10 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class SixSTarget(NamedTuple):

archive_urls: list[str]
"""
URL(s) to obtain 6S source archive from.
URL(s) to obtain 6S source archive from.
To avoid downloading a new copy, configure a cache directory using SIXS_ARCHIVE_DIR.
"""

Expand Down Expand Up @@ -205,7 +205,7 @@ def _resolve_source(
f"Expected SHA256={target.archive_sha256}, got SHA256={digest}"
)

logger.info(f"Extracting source...")
logger.info("Extracting source...")
logger.debug("Extracting %d byte payload to '%s'", len(sixs_source), directory)
buffer = io.BytesIO(sixs_source)
tar_file = tarfile.open(fileobj=buffer, mode="r:")
Expand All @@ -215,7 +215,7 @@ def _resolve_source(
def _install(binary: pathlib.Path, target: pathlib.Path) -> None:
shutil.copyfile(binary, target)
# Make sure file has owner execute permissions.
os.chmod(target, target.stat().st_mode | stat.S_IXUSR)
target.chmod(target.stat().st_mode | stat.S_IXUSR)


def build(target: SixSTarget, build_dir: pathlib.Path, config: BuildConfig) -> None:
Expand All @@ -226,21 +226,22 @@ def build(target: SixSTarget, build_dir: pathlib.Path, config: BuildConfig) -> N
)

binary_dest = PACKAGE_ROOT.joinpath(target.target_name)
logger.debug(f"destination for %s is '%s'", target.target_name, binary_dest)
logger.debug("destination for %s is '%s'", target.target_name, binary_dest)

if binary_dest.is_file():
# Binary already exists in package. Skip rebuilding.
logger.info(f"target {binary_dest} already exists - skipping build")
return

logger.info(f"Resolving 6S source...")
logger.info("Resolving 6S source...")
_resolve_source(target, build_dir, config.archive_dir)
logger.debug("source contents: %r", sorted(build_dir.glob("**/*")))

# Make 6S executable.
logger.info("Building...")
try:
# If 6S source contains a directory beginning with 6S, build from that directory.
# If 6S source contains a directory beginning with "6S", build
# from that directory.
(src_dir,) = build_dir.glob("6S*")
except (FileNotFoundError, ValueError):
# No 6S* subdirectory. Build from source root.
Expand All @@ -252,7 +253,10 @@ def build(target: SixSTarget, build_dir: pathlib.Path, config: BuildConfig) -> N

fc_override = config.fc_override
if fc_override is None:
fc_override = "FC=gfortran -std=legacy -ffixed-line-length-none -ffpe-summary=none $(FFLAGS)"
fc_override = (
"FC=gfortran -std=legacy -ffixed-line-length-none"
" -ffpe-summary=none $(FFLAGS)"
)
if config.fc_append is not None:
fc_override += f" {config.fc_append}"

Expand All @@ -268,7 +272,9 @@ def build(target: SixSTarget, build_dir: pathlib.Path, config: BuildConfig) -> N
)
except subprocess.CalledProcessError as ex:
raise BuildError(
f"make exited with non-zero exit status {ex.returncode}\nstdout:\n{ex.stdout}\nstderr:\n{ex.stderr}",
f"make exited with non-zero exit status {ex.returncode}"
f"\nstdout:\n{ex.stdout}"
f"\nstderr:\n{ex.stderr}",
) from ex
logger.debug("make output\nstdout:\n%s\nstderr:\n%s", result.stdout, result.stderr)

Expand Down Expand Up @@ -318,7 +324,7 @@ def main() -> None:

_setup_logging(config.log_file)
logger = logging.getLogger(__name__)
logger.info(f"Building from '%s' with config %r", pathlib.Path.cwd(), config)
logger.info("Building from '%s' with config %r", pathlib.Path.cwd(), config)

# Check system dependencies
logger.info("Checking system dependencies...")
Expand Down
Loading

0 comments on commit 2953932

Please sign in to comment.