Skip to content

Commit

Permalink
resolve merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
Antsalacia committed Dec 3, 2024
2 parents 0a9d2cc + a3d8c28 commit ad78deb
Show file tree
Hide file tree
Showing 33 changed files with 681 additions and 163 deletions.
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
# Check for updates to GitHub Actions every week
interval: "weekly"
152 changes: 152 additions & 0 deletions .github/scripts/generate_pip_deps_from_conda.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
#!/usr/bin/env python3
"""
(Copied from pandas:
https://github.com/pandas-dev/pandas/blob/main/scripts/generate_pip_deps_from_conda.py)
Convert the conda environment.yml to the pip requirements-dev.txt, or
check that they have the same packages (for the CI)
Usage:
Generate `requirements-dev.txt`
$ python scripts/generate_pip_deps_from_conda.py
Compare and fail (exit status != 0) if `requirements-dev.txt` has not been
generated with this script:
$ python scripts/generate_pip_deps_from_conda.py --compare
"""
import argparse
import pathlib
import re
import sys

if sys.version_info >= (3, 11):
import tomllib
else:
import tomli as tomllib
import yaml

EXCLUDE = {"python"}
REMAP_VERSION = {"tzdata": "2022.1"}
RENAME = {}


def conda_package_to_pip(package: str):
"""
Convert a conda package to its pip equivalent.
In most cases they are the same, those are the exceptions:
- Packages that should be excluded (in `EXCLUDE`)
- Packages that should be renamed (in `RENAME`)
- A package requiring a specific version, in conda is defined with a single
equal (e.g. ``pandas=1.0``) and in pip with two (e.g. ``pandas==1.0``)
"""
package = re.sub("(?<=[^<>])=", "==", package).strip()
print(package)

for compare in ("<=", ">=", "=="):
if compare in package:
pkg, version = package.split(compare)
if pkg in EXCLUDE:
return
if pkg in REMAP_VERSION:
return "".join((pkg, compare, REMAP_VERSION[pkg]))
if pkg in RENAME:
return "".join((RENAME[pkg], compare, version))

if package in EXCLUDE:
return

if package in RENAME:
return RENAME[package]

return package


def generate_pip_from_conda(
conda_path: pathlib.Path, pip_path: pathlib.Path, compare: bool = False
) -> bool:
"""
Generate the pip dependencies file from the conda file, or compare that
they are synchronized (``compare=True``).
Parameters
----------
conda_path : pathlib.Path
Path to the conda file with dependencies (e.g. `environment.yml`).
pip_path : pathlib.Path
Path to the pip file with dependencies (e.g. `requirements-dev.txt`).
compare : bool, default False
Whether to generate the pip file (``False``) or to compare if the
pip file has been generated with this script and the last version
of the conda file (``True``).
Returns
-------
bool
True if the comparison fails, False otherwise
"""
with conda_path.open() as file:
deps = yaml.safe_load(file)["dependencies"]

pip_deps = []
for dep in deps:
if isinstance(dep, str):
conda_dep = conda_package_to_pip(dep)
if conda_dep:
pip_deps.append(conda_dep)
elif isinstance(dep, dict) and len(dep) == 1 and "pip" in dep:
pip_deps.extend(dep["pip"])
else:
raise ValueError(f"Unexpected dependency {dep}")

header = (
f"# This file is auto-generated from {conda_path.name}, do not modify.\n"
"# See that file for comments about the need/usage of each dependency.\n\n"
)
pip_content = header + "\n".join(pip_deps) + "\n"

# Add setuptools to requirements-dev.txt

# with open(pathlib.Path(conda_path.parent, "pyproject.toml"), "rb") as fd:
# meta = tomllib.load(fd)
# for requirement in meta["build-system"]["requires"]:
# if "setuptools" in requirement:
# pip_content += requirement
# pip_content += "\n"

if compare:
with pip_path.open() as file:
return pip_content != file.read()

with pip_path.open("w") as file:
file.write(pip_content)
return False


if __name__ == "__main__":
argparser = argparse.ArgumentParser(
description="convert (or compare) conda file to pip"
)
argparser.add_argument(
"--compare",
action="store_true",
help="compare whether the two files are equivalent",
)
args = argparser.parse_args()

conda_fname = "dev-environment.yml"
pip_fname = "requirements-dev.txt"
repo_path = pathlib.Path(__file__).parent.parent.parent.absolute()
res = generate_pip_from_conda(
pathlib.Path(repo_path, conda_fname),
pathlib.Path(repo_path, pip_fname),
compare=args.compare,
)
if res:
msg = (
f"`{pip_fname}` has to be generated with `{__file__}` after "
f"`{conda_fname}` is modified.\n"
)
sys.stderr.write(msg)
sys.exit(res)
8 changes: 4 additions & 4 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
queries: +security-and-quality

- name: Autobuild
uses: github/codeql-action/autobuild@v2
uses: github/codeql-action/autobuild@v3

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{ matrix.language }}"
55 changes: 28 additions & 27 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,37 @@ jobs:
name: Setup and test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ["ubuntu-latest"]
matrix:
os: ["ubuntu-latest"]
python-version: ["3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v2
- uses: snyk/actions/setup@master
- uses: conda-incubator/setup-miniconda@v2
- uses: actions/checkout@v4
- uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: test
environment-file: environment.yml
python-version: 3.8
use-mamba: true
auto-activate-base: true

- shell: bash -l {0}
run: |
conda info
conda list
- name: Install earthspy
shell: bash -l {0}
run: |
pip install -e .
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
# Full git history is needed to get a proper list of changed files within `super-linter`
fetch-depth: 0
fetch-depth: 0

- name: Lint code base
uses: github/super-linter/slim@v4.9.0
uses: github/super-linter/slim@v7
env:
VALIDATE_ALL_CODEBASE: true
VALIDATE_JSON: true
Expand All @@ -48,26 +49,26 @@ jobs:
run: |
pip install pytest
pip install pytest-cov
pytest --cov=./ --cov-report=xml
pytest --cov --junitxml=junit.xml -o junit_family=legacy
env:
SH_CLIENT_ID: ${{ secrets.SH_CLIENT_ID }}
SH_CLIENT_SECRET: ${{ secrets.SH_CLIENT_SECRET }}

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
- name: Upload test results to Codecov
if: ${{ !cancelled() }}
uses: codecov/test-results-action@v1
with:
directory: ./coverage/reports/
fail_ci_if_error: true
files: ./coverage.xml
flags: unittests
name: codecov-umbrella
path_to_write_report: ./coverage/codecov_report.txt
verbose: true
token: ${{ secrets.CODECOV_TOKEN }}

- name: Run Snyk to check for vulnerabilities
- name: Install dev requirements
shell: bash -l {0}
run: |
pip install -r dev-requirements.txt
snyk test --file=dev-requirements.txt --package-manager=pip --severity-threshold=high
pip install -r requirements-dev.txt
- name: Run Snyk to check for vulnerabilities
uses: snyk/actions/python@master
continue-on-error: true
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}

with:
args: --file=requirements-dev.txt --package-manager=pip --severity-threshold=high --skip-unresolved=true
15 changes: 15 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Linting and formatting (pre-commit)

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

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: pre-commit/action@v3.0.1
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,4 @@ auth.txt
*.gcno
*.gcda
*.gcov
test_calculator
test_calculator
12 changes: 9 additions & 3 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@
# Required
version: 2

# Set the OS, Python version and other tools you might need

build:
os: ubuntu-22.04
tools:
python: "3.12"

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/conf.py
fail_on_warning: false

# Optionally build your docs in additional formats such as PDF and ePub
formats: []
formats: [pdf]

python:
version: 3.7
install:
- requirements: dev-requirements.txt
- requirements: requirements-dev.txt
- method: pip
path: .
Loading

0 comments on commit ad78deb

Please sign in to comment.