Skip to content

Commit

Permalink
Merge pull request #333 from WilliamJamieson/feature/cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamJamieson committed Sep 12, 2022
2 parents 410dfc1 + 8683c81 commit b3916db
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 20 deletions.
3 changes: 2 additions & 1 deletion setup.cfg → .flake8
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# this file exists to support an editable PEP517 install and for `flake8` (https://github.com/PyCQA/flake8/issues/234)
# and `sphinx` configuration
[flake8]
ignore = E501, E203, W503
max-line-length = 120
extend-ignore = E203
exclude = .git, __pycache__, build, dist, eggs, *.egg, reference_files, schemas, source, .pytest_cache, .tox
16 changes: 16 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/asottile/pyupgrade
rev: v2.37.3
hooks:
- id: pyupgrade
args: ["--py38-plus"]

- repo: https://github.com/PyCQA/autoflake
rev: v1.5.3
hooks:
- id: autoflake

- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
Expand All @@ -21,6 +32,11 @@ repos:
hooks:
- id: black

- repo: https://github.com/asottile/blacken-docs
rev: v1.12.1
hooks:
- id: blacken-docs

- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
hooks:
Expand Down
7 changes: 3 additions & 4 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
#
Expand All @@ -10,7 +9,7 @@
import sys
from pathlib import Path

import toml
import tomli
from pkg_resources import get_distribution

# -- Project information -----------------------------------------------------
Expand All @@ -21,8 +20,8 @@
sys.exit(1)

# Get configuration information from `pyproject.toml`
with open(Path(__file__).parent.parent.parent / "pyproject.toml") as configuration_file:
conf = toml.load(configuration_file)
with open(Path(__file__).parent.parent.parent / "pyproject.toml", "rb") as configuration_file:
conf = tomli.load(configuration_file)
configuration = conf["project"]

project = configuration["name"]
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dynamic = ['version']

[project.optional-dependencies]
docs = [
'toml',
'tomli',
'sphinx',
'sphinx-asdf >= 0.1.3',
'sphinx-astropy',
Expand Down Expand Up @@ -48,7 +48,7 @@ test = [

[build-system]
requires = [
"setuptools >=42",
"setuptools >=61",
"setuptools_scm[toml] >=3.4",
"wheel",
]
Expand Down
2 changes: 0 additions & 2 deletions reference_files/generate/generate
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env python
#-*- coding: utf-8 -*-

from __future__ import unicode_literals

import os

Expand Down
2 changes: 1 addition & 1 deletion scripts/generate-core-manifests.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def represent_string(dumper, data):
for path in sorted(glob.glob("schemas/stsci.edu/asdf/version_map-*.yaml")):
version_map = yaml.safe_load(open(path).read())
version = path.split("/")[-1].split("-")[-1].split(".yaml")[0]
tags = sorted([k + "-" + str(v) for k, v in version_map["tags"].items() if "/transform/" not in k])
tags = sorted(k + "-" + str(v) for k, v in version_map["tags"].items() if "/transform/" not in k)

tag_defs = []
for tag in tags:
Expand Down
8 changes: 4 additions & 4 deletions scripts/update-schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ def get_schemas(pattern):

dedupe[basepath] = version

return ["{}-{}.yaml".format(x, y) for x, y in dedupe.items()]
return [f"{x}-{y}.yaml" for x, y in dedupe.items()]


def update_version(string):

groups = re.search(r"((\d)\.(\d)\.(\d))", string).groups()
bumped = int(groups[2]) + 1

new_version = "{}.{}.{}".format(groups[1], bumped, groups[3])
new_version = f"{groups[1]}.{bumped}.{groups[3]}"
return re.sub(r"((\d)\.(\d)\.(\d))", new_version, string)


Expand All @@ -42,7 +42,7 @@ def create_updated_schema(schema, pattern, new_pattern):
new_schema = re.sub(name, updated, schema)

with open(new_schema, "w") as new_file:
with open(schema, "r") as old_file:
with open(schema) as old_file:
for line in old_file:
line = line.replace(pattern, new_pattern)
line = line.replace(name, updated)
Expand All @@ -53,7 +53,7 @@ def main():

if len(sys.argv) != 2:
name = os.path.basename(sys.argv[0])
sys.stderr.write("USAGE: {} <pattern>\n".format(name))
sys.stderr.write(f"USAGE: {name} <pattern>\n")
exit(1)

pattern = sys.argv[1]
Expand Down
4 changes: 2 additions & 2 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ def list_latest_schema_paths(path):
else:
latest_by_id_base[id_base] = (version, path)

return sorted([p for _, p in latest_by_id_base.values()])
return sorted(p for _, p in latest_by_id_base.values())


def list_legacy_schema_paths(path):
paths = list_schema_paths(path)
latest_paths = list_latest_schema_paths(path)

return sorted([p for p in paths if p not in latest_paths])
return sorted(p for p in paths if p not in latest_paths)


def ref_to_id(schema_id, ref):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ def test_docs_schema_links(

counter = collections.Counter(docs_schema_ids)
if max(counter.values()) > 1:
remove_list = "\n".join(sorted([tag for tag, count in counter.items() if count > 1]))
remove_list = "\n".join(sorted(tag for tag, count in counter.items() if count > 1))
message = "The documentation contains duplicate links to the following schemas: \n" f"{remove_list}"
assert False, message
6 changes: 3 additions & 3 deletions tests/test_version_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_latest_version_map(latest_schema_tags):

tag_base_to_version = dict([tag.rsplit("-", 1) for tag in latest_schema_tags])

expected_tag_bases = set([t for t in tag_base_to_version.keys() if not is_deprecated(t)])
expected_tag_bases = {t for t in tag_base_to_version.keys() if not is_deprecated(t)}
vm_tag_bases = set(vm["tags"].keys())
if not expected_tag_bases.issubset(vm_tag_bases):
missing_tag_bases = expected_tag_bases - vm_tag_bases
Expand All @@ -70,7 +70,7 @@ def test_latest_version_map(latest_schema_tags):
)
assert False, message

incorrect_tag_bases = sorted([tag for tag in expected_tag_bases if vm["tags"][tag] != tag_base_to_version[tag]])
incorrect_tag_bases = sorted(tag for tag in expected_tag_bases if vm["tags"][tag] != tag_base_to_version[tag])
if len(incorrect_tag_bases) > 0:
update_list = "\n".join(
[f"""{tag}: {vm["tags"][tag]} --> {tag_base_to_version[tag]}""" for tag in incorrect_tag_bases]
Expand All @@ -92,7 +92,7 @@ def test_version_map_tags_retained(path, previous_path):
vm = load_yaml(path)
prev_vm = load_yaml(previous_path)

expected_tags = set([t for t in prev_vm["tags"].keys() if not is_deprecated(t)])
expected_tags = {t for t in prev_vm["tags"].keys() if not is_deprecated(t)}
tags = set(vm["tags"].keys())
if not expected_tags.issubset(tags):
missing_tags = expected_tags - tags
Expand Down

0 comments on commit b3916db

Please sign in to comment.