From 6d4a27459afbe68d2ec68dd9e72e0783e2e489f9 Mon Sep 17 00:00:00 2001 From: Mike Gray Date: Thu, 24 Aug 2023 21:50:09 -0500 Subject: [PATCH 1/5] fix: always generate requirements.txt closes #11 --- src/index.ts | 18 +++++++++--------- .../OVOSSkillProject.test.ts.snap | 8 ++++++++ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/index.ts b/src/index.ts index edf0f5a..cd9db8a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -197,16 +197,16 @@ ${line}`; new SampleFile(this, 'skill.json', { contents: '{}', }); - let requirements = 'ovos-utils\novos-bus-client\novos-workshop'; + let requirements = 'ovos-utils\novos-bus-client\novos-workshop\n# Your requirements here\n'; + if (existsSync('requirements.txt')) { + const existingRequirements = readFileSync('requirements.txt').toString(); + requirements = `${existingRequirements}\n${requirements}`; + } else { + new TextFile(this, 'requirements.txt', { + lines: requirements.split('\n'), + }); + } if (retrofit) { - if (existsSync('requirements.txt')) { - const existingRequirements = readFileSync('requirements.txt').toString(); - requirements = `${existingRequirements}\n${requirements}`; - } else { - new TextFile(this, 'requirements.txt', { - lines: requirements.split('\n'), - }); - } if (existsSync('__init__.py') && !existsSync('setup.py')) { OVOSSkillProject.modernizeSkillCode('__init__.py'); } else if (!existsSync('__init__.py') && !existsSync('setup.py')) { diff --git a/test/__snapshots__/OVOSSkillProject.test.ts.snap b/test/__snapshots__/OVOSSkillProject.test.ts.snap index ec6f05a..ea5b1c5 100644 --- a/test/__snapshots__/OVOSSkillProject.test.ts.snap +++ b/test/__snapshots__/OVOSSkillProject.test.ts.snap @@ -17,6 +17,7 @@ Object { /.projen/deps.json linguist-generated /.projen/files.json linguist-generated /.projen/tasks.json linguist-generated +/requirements.txt linguist-generated /setup.py linguist-generated", ".github/workflows/license_tests.yml": "# ~~ Generated by projen. To modify, edit .projenrc.json and run \\"npx projen\\". @@ -287,6 +288,7 @@ dmypy.json .pytype/ cython_debug/ !/setup.py +!/requirements.txt !/.github/workflows/license_tests.yml !/.github/workflows/propose_release.yml !/.github/workflows/publish_alpha.yml @@ -309,6 +311,7 @@ cython_debug/ ".projen/deps.json", ".projen/files.json", ".projen/tasks.json", + "requirements.txt", "setup.py", ], }, @@ -442,6 +445,11 @@ TODO: ## Tags ovos skill +", + "requirements.txt": "ovos-utils +ovos-bus-client +ovos-workshop +# Your requirements here ", "setup.py": "#!/usr/bin/env python3 from setuptools import setup From 581f2a62f50f53e3a1f7d127ee16c10c8cfd192f Mon Sep 17 00:00:00 2001 From: Mike Gray Date: Thu, 24 Aug 2023 21:56:45 -0500 Subject: [PATCH 2/5] fix: generate version.py on retrofit fixes #10 --- src/index.ts | 5 + test/OVOSSkillProject.test.ts | 12 + .../OVOSSkillProject.test.ts.snap | 519 ++++++++++++++++++ 3 files changed, 536 insertions(+) diff --git a/src/index.ts b/src/index.ts index cd9db8a..98a3c0e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -206,6 +206,11 @@ ${line}`; lines: requirements.split('\n'), }); } + if (!existsSync('version.py') && retrofit) { + new TextFile(this, 'version.py', { + lines: 'VERSION_MAJOR = 0\nVERSION_MINOR = 0\nVERSION_BUILD = 1\nVERSION_ALPHA = 0'.split('\n'), + }); + }; if (retrofit) { if (existsSync('__init__.py') && !existsSync('setup.py')) { OVOSSkillProject.modernizeSkillCode('__init__.py'); diff --git a/test/OVOSSkillProject.test.ts b/test/OVOSSkillProject.test.ts index f6e2aa4..da0dc96 100644 --- a/test/OVOSSkillProject.test.ts +++ b/test/OVOSSkillProject.test.ts @@ -8,6 +8,18 @@ test('snapshot', () => { pypiName: 'test-skill', }); + const synth = Testing.synth(project); + expect(synth).toMatchSnapshot(); +}); + +test('snapshot retrofit', () => { + const project = new OVOSSkillProject({ + name: 'test', + skillClass: 'TestSkill', + pypiName: 'test-skill', + retrofit: true, + }); + const synth = Testing.synth(project); expect(synth).toMatchSnapshot(); }); \ No newline at end of file diff --git a/test/__snapshots__/OVOSSkillProject.test.ts.snap b/test/__snapshots__/OVOSSkillProject.test.ts.snap index ea5b1c5..c48af92 100644 --- a/test/__snapshots__/OVOSSkillProject.test.ts.snap +++ b/test/__snapshots__/OVOSSkillProject.test.ts.snap @@ -657,3 +657,522 @@ VERSION_BUILD = 1 VERSION_ALPHA = 0", } `; + +exports[`snapshot retrofit 1`] = ` +Object { + ".gitattributes": "# ~~ Generated by projen. To modify, edit .projenrc.json and run \\"npx projen\\". + +/.gitattributes linguist-generated +/.github/workflows/license_tests.yml linguist-generated +/.github/workflows/propose_release.yml linguist-generated +/.github/workflows/publish_alpha.yml linguist-generated +/.github/workflows/publish_release.yml linguist-generated +/.github/workflows/pull-request-lint.yml linguist-generated +/.github/workflows/skill_tests.yml linguist-generated +/.github/workflows/update_skill_json.yml linguist-generated +/.gitignore linguist-generated +/.projen/** linguist-generated +/.projen/deps.json linguist-generated +/.projen/files.json linguist-generated +/.projen/tasks.json linguist-generated +/requirements.txt linguist-generated +/setup.py linguist-generated +/version.py linguist-generated", + ".github/workflows/license_tests.yml": "# ~~ Generated by projen. To modify, edit .projenrc.json and run \\"npx projen\\". + +name: license_tests +on: + push: {} + workflow_dispatch: {} + pull_request: + branches: + - master + - main +jobs: + license_tests: + name: license_tests + permissions: + contents: read + uses: neongeckocom/.github/.github/workflows/license_tests.yml@master +", + ".github/workflows/propose_release.yml": "# ~~ Generated by projen. To modify, edit .projenrc.json and run \\"npx projen\\". + +name: propose_release +on: + workflow_dispatch: + inputs: + release_type: + type: choice + description: Release Type + options: + - build + - minor + - major + - patch + - alpha +jobs: + update_version: + name: update_version + permissions: + contents: write + packages: write + uses: neongeckocom/.github/.github/workflows/propose_semver_release.yml@master + with: + release_type: \${{ inputs.release_type }} + version_file: version.py + alpha_var: VERSION_ALPHA + build_var: VERSION_BUILD + minor_var: VERSION_MINOR + major_var: VERSION_MAJOR + update_changelog: true + branch: dev + pull_changes: + needs: update_version + permissions: + contents: write + uses: neongeckocom/.github/.github/workflows/pull_master.yml@master + with: + pr_assignee: \${{ github.actor }} + pr_draft: false + pr_title: \${{ needs.update_version.outputs.version }} + pr_body: \${{ needs.update_version.outputs.changelog }} +", + ".github/workflows/publish_alpha.yml": "# ~~ Generated by projen. To modify, edit .projenrc.json and run \\"npx projen\\". + +name: publish_alpha +on: + push: + branches: + - dev + paths: + - \\"!version.py\\" + - \\"!test/**\\" + - \\"!examples/**\\" + - \\"!.github/**\\" + - \\"!.gitignore\\" + - \\"!LICENSE\\" + - \\"!CHANGELOG.md\\" + - \\"!MANIFEST.in\\" + - \\"!README.md\\" + - \\"!scripts/*\\" + workflow_dispatch: {} +jobs: + publish_alpha_release: + permissions: + contents: write + packages: write + uses: neongeckocom/.github/.github/workflows/publish_alpha_release.yml@master + with: + version_file: version.py + publish_prerelease: true + update_changelog: true + alpha_var: VERSION_ALPHA + build_var: VERSION_BUILD + minor_var: VERSION_MINOR + major_var: VERSION_MAJOR +", + ".github/workflows/publish_release.yml": "# ~~ Generated by projen. To modify, edit .projenrc.json and run \\"npx projen\\". + +name: publish_release +on: + push: + branches: + - master + - main +jobs: + build_and_publish_pypi_and_release: + permissions: + contents: write + packages: write + uses: neongeckocom/.github/.github/workflows/publish_stable_release.yml@master + secrets: + PYPI_TOKEN: \${{ secrets.PYPI_TOKEN }} +", + ".github/workflows/pull-request-lint.yml": "# ~~ Generated by projen. To modify, edit .projenrc.json and run \\"npx projen\\". + +name: pull-request-lint +on: + pull_request_target: + types: + - labeled + - opened + - synchronize + - reopened + - ready_for_review + - edited +jobs: + validate: + name: Validate PR title + runs-on: ubuntu-latest + permissions: + pull-requests: write + steps: + - uses: amannn/action-semantic-pull-request@v5.0.2 + env: + GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }} + with: + types: |- + feat + fix + chore + requireScope: false +", + ".github/workflows/skill_tests.yml": "# ~~ Generated by projen. To modify, edit .projenrc.json and run \\"npx projen\\". + +name: skill_tests +on: + pull_request: {} + workflow_dispatch: {} +jobs: + py_build_tests: + name: py_build_tests + permissions: + contents: read + uses: neongeckocom/.github/.github/workflows/python_build_tests.yml@master + skill_unit_tests: + name: skill_unit_tests + permissions: + contents: read + uses: neongeckocom/.github/.github/workflows/skill_tests.yml@master + skill_intent_tests: + name: skill_intent_tests + permissions: + contents: read + uses: neongeckocom/.github/.github/workflows/skill_test_intents.yml@master + skill_resource_tests: + name: skill_resource_tests + permissions: + contents: read + uses: neongeckocom/.github/.github/workflows/skill_test_resources.yml@master + skill_install_tests: + name: skill_install_tests + permissions: + contents: read + uses: neongeckocom/.github/.github/workflows/skill_test_installation.yml@master +", + ".github/workflows/update_skill_json.yml": "# ~~ Generated by projen. To modify, edit .projenrc.json and run \\"npx projen\\". + +name: update_skill_json +on: + push: {} +jobs: + update-skill-json: + name: update_skill_json + permissions: + contents: write + uses: neongeckocom/.github/.github/workflows/skill_update_json_spec.yml@master +", + ".gitignore": "# ~~ Generated by projen. To modify, edit .projenrc.json and run \\"npx projen\\". +node_modules/ +!/.gitattributes +!/.projen/tasks.json +!/.projen/deps.json +!/.projen/files.json +!/.github/workflows/pull-request-lint.yml +.DS_Store +node_modules +__pycache__/ +*.py[cod] +*$py.class +*.so +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST +*.manifest +*.spec +pip-log.txt +pip-delete-this-directory.txt +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ +*.mo +*.pot +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal +instance/ +.webassets-cache +.scrapy +docs/_build/ +.pybuilder/ +target/ +.ipynb_checkpoints +profile_default/ +ipython_config.py +__pypackages__/ +celerybeat-schedule +celerybeat.pid +*.sage.py +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ +.spyderproject +.spyproject +.ropeproject +/site +.mypy_cache/ +.dmypy.json +dmypy.json +.pyre/ +.pytype/ +cython_debug/ +!/setup.py +!/requirements.txt +!/version.py +!/.github/workflows/license_tests.yml +!/.github/workflows/propose_release.yml +!/.github/workflows/publish_alpha.yml +!/.github/workflows/publish_release.yml +!/.github/workflows/skill_tests.yml +!/.github/workflows/update_skill_json.yml +", + ".projen/files.json": Object { + "//": "~~ Generated by projen. To modify, edit .projenrc.json and run \\"npx projen\\".", + "files": Array [ + ".gitattributes", + ".github/workflows/license_tests.yml", + ".github/workflows/propose_release.yml", + ".github/workflows/publish_alpha.yml", + ".github/workflows/publish_release.yml", + ".github/workflows/pull-request-lint.yml", + ".github/workflows/skill_tests.yml", + ".github/workflows/update_skill_json.yml", + ".gitignore", + ".projen/deps.json", + ".projen/files.json", + ".projen/tasks.json", + "requirements.txt", + "setup.py", + "version.py", + ], + }, + ".projen/tasks.json": Object { + "//": "~~ Generated by projen. To modify, edit .projenrc.json and run \\"npx projen\\".", + "tasks": Object { + "build": Object { + "description": "Full release build", + "name": "build", + "steps": Array [ + Object { + "spawn": "default", + }, + Object { + "spawn": "pre-compile", + }, + Object { + "spawn": "compile", + }, + Object { + "spawn": "post-compile", + }, + Object { + "spawn": "test", + }, + Object { + "spawn": "package", + }, + ], + }, + "clobber": Object { + "condition": "git diff --exit-code > /dev/null", + "description": "hard resets to HEAD of origin and cleans the local repo", + "env": Object { + "BRANCH": "$(git branch --show-current)", + }, + "name": "clobber", + "steps": Array [ + Object { + "exec": "git checkout -b scratch", + "name": "save current HEAD in \\"scratch\\" branch", + }, + Object { + "exec": "git checkout $BRANCH", + }, + Object { + "exec": "git fetch origin", + "name": "fetch latest changes from origin", + }, + Object { + "exec": "git reset --hard origin/$BRANCH", + "name": "hard reset to origin commit", + }, + Object { + "exec": "git clean -fdx", + "name": "clean all untracked files", + }, + Object { + "say": "ready to rock! (unpushed commits are under the \\"scratch\\" branch)", + }, + ], + }, + "compile": Object { + "description": "Only compile", + "name": "compile", + }, + "default": Object { + "description": "Synthesize project files", + "env": Object { + "FILENAME": ".projenrc.json", + }, + "name": "default", + "steps": Array [ + Object { + "builtin": "run-projenrc-json", + }, + ], + }, + "eject": Object { + "description": "Remove projen from the project", + "env": Object { + "PROJEN_EJECTING": "true", + }, + "name": "eject", + "steps": Array [ + Object { + "spawn": "default", + }, + ], + }, + "package": Object { + "description": "Creates the distribution package", + "name": "package", + }, + "post-compile": Object { + "description": "Runs after successful compilation", + "name": "post-compile", + }, + "pre-compile": Object { + "description": "Prepare the project for compilation", + "name": "pre-compile", + }, + "test": Object { + "description": "Run tests", + "name": "test", + }, + }, + }, + "README.md": "# replace this", + "requirements.txt": "ovos-utils +ovos-bus-client +ovos-workshop +# Your requirements here +", + "setup.py": "#!/usr/bin/env python3 +from setuptools import setup +from os import walk, path + +BASEDIR = path.abspath(path.dirname(__file__)) +URL = \\"TODO: Add 'repositoryUrl' to .projenrc.json and run pj\\" +SKILL_CLAZZ = \\"TestSkill\\" # needs to match __init__.py class name +PYPI_NAME = \\"test-skill\\" # pip install PYPI_NAME + +# below derived from github url to ensure standard skill_id +SKILL_AUTHOR, SKILL_NAME = URL.split(\\".com/\\")[-1].split(\\"/\\") +SKILL_PKG = SKILL_NAME.lower().replace(\\"-\\", \\"_\\") +PLUGIN_ENTRY_POINT = f\\"{SKILL_NAME.lower()}.{SKILL_AUTHOR.lower()}={SKILL_PKG}:{SKILL_CLAZZ}\\" +# skill_id=package_name:SkillClass +BASE_PATH = BASE_PATH = path.abspath(path.join(path.dirname(__file__), \\"\\")) + + +def get_version(): + \\"\\"\\"Find the version of the package\\"\\"\\" + version = None + version_file = path.join(BASE_PATH, \\"version.py\\") + major, minor, build, alpha = (None, None, None, None) + with open(version_file) as f: + for line in f: + if \\"VERSION_MAJOR\\" in line: + major = line.split(\\"=\\")[1].strip() + elif \\"VERSION_MINOR\\" in line: + minor = line.split(\\"=\\")[1].strip() + elif \\"VERSION_BUILD\\" in line: + build = line.split(\\"=\\")[1].strip() + elif \\"VERSION_ALPHA\\" in line: + alpha = line.split(\\"=\\")[1].strip() + + if (major and minor and build and alpha) or \\"# END_VERSION_BLOCK\\" in line: + break + version = f\\"{major}.{minor}.{build}\\" + if alpha and int(alpha) > 0: + version += f\\"a{alpha}\\" + return version + + +def get_requirements(requirements_filename: str): + requirements_file = path.join(path.dirname(__file__), requirements_filename) + with open(requirements_file, \\"r\\", encoding=\\"utf-8\\") as r: + requirements = r.readlines() + requirements = [r.strip() for r in requirements if r.strip() and not r.strip().startswith(\\"#\\")] + return requirements + + +def find_resource_files(): + resource_base_dirs = (\\"locale\\", \\"intents\\", \\"dialog\\", \\"vocab\\", \\"regex\\", \\"ui\\") + package_data = [\\"*.json\\"] + for res in resource_base_dirs: + if path.isdir(path.join(BASE_PATH, res)): + for directory, _, files in walk(path.join(BASE_PATH, res)): + if files: + package_data.append(path.join(directory.replace(BASE_PATH, \\"\\").lstrip(\\"/\\"), \\"*\\")) + return package_data + + +with open(\\"README.md\\", \\"r\\") as f: + long_description = f.read() + +setup( + name=PYPI_NAME, + version=get_version(), + description=\\"\\", + long_description=long_description, + long_description_content_type=\\"text/markdown\\", + url=URL, + author=\\"TODO: Add 'author' to .projenrc.json and run pj\\", + author_email=\\"TODO: Add 'authorAddress' to .projenrc.json and run pj\\", + license=\\"# TODO: Add 'license' to .projenrc.json and run pj\\", + package_dir={SKILL_PKG: \\"\\"}, + package_data={SKILL_PKG: find_resource_files()}, + packages=[SKILL_PKG], + include_package_data=True, + install_requires=get_requirements(\\"requirements.txt\\"), + keywords=\\"ovos skill voice assistant\\", + entry_points={\\"ovos.plugin.skill\\": PLUGIN_ENTRY_POINT}, +) +", + "skill.json": Object {}, + "version.py": "VERSION_MAJOR = 0 +VERSION_MINOR = 0 +VERSION_BUILD = 1 +VERSION_ALPHA = 0", +} +`; From c781e1ac1309a24a80bb715caf60121e565df29c Mon Sep 17 00:00:00 2001 From: Mike Gray Date: Thu, 24 Aug 2023 22:36:18 -0500 Subject: [PATCH 3/5] fix: appropriately handle non-existent folders fixes #9 --- src/index.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 98a3c0e..907f5d3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -410,6 +410,14 @@ ${line}`; */ restructureLocaleFolders(sourceFolder: string) { ['vocab', 'dialog', 'regex', 'intents'].forEach((dir) => { + const dirPath = join(sourceFolder, dir); + + // Check if the directory exists before proceeding + if (!existsSync(dirPath)) { + console.warn(`${dir} folder not found in original skill; skipping.`); + return; // Continue to the next iteration of the loop + } + const locale = join(sourceFolder, 'locale'); try { mkdirSync(locale, { recursive: true }); @@ -429,9 +437,8 @@ ${line}`; renameSync(join(sourceFolder, dir, lang), join(locale, lang, dir)); } }); - } catch (err) { - console.debug(err); + console.error(err); } }); } From de7e5013974b1ac4a9554b1f6e71a5b26e1e2147 Mon Sep 17 00:00:00 2001 From: Mike Gray Date: Thu, 24 Aug 2023 23:15:54 -0500 Subject: [PATCH 4/5] fix: accept deps in manifest.yml fixes #6 --- .projen/deps.json | 4 + .projenrc.ts | 2 +- package.json | 3 +- src/index.ts | 15 +- test/OVOSSkillProject.test.ts | 23 + .../OVOSSkillProject.test.ts.snap | 524 ++++++++++++++++++ yarn.lock | 2 +- 7 files changed, 568 insertions(+), 5 deletions(-) diff --git a/.projen/deps.json b/.projen/deps.json index 78e4ff8..5925802 100644 --- a/.projen/deps.json +++ b/.projen/deps.json @@ -109,6 +109,10 @@ { "name": "projen", "type": "runtime" + }, + { + "name": "yaml", + "type": "runtime" } ], "//": "~~ Generated by projen. To modify, edit .projenrc.ts and run \"npx projen\"." diff --git a/.projenrc.ts b/.projenrc.ts index 68ff93b..77ea9fa 100644 --- a/.projenrc.ts +++ b/.projenrc.ts @@ -22,7 +22,7 @@ const project = new cdk.JsiiProject({ githubOptions: { mergify: false }, license: 'Apache-2.0', - deps: ['projen'], + deps: ['projen', 'yaml'], devDeps: ['jsii-rosetta@~5.0.7'], description: 'A projen project for creating OVOS skills, or retrofitting Mycroft skills to OVOS', }); diff --git a/package.json b/package.json index 470ff91..dd80da3 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,8 @@ "typescript": "^5.1.3" }, "dependencies": { - "projen": "^0.71.108" + "projen": "^0.71.108", + "yaml": "^2.3.1" }, "resolutions": { "@types/babel__traverse": "7.18.2", diff --git a/src/index.ts b/src/index.ts index 907f5d3..8beea51 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,6 +3,7 @@ import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, writeFile import { join } from 'path'; import { ProjenrcJson, SampleDir, SampleFile, TextFile } from 'projen'; import { GitHubProject, GitHubProjectOptions } from 'projen/lib/github'; +import { parse } from 'yaml'; import { readmeMd } from './files/README'; import { setupPy } from './files/setup.py'; import { LicenseTestsWorkflow, ProposeReleaseWorkflow, PublishAlphaWorkflow, PublishReleaseWorkflow, SkillTestsWorkflow, UpdateSkillJsonWorkflow } from './GithubWorkflows'; @@ -198,12 +199,22 @@ ${line}`; contents: '{}', }); let requirements = 'ovos-utils\novos-bus-client\novos-workshop\n# Your requirements here\n'; + let manifestReqs = ''; + if (existsSync('manifest.yml')) { + // Load and parse YAML file + console.debug('Found manifest.yml, trying to extract Python dependencies'); + const manifest = readFileSync('manifest.yml').toString(); + const manifestObject = parse(manifest); + if (manifestObject.dependencies.python) { + manifestReqs = manifestObject.dependencies.python.join('\n') + '\n'; + } + } if (existsSync('requirements.txt')) { const existingRequirements = readFileSync('requirements.txt').toString(); - requirements = `${existingRequirements}\n${requirements}`; + requirements = `${existingRequirements}\n${manifestReqs ?? ''}${requirements}`; } else { new TextFile(this, 'requirements.txt', { - lines: requirements.split('\n'), + lines: [...requirements.split('\n'), ...manifestReqs.split('\n')], }); } if (!existsSync('version.py') && retrofit) { diff --git a/test/OVOSSkillProject.test.ts b/test/OVOSSkillProject.test.ts index da0dc96..1d3e157 100644 --- a/test/OVOSSkillProject.test.ts +++ b/test/OVOSSkillProject.test.ts @@ -1,3 +1,4 @@ +import { rmSync, writeFileSync } from 'fs'; import { Testing } from 'projen'; import { OVOSSkillProject } from '../src'; @@ -22,4 +23,26 @@ test('snapshot retrofit', () => { const synth = Testing.synth(project); expect(synth).toMatchSnapshot(); + + rmSync('TODO.md'); +}); + +test('snapshot retrofit with manifest.yml', () => { + writeFileSync('manifest.yml', `dependencies: + python: + - akinator + - rapidfuzz +`); + const project = new OVOSSkillProject({ + name: 'test', + skillClass: 'TestSkill', + pypiName: 'test-skill', + retrofit: true, + }); + + const synth = Testing.synth(project); + expect(synth).toMatchSnapshot(); + + rmSync('manifest.yml'); + rmSync('TODO.md'); }); \ No newline at end of file diff --git a/test/__snapshots__/OVOSSkillProject.test.ts.snap b/test/__snapshots__/OVOSSkillProject.test.ts.snap index c48af92..9ff7be7 100644 --- a/test/__snapshots__/OVOSSkillProject.test.ts.snap +++ b/test/__snapshots__/OVOSSkillProject.test.ts.snap @@ -450,6 +450,7 @@ ovos skill ovos-bus-client ovos-workshop # Your requirements here + ", "setup.py": "#!/usr/bin/env python3 from setuptools import setup @@ -1086,6 +1087,529 @@ cython_debug/ ovos-bus-client ovos-workshop # Your requirements here + +", + "setup.py": "#!/usr/bin/env python3 +from setuptools import setup +from os import walk, path + +BASEDIR = path.abspath(path.dirname(__file__)) +URL = \\"TODO: Add 'repositoryUrl' to .projenrc.json and run pj\\" +SKILL_CLAZZ = \\"TestSkill\\" # needs to match __init__.py class name +PYPI_NAME = \\"test-skill\\" # pip install PYPI_NAME + +# below derived from github url to ensure standard skill_id +SKILL_AUTHOR, SKILL_NAME = URL.split(\\".com/\\")[-1].split(\\"/\\") +SKILL_PKG = SKILL_NAME.lower().replace(\\"-\\", \\"_\\") +PLUGIN_ENTRY_POINT = f\\"{SKILL_NAME.lower()}.{SKILL_AUTHOR.lower()}={SKILL_PKG}:{SKILL_CLAZZ}\\" +# skill_id=package_name:SkillClass +BASE_PATH = BASE_PATH = path.abspath(path.join(path.dirname(__file__), \\"\\")) + + +def get_version(): + \\"\\"\\"Find the version of the package\\"\\"\\" + version = None + version_file = path.join(BASE_PATH, \\"version.py\\") + major, minor, build, alpha = (None, None, None, None) + with open(version_file) as f: + for line in f: + if \\"VERSION_MAJOR\\" in line: + major = line.split(\\"=\\")[1].strip() + elif \\"VERSION_MINOR\\" in line: + minor = line.split(\\"=\\")[1].strip() + elif \\"VERSION_BUILD\\" in line: + build = line.split(\\"=\\")[1].strip() + elif \\"VERSION_ALPHA\\" in line: + alpha = line.split(\\"=\\")[1].strip() + + if (major and minor and build and alpha) or \\"# END_VERSION_BLOCK\\" in line: + break + version = f\\"{major}.{minor}.{build}\\" + if alpha and int(alpha) > 0: + version += f\\"a{alpha}\\" + return version + + +def get_requirements(requirements_filename: str): + requirements_file = path.join(path.dirname(__file__), requirements_filename) + with open(requirements_file, \\"r\\", encoding=\\"utf-8\\") as r: + requirements = r.readlines() + requirements = [r.strip() for r in requirements if r.strip() and not r.strip().startswith(\\"#\\")] + return requirements + + +def find_resource_files(): + resource_base_dirs = (\\"locale\\", \\"intents\\", \\"dialog\\", \\"vocab\\", \\"regex\\", \\"ui\\") + package_data = [\\"*.json\\"] + for res in resource_base_dirs: + if path.isdir(path.join(BASE_PATH, res)): + for directory, _, files in walk(path.join(BASE_PATH, res)): + if files: + package_data.append(path.join(directory.replace(BASE_PATH, \\"\\").lstrip(\\"/\\"), \\"*\\")) + return package_data + + +with open(\\"README.md\\", \\"r\\") as f: + long_description = f.read() + +setup( + name=PYPI_NAME, + version=get_version(), + description=\\"\\", + long_description=long_description, + long_description_content_type=\\"text/markdown\\", + url=URL, + author=\\"TODO: Add 'author' to .projenrc.json and run pj\\", + author_email=\\"TODO: Add 'authorAddress' to .projenrc.json and run pj\\", + license=\\"# TODO: Add 'license' to .projenrc.json and run pj\\", + package_dir={SKILL_PKG: \\"\\"}, + package_data={SKILL_PKG: find_resource_files()}, + packages=[SKILL_PKG], + include_package_data=True, + install_requires=get_requirements(\\"requirements.txt\\"), + keywords=\\"ovos skill voice assistant\\", + entry_points={\\"ovos.plugin.skill\\": PLUGIN_ENTRY_POINT}, +) +", + "skill.json": Object {}, + "version.py": "VERSION_MAJOR = 0 +VERSION_MINOR = 0 +VERSION_BUILD = 1 +VERSION_ALPHA = 0", +} +`; + +exports[`snapshot retrofit with manifest.yml 1`] = ` +Object { + ".gitattributes": "# ~~ Generated by projen. To modify, edit .projenrc.json and run \\"npx projen\\". + +/.gitattributes linguist-generated +/.github/workflows/license_tests.yml linguist-generated +/.github/workflows/propose_release.yml linguist-generated +/.github/workflows/publish_alpha.yml linguist-generated +/.github/workflows/publish_release.yml linguist-generated +/.github/workflows/pull-request-lint.yml linguist-generated +/.github/workflows/skill_tests.yml linguist-generated +/.github/workflows/update_skill_json.yml linguist-generated +/.gitignore linguist-generated +/.projen/** linguist-generated +/.projen/deps.json linguist-generated +/.projen/files.json linguist-generated +/.projen/tasks.json linguist-generated +/requirements.txt linguist-generated +/setup.py linguist-generated +/version.py linguist-generated", + ".github/workflows/license_tests.yml": "# ~~ Generated by projen. To modify, edit .projenrc.json and run \\"npx projen\\". + +name: license_tests +on: + push: {} + workflow_dispatch: {} + pull_request: + branches: + - master + - main +jobs: + license_tests: + name: license_tests + permissions: + contents: read + uses: neongeckocom/.github/.github/workflows/license_tests.yml@master +", + ".github/workflows/propose_release.yml": "# ~~ Generated by projen. To modify, edit .projenrc.json and run \\"npx projen\\". + +name: propose_release +on: + workflow_dispatch: + inputs: + release_type: + type: choice + description: Release Type + options: + - build + - minor + - major + - patch + - alpha +jobs: + update_version: + name: update_version + permissions: + contents: write + packages: write + uses: neongeckocom/.github/.github/workflows/propose_semver_release.yml@master + with: + release_type: \${{ inputs.release_type }} + version_file: version.py + alpha_var: VERSION_ALPHA + build_var: VERSION_BUILD + minor_var: VERSION_MINOR + major_var: VERSION_MAJOR + update_changelog: true + branch: dev + pull_changes: + needs: update_version + permissions: + contents: write + uses: neongeckocom/.github/.github/workflows/pull_master.yml@master + with: + pr_assignee: \${{ github.actor }} + pr_draft: false + pr_title: \${{ needs.update_version.outputs.version }} + pr_body: \${{ needs.update_version.outputs.changelog }} +", + ".github/workflows/publish_alpha.yml": "# ~~ Generated by projen. To modify, edit .projenrc.json and run \\"npx projen\\". + +name: publish_alpha +on: + push: + branches: + - dev + paths: + - \\"!version.py\\" + - \\"!test/**\\" + - \\"!examples/**\\" + - \\"!.github/**\\" + - \\"!.gitignore\\" + - \\"!LICENSE\\" + - \\"!CHANGELOG.md\\" + - \\"!MANIFEST.in\\" + - \\"!README.md\\" + - \\"!scripts/*\\" + workflow_dispatch: {} +jobs: + publish_alpha_release: + permissions: + contents: write + packages: write + uses: neongeckocom/.github/.github/workflows/publish_alpha_release.yml@master + with: + version_file: version.py + publish_prerelease: true + update_changelog: true + alpha_var: VERSION_ALPHA + build_var: VERSION_BUILD + minor_var: VERSION_MINOR + major_var: VERSION_MAJOR +", + ".github/workflows/publish_release.yml": "# ~~ Generated by projen. To modify, edit .projenrc.json and run \\"npx projen\\". + +name: publish_release +on: + push: + branches: + - master + - main +jobs: + build_and_publish_pypi_and_release: + permissions: + contents: write + packages: write + uses: neongeckocom/.github/.github/workflows/publish_stable_release.yml@master + secrets: + PYPI_TOKEN: \${{ secrets.PYPI_TOKEN }} +", + ".github/workflows/pull-request-lint.yml": "# ~~ Generated by projen. To modify, edit .projenrc.json and run \\"npx projen\\". + +name: pull-request-lint +on: + pull_request_target: + types: + - labeled + - opened + - synchronize + - reopened + - ready_for_review + - edited +jobs: + validate: + name: Validate PR title + runs-on: ubuntu-latest + permissions: + pull-requests: write + steps: + - uses: amannn/action-semantic-pull-request@v5.0.2 + env: + GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }} + with: + types: |- + feat + fix + chore + requireScope: false +", + ".github/workflows/skill_tests.yml": "# ~~ Generated by projen. To modify, edit .projenrc.json and run \\"npx projen\\". + +name: skill_tests +on: + pull_request: {} + workflow_dispatch: {} +jobs: + py_build_tests: + name: py_build_tests + permissions: + contents: read + uses: neongeckocom/.github/.github/workflows/python_build_tests.yml@master + skill_unit_tests: + name: skill_unit_tests + permissions: + contents: read + uses: neongeckocom/.github/.github/workflows/skill_tests.yml@master + skill_intent_tests: + name: skill_intent_tests + permissions: + contents: read + uses: neongeckocom/.github/.github/workflows/skill_test_intents.yml@master + skill_resource_tests: + name: skill_resource_tests + permissions: + contents: read + uses: neongeckocom/.github/.github/workflows/skill_test_resources.yml@master + skill_install_tests: + name: skill_install_tests + permissions: + contents: read + uses: neongeckocom/.github/.github/workflows/skill_test_installation.yml@master +", + ".github/workflows/update_skill_json.yml": "# ~~ Generated by projen. To modify, edit .projenrc.json and run \\"npx projen\\". + +name: update_skill_json +on: + push: {} +jobs: + update-skill-json: + name: update_skill_json + permissions: + contents: write + uses: neongeckocom/.github/.github/workflows/skill_update_json_spec.yml@master +", + ".gitignore": "# ~~ Generated by projen. To modify, edit .projenrc.json and run \\"npx projen\\". +node_modules/ +!/.gitattributes +!/.projen/tasks.json +!/.projen/deps.json +!/.projen/files.json +!/.github/workflows/pull-request-lint.yml +.DS_Store +node_modules +__pycache__/ +*.py[cod] +*$py.class +*.so +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST +*.manifest +*.spec +pip-log.txt +pip-delete-this-directory.txt +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ +*.mo +*.pot +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal +instance/ +.webassets-cache +.scrapy +docs/_build/ +.pybuilder/ +target/ +.ipynb_checkpoints +profile_default/ +ipython_config.py +__pypackages__/ +celerybeat-schedule +celerybeat.pid +*.sage.py +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ +.spyderproject +.spyproject +.ropeproject +/site +.mypy_cache/ +.dmypy.json +dmypy.json +.pyre/ +.pytype/ +cython_debug/ +!/setup.py +!/requirements.txt +!/version.py +!/.github/workflows/license_tests.yml +!/.github/workflows/propose_release.yml +!/.github/workflows/publish_alpha.yml +!/.github/workflows/publish_release.yml +!/.github/workflows/skill_tests.yml +!/.github/workflows/update_skill_json.yml +", + ".projen/files.json": Object { + "//": "~~ Generated by projen. To modify, edit .projenrc.json and run \\"npx projen\\".", + "files": Array [ + ".gitattributes", + ".github/workflows/license_tests.yml", + ".github/workflows/propose_release.yml", + ".github/workflows/publish_alpha.yml", + ".github/workflows/publish_release.yml", + ".github/workflows/pull-request-lint.yml", + ".github/workflows/skill_tests.yml", + ".github/workflows/update_skill_json.yml", + ".gitignore", + ".projen/deps.json", + ".projen/files.json", + ".projen/tasks.json", + "requirements.txt", + "setup.py", + "version.py", + ], + }, + ".projen/tasks.json": Object { + "//": "~~ Generated by projen. To modify, edit .projenrc.json and run \\"npx projen\\".", + "tasks": Object { + "build": Object { + "description": "Full release build", + "name": "build", + "steps": Array [ + Object { + "spawn": "default", + }, + Object { + "spawn": "pre-compile", + }, + Object { + "spawn": "compile", + }, + Object { + "spawn": "post-compile", + }, + Object { + "spawn": "test", + }, + Object { + "spawn": "package", + }, + ], + }, + "clobber": Object { + "condition": "git diff --exit-code > /dev/null", + "description": "hard resets to HEAD of origin and cleans the local repo", + "env": Object { + "BRANCH": "$(git branch --show-current)", + }, + "name": "clobber", + "steps": Array [ + Object { + "exec": "git checkout -b scratch", + "name": "save current HEAD in \\"scratch\\" branch", + }, + Object { + "exec": "git checkout $BRANCH", + }, + Object { + "exec": "git fetch origin", + "name": "fetch latest changes from origin", + }, + Object { + "exec": "git reset --hard origin/$BRANCH", + "name": "hard reset to origin commit", + }, + Object { + "exec": "git clean -fdx", + "name": "clean all untracked files", + }, + Object { + "say": "ready to rock! (unpushed commits are under the \\"scratch\\" branch)", + }, + ], + }, + "compile": Object { + "description": "Only compile", + "name": "compile", + }, + "default": Object { + "description": "Synthesize project files", + "env": Object { + "FILENAME": ".projenrc.json", + }, + "name": "default", + "steps": Array [ + Object { + "builtin": "run-projenrc-json", + }, + ], + }, + "eject": Object { + "description": "Remove projen from the project", + "env": Object { + "PROJEN_EJECTING": "true", + }, + "name": "eject", + "steps": Array [ + Object { + "spawn": "default", + }, + ], + }, + "package": Object { + "description": "Creates the distribution package", + "name": "package", + }, + "post-compile": Object { + "description": "Runs after successful compilation", + "name": "post-compile", + }, + "pre-compile": Object { + "description": "Prepare the project for compilation", + "name": "pre-compile", + }, + "test": Object { + "description": "Run tests", + "name": "test", + }, + }, + }, + "README.md": "# replace this", + "requirements.txt": "ovos-utils +ovos-bus-client +ovos-workshop +# Your requirements here + +akinator +rapidfuzz ", "setup.py": "#!/usr/bin/env python3 from setuptools import setup diff --git a/yarn.lock b/yarn.lock index 5476a3c..6d5fd04 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6774,7 +6774,7 @@ yallist@^4.0.0: resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72" integrity sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A== -yaml@^2.2.2: +yaml@^2.2.2, yaml@^2.3.1: version "2.3.1" resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.3.1.tgz#02fe0975d23cd441242aa7204e09fc28ac2ac33b" integrity sha512-2eHWfjaoXgTBC2jNM1LRef62VQa0umtvRiDSk6HSzW7RvS5YtkabJrwYLLEKWBc8a5U2PTSCs+dJjUTJdlHsWQ== From 9cb2320617d7242061f37bfd1e0aa8d038d663d8 Mon Sep 17 00:00:00 2001 From: Mike Gray Date: Thu, 24 Aug 2023 23:19:37 -0500 Subject: [PATCH 5/5] build fixes --- .projen/deps.json | 8 ++++---- .projenrc.ts | 3 ++- package.json | 3 +++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.projen/deps.json b/.projen/deps.json index 5925802..02e09f3 100644 --- a/.projen/deps.json +++ b/.projen/deps.json @@ -96,6 +96,10 @@ "name": "typescript", "type": "build" }, + { + "name": "yaml", + "type": "bundled" + }, { "name": "@types/babel__traverse", "version": "7.18.2", @@ -109,10 +113,6 @@ { "name": "projen", "type": "runtime" - }, - { - "name": "yaml", - "type": "runtime" } ], "//": "~~ Generated by projen. To modify, edit .projenrc.ts and run \"npx projen\"." diff --git a/.projenrc.ts b/.projenrc.ts index 77ea9fa..02119d6 100644 --- a/.projenrc.ts +++ b/.projenrc.ts @@ -22,7 +22,8 @@ const project = new cdk.JsiiProject({ githubOptions: { mergify: false }, license: 'Apache-2.0', - deps: ['projen', 'yaml'], + deps: ['projen'], + bundledDeps: ['yaml'], devDeps: ['jsii-rosetta@~5.0.7'], description: 'A projen project for creating OVOS skills, or retrofitting Mycroft skills to OVOS', }); diff --git a/package.json b/package.json index dd80da3..9d03bc4 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,9 @@ "projen": "^0.71.108", "yaml": "^2.3.1" }, + "bundledDependencies": [ + "yaml" + ], "resolutions": { "@types/babel__traverse": "7.18.2", "@types/prettier": "2.6.0"