Skip to content
Merged
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
11 changes: 11 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[flake8]
exclude =
.git,
__pycache__,
build,
dist,
doc/source/conf.py
max-line-length = 115
# Ignore some style 'errors' produced while formatting by 'black'
# https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#labels-why-pycodestyle-warnings
extend-ignore = E203
3 changes: 2 additions & 1 deletion .github/workflows/_tests-on-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ jobs:
- name: Validate ${{ inputs.project }}
run: |
if ${{ inputs.headless }}; then
xport DISPLAY=:99
export DISPLAY=:99

fi
python -m pytest
32 changes: 19 additions & 13 deletions .github/workflows/check-news.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ def get_added_files(pr: PullRequest.PullRequest):


def check_news_file(pr):
return any(map(lambda file_name: fnmatch(file_name, "news/*.rst"), get_added_files(pr)))
return any(
map(lambda file_name: fnmatch(file_name, "news/*.rst"), get_added_files(pr))
)


def get_pr_number():
Expand All @@ -29,7 +31,9 @@ def get_pr_number():

def get_old_comment(pr: PullRequest.PullRequest):
for comment in pr.get_issue_comments():
if ("github-actions" in comment.user.login) and ("No news item is found" in comment.body):
if ("github-actions" in comment.user.login) and (
"No news item is found" in comment.body
):
return comment


Expand All @@ -41,20 +45,22 @@ def main():
has_news_added = check_news_file(pr)
old_comment = get_old_comment(pr)

if old_comment:
print("Found an existing comment from bot")
if has_news_added:
print("Delete warning from bot, since news items is added.")
if has_news_added:
if old_comment:
print("Found an existing comment from bot")
print("Delete warning from bot, since news item is added.")
old_comment.delete()
elif not has_news_added:
else:
print("No news item found")

pr.create_issue_comment(
"""\
**Warning!** No news item is found for this PR. If this is an user facing change/feature/fix,
please add a news item by copying the format from `news/TEMPLATE.rst`.
if old_comment:
print("Old warning remains relevant, no action needed.")
else:
pr.create_issue_comment(
"""\
**Warning!** No news item is found for this PR. If this is a user-facing change/feature/fix,
please add a news item by copying the format from `news/TEMPLATE.rst`.
"""
)
)
assert False


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
types:
- prereleased
- published
workflow_dispatch: null
workflow_dispatch:

jobs:
coverage:
Expand Down
99 changes: 99 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
venv/
*.egg-info/
.installed.cfg
*.egg
bin/
temp/
tags/
errors.err

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt
MANIFEST

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/

# Translations
*.mo
*.pot

# Mr Developer
.mr.developer.cfg
.project
.pydevproject

# Django stuff:
*.log

# Sphinx documentation
docs/build/
docs/source/generated/

# pytest
.pytest_cache/

# PyBuilder
target/

# Editor files
# mac
.DS_Store
*~

# vim
*.swp
*.swo

# pycharm
.idea/

# VSCode
.vscode/

# Ipython Notebook
.ipynb_checkpoints

# version information
setup.cfg
/src/{{ cookiecutter.github_org }}/*/version.cfg

# Rever
rever/
47 changes: 47 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
default_language_version:
python: python3
ci:
autofix_commit_msg: |
[pre-commit.ci] auto fixes from pre-commit hooks
autofix_prs: true
autoupdate_branch: 'pre-commit-autoupdate'
autoupdate_commit_msg: '[pre-commit.ci] pre-commit autoupdate'
autoupdate_schedule: monthly
skip: [no-commit-to-branch]
submodules: false
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-yaml
exclude: '.github/'
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-case-conflict
- id: check-merge-conflict
- id: check-toml
- id: check-added-large-files
- repo: https://github.com/psf/black
rev: 24.4.2
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: 7.0.0
hooks:
- id: flake8
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
args: ["--profile", "black"]
- repo: https://github.com/kynan/nbstripout
rev: 0.7.1
hooks:
- id: nbstripout
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: no-commit-to-branch
name: Prevent Commit to Main Branch
args: ["--branch", "main"]
stages: [pre-commit]
42 changes: 23 additions & 19 deletions auto_api.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env python

from pathlib import Path
import optparse
import re
import shlex
import subprocess
import sys
from pathlib import Path


def call(cmd, cwd, capture_output=False):
Expand All @@ -20,16 +20,16 @@ def __init__(self, prog_name, *args, **kwargs):
super(Parser, self).__init__(*args, **kwargs)
self.prog_name = prog_name

def detailed_error(self, msg):
self.exit(2, f"{prog_name}: error: {msg}\n")

parser = Parser(prog_name=prog_name_short,
usage='\n'.join([
"%prog <package_name> <path_to_package_proper> <path_to_api_directory>",
"Automatically populate the API directory for a package.",
"This only handles packages with single-depth submodules.",
]),
epilog="Please report bugs on https://github.com/Billingegroup/release-scripts/issues."
parser = Parser(
prog_name=prog_name_short,
usage="\n".join(
[
"%prog <package_name> <path_to_package_proper> <path_to_api_directory>",
"Automatically populate the API directory for a package.",
"This only handles packages with single-depth submodules.",
]
),
epilog="Please report bugs on https://github.com/Billingegroup/release-scripts/issues.",
)

return parser
Expand All @@ -50,17 +50,17 @@ def main(opts, pargs):

# Populate API directory
def gen_package_files(package_dir, package_name):
""" Generate package files.
"""Generate package files.

Parameters
----------

package_dir: Path
The package directory (e.g. /src/diffpy/pdfmorph).
package_name: str
The name of the package (e.g. diffpy.pdfmorph).
"""
eq_spacing = "="*len(f"{package_name} package")
eq_spacing = "=" * len(f"{package_name} package")
s = f""":tocdepth: -1

{package_name} package
Expand Down Expand Up @@ -96,15 +96,19 @@ def gen_package_files(package_dir, package_name):
sm_names = []
skip_files = ["__init__", "version"]
for child in package_dir.iterdir():
if child.is_file() and child.suffix == ".py" and child.stem not in skip_files:
if (
child.is_file()
and child.suffix == ".py"
and child.stem not in skip_files
):
sm_names.append(f"{package_name}.{child.stem}")
if len(sm_names) > 0:
s += """
Submodules
----------
"""
for sm_name in sm_names:
dsh_spacing = "^"*len(f"{sm_name} module")
dsh_spacing = "^" * len(f"{sm_name} module")
s += f"""
{sm_name} module
{dsh_spacing}
Expand All @@ -114,7 +118,7 @@ def gen_package_files(package_dir, package_name):
:undoc-members:
:show-inheritance:
"""

s += "\n"
package_file = api_dir / f"{package_name}.rst"
with open(package_file, "w") as pfile:
Expand Down
2 changes: 1 addition & 1 deletion basic_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ mkdir "$tmp_release_dir"
project_path="$(pwd)"
project="${project_path##*/}"
tgz_name="$project-$version.tar.gz"
tar --exclude="./$tmp_release_dir" -zcf "./$tmp_release_dir/$tgz_name" .
tar --exclude="./$tmp_release_dir" -zcf "./$tmp_release_dir/$tgz_name" .

# GitHub Release
git tag $version $(git rev-parse HEAD)
Expand Down
Loading