Skip to content

Commit

Permalink
Merge branch 'mainline' into dependabot/pip/ruff-eq-0.0.star
Browse files Browse the repository at this point in the history
  • Loading branch information
agerveshi authored Oct 10, 2023
2 parents 32f6153 + 7789968 commit 8fdb341
Show file tree
Hide file tree
Showing 18 changed files with 177 additions and 70 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Publish
on:
workflow_dispatch:

jobs:
PublishToRepository:
runs-on: ubuntu-latest
environment: release
permissions:
id-token: write
contents: read
env:
CODEARTIFACT_REGION: "us-west-2"
CODEARTIFACT_DOMAIN: ${{ secrets.CODEARTIFACT_DOMAIN }}
CODEARTIFACT_ACCOUNT_ID: ${{ secrets.CODEARTIFACT_ACCOUNT_ID }}
CODEARTIFACT_REPOSITORY: ${{ secrets.CODEARTIFACT_REPOSITORY }}
CUSTOMER_REPOSITORY: ${{ secrets.CUSTOMER_REPOSITORY }}
steps:
- name: "Checkout"
uses: actions/checkout@v4
with:
ref: release
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_CODEARTIFACT_ROLE }}
aws-region: us-west-2
mask-aws-account-id: true
- name: Install dependencies
run: |
CODEARTIFACT_AUTH_TOKEN=$(aws codeartifact get-authorization-token --domain ${{ secrets.CODEARTIFACT_DOMAIN }} --domain-owner ${{ secrets.CODEARTIFACT_ACCOUNT_ID }} --query authorizationToken --output text --region us-west-2)
echo "::add-mask::$CODEARTIFACT_AUTH_TOKEN"
echo CODEARTIFACT_AUTH_TOKEN=$CODEARTIFACT_AUTH_TOKEN >> $GITHUB_ENV
pip install --upgrade hatch
pip install --upgrade twine
- name: Run Build
run: hatch build
- name: Publish to Repository
run: |
export TWINE_USERNAME=aws
export TWINE_PASSWORD=`aws codeartifact get-authorization-token --domain ${{ secrets.CODEARTIFACT_DOMAIN }} --domain-owner ${{ secrets.CODEARTIFACT_ACCOUNT_ID }} --query authorizationToken --output text`
export TWINE_REPOSITORY_URL=`aws codeartifact get-repository-endpoint --domain ${{ secrets.CODEARTIFACT_DOMAIN }} --domain-owner ${{ secrets.CODEARTIFACT_ACCOUNT_ID }} --repository ${{ secrets.CODEARTIFACT_REPOSITORY }} --format pypi --query repositoryEndpoint --output text`
twine upload dist/*
- name: Publish to Customer Repository
run: |
export TWINE_USERNAME=aws
export TWINE_PASSWORD=`aws codeartifact get-authorization-token --domain ${{ secrets.CODEARTIFACT_DOMAIN }} --domain-owner ${{ secrets.CODEARTIFACT_ACCOUNT_ID }} --query authorizationToken --output text`
export TWINE_REPOSITORY_URL=`aws codeartifact get-repository-endpoint --domain ${{ secrets.CODEARTIFACT_DOMAIN }} --domain-owner ${{ secrets.CODEARTIFACT_ACCOUNT_ID }} --repository ${{ secrets.CUSTOMER_REPOSITORY }} --format pypi --query repositoryEndpoint --output text`
twine upload dist/*
PublishToService:
runs-on: ubuntu-latest
environment: release
permissions:
id-token: write
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_CODEBUILD_RELEASE_PUBLISH_ROLE }}
aws-region: us-west-2
mask-aws-account-id: true
- name: Run CodeBuild
uses: aws-actions/aws-codebuild-run-build@v1
with:
project-name: openjd-adaptor-runtime-for-python-Publish
hide-cloudwatch-logs: true
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: release
fetch-depth: 0
Expand Down
14 changes: 8 additions & 6 deletions .github/workflows/reuse_python_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ jobs:
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11']
os: [ubuntu-latest, macOS-latest]
os: [ubuntu-latest]
env:
PYTHON: ${{ matrix.python-version }}
CODEARTIFACT_REGION: "us-west-2"
CODEARTIFACT_DOMAIN: ${{ secrets.CODEARTIFACT_DOMAIN }}
CODEARTIFACT_ACCOUNT_ID: ${{ secrets.CODEARTIFACT_ACCOUNT_ID }}
CODEARTIFACT_REPOSITORY: ${{ secrets.CODEARTIFACT_REPOSITORY }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
if: ${{ !inputs.branch }}

- uses: actions/checkout@v3
- uses: actions/checkout@v4
if: ${{ inputs.branch }}
with:
ref: ${{ inputs.branch }}
Expand All @@ -42,18 +42,20 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v3
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_CODEARTIFACT_ROLE }}
aws-region: us-west-2
mask-aws-account-id: true

- name: Install Hatch
- name: Setup CodeArtifact Linux
run: |
CODEARTIFACT_AUTH_TOKEN=$(aws codeartifact get-authorization-token --domain ${{ secrets.CODEARTIFACT_DOMAIN }} --domain-owner ${{ secrets.CODEARTIFACT_ACCOUNT_ID }} --query authorizationToken --output text --region us-west-2)
echo "::add-mask::$CODEARTIFACT_AUTH_TOKEN"
echo CODEARTIFACT_AUTH_TOKEN=$CODEARTIFACT_AUTH_TOKEN >> $GITHUB_ENV
pip install --upgrade -r requirements-development.txt
- name: Install Dependencies
run: pip install --upgrade -r requirements-development.txt

- name: Run Linting
run: hatch run lint
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ __pycache__/
/build
/dist
_version.py
.vscode
2 changes: 1 addition & 1 deletion THIRD-PARTY-LICENSES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
** Python-jsonschema; version 4.19 -- https://github.com/python-jsonschema/jsonschema
** Python-jsonschema; version 4.17 -- https://github.com/python-jsonschema/jsonschema
Copyright (c) 2013 Julian Berman

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ requires-python = ">=3.9"

dependencies = [
"pyyaml ~= 6.0",
"jsonschema >= 4.19.0, == 4.*",
"jsonschema >= 4.17.0, == 4.*",
]

[tool.hatch.build]
Expand Down
6 changes: 3 additions & 3 deletions requirements-testing.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
coverage[toml] >= 7.3, == 7.*
pytest >= 7.4, == 7.*
coverage[toml] == 7.*
pytest == 7.*
pytest-cov >= 4.1, == 4.*
pytest-timeout >= 2.1, == 2.*
pytest-xdist >= 3.3.1, == 3.*
black >= 23.7, == 23.*
black == 23.*
ruff == 0.0.*
mypy >= 1.5.1, == 1.5.*
types-PyYAML ~= 6.0
Expand Down
8 changes: 7 additions & 1 deletion src/openjd/adaptor_runtime/_background/frontend_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,17 @@ def __init__(
signal.signal(signal.SIGINT, self._sigint_handler)
signal.signal(signal.SIGTERM, self._sigint_handler)

def init(self, adaptor_module: ModuleType, init_data: dict = {}) -> None:
def init(
self, adaptor_module: ModuleType, init_data: dict = {}, path_mapping_data: dict = {}
) -> None:
"""
Creates the backend process then sends a heartbeat request to verify that it has started
successfully.
Args:
adaptor_module (ModuleType): The module of the adaptor running the runtime.
init_data (dict): Data to pass to the adaptor during initialization.
path_mapping_data (dict): Path mapping rules to make available to the adaptor while it's running.
"""
if adaptor_module.__package__ is None:
raise Exception(f"Adaptor module is not a package: {adaptor_module}")
Expand All @@ -85,6 +89,8 @@ def init(self, adaptor_module: ModuleType, init_data: dict = {}) -> None:
self._connection_file_path,
"--init-data",
json.dumps(init_data),
"--path-mapping-rules",
json.dumps(path_mapping_data),
]
try:
process = subprocess.Popen(
Expand Down
5 changes: 3 additions & 2 deletions src/openjd/adaptor_runtime/_entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def start(self) -> None:
f"Adaptor module is not loaded: {self.adaptor_class.__module__}"
)

frontend.init(adaptor_module, init_data)
frontend.init(adaptor_module, init_data, path_mapping_data)
frontend.start()
elif subcommand == "run":
frontend.run(run_data)
Expand Down Expand Up @@ -241,6 +241,7 @@ def _build_argparser(self) -> ArgumentParser:
path_mapping_rules = ArgumentParser(add_help=False)
path_mapping_rules.add_argument(
"--path-mapping-rules",
default="",
required=False,
type=_load_data,
help=_CLI_HELP_TEXT["path_mapping_rules"],
Expand All @@ -266,7 +267,7 @@ def _build_argparser(self) -> ArgumentParser:
)

# "Hidden" command that actually runs the adaptor runtime in background mode
bg_subparser.add_parser("_serve", parents=[init_data, connection_file])
bg_subparser.add_parser("_serve", parents=[init_data, path_mapping_rules, connection_file])

bg_subparser.add_parser("start", parents=[init_data, path_mapping_rules, connection_file])
bg_subparser.add_parser("run", parents=[run_data, connection_file])
Expand Down
22 changes: 17 additions & 5 deletions src/openjd/adaptor_runtime/adaptors/_path_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ class PathMappingRule:
def __init__(
self,
*,
source_os: str,
source_path_format: str,
source_path: str,
destination_path: str,
destination_os: str = OSName(),
):
for label, value in (
("source_os", source_os),
("source_path_format", source_path_format),
("source_path", source_path),
("destination_path", destination_path),
):
Expand All @@ -60,8 +60,10 @@ def __init__(

self.source_path: str = source_path
self.destination_path: str = destination_path
self._source_os: str = OSName(source_os) # Raises ValueError if not valid OS
self._is_windows_source: bool = OSName.is_windows(self._source_os)
self._source_path_format: str = OSName(
source_path_format
) # Raises ValueError if not valid OS
self._is_windows_source: bool = OSName.is_windows(self._source_path_format)

self._destination_os: str = OSName(destination_os) # Raises ValueError if not valid OS
self._is_windows_destination: bool = OSName.is_windows(self._destination_os)
Expand Down Expand Up @@ -91,13 +93,23 @@ def from_dict(*, rule: dict[str, str]) -> PathMappingRule:
if not rule:
raise ValueError("Empty path mapping rule")

# TODO - DELETE ONCE MIGRATION COMPLETE
# The field "source_os" was renamed to "source_path_format", but interfaces may still
# provide the old name until they're updated. Remove once we're sure all interfaces are
# updated.
if "source_os" in rule:
new_rule = dict(**rule)
new_rule["source_path_format"] = new_rule["source_os"]
del new_rule["source_os"]
rule = new_rule
# END TODO
return PathMappingRule(**rule)

def to_dict(self) -> dict[str, str]:
"""Builds a PathMappingRule given a dict with the fields required by __init__
raises TypeError, ValueError: if rule is None, an empty dict, or nonvalid"""
return {
"source_os": self._source_os,
"source_path_format": self._source_path_format,
"source_path": self.source_path,
"destination_os": self._destination_os,
"destination_path": self.destination_path,
Expand Down
2 changes: 1 addition & 1 deletion src/openjd/adaptor_runtime_client/client_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# due to some applications running an older Python version that can't import newer typing
@_dataclass
class PathMappingRule:
source_os: str
source_path_format: str
source_path: str
destination_path: str
destination_os: str
Expand Down
Loading

0 comments on commit 8fdb341

Please sign in to comment.