Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An initial go at Python Support #69

Merged
merged 10 commits into from
Jul 14, 2022

Conversation

mrkaiser
Copy link
Contributor

@mrkaiser mrkaiser commented Jun 12, 2022

This attempts to solve GH-49. It adds python support via behave
only. This is still a WIP. The tests pass but after building with
changes in language-server and vscode, functionality in real world
applications is severely diminished. Go To Definition and Autocomplete
are currently missing.

🤔 What's changed?

There is python support via the behave library

⚡️ What's your motivation?

Fixes #49

🏷️ What kind of change is this?

  • ⚡ New feature (non-breaking change which adds new behaviour)

♻️ Anything particular you want feedback on?

The tests currently pass. Functionality in an editor (testing with vscode) is however extremely broken, providing no go to definition or autocomplete.

📋 Checklist:

  • I agree to respect and uphold the Cucumber Community Code of Conduct
  • I've changed the behaviour of the code
    • I have added/updated tests to cover my changes.
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.
  • Users should know about my change
    • I have added an entry to the "Unreleased" section of the CHANGELOG, linking to this pull request.

This text was originally generated from a template, then edited by hand. You can modify the template here.

mrkaiser added 2 commits June 12, 2022 14:32
This attempts to solve cucumberGH-49. It adds python support via `behave`
only. This is still a WIP. The tests pass but after building with
changes in `language-server` and `vscode`, functionality in real world
applications is severely diminished. Go To Definition and Autocomplete
are currently missing.
@@ -31,14 +32,17 @@ If your contribution is to add support for a new programming language, follow th
6. Add the name of the new language to the `LanguageName` type
7. Update `languageByName` in `src/language/language.ts`
8. Update `src/tree-sitter-node/NodeParserAdapter.ts`
9. Run tests
9. Update `test/language/ExpressionBuilder.test.ts` to include the new language if it supports Cucumber Expressions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

Copy link
Contributor

@aslakhellesoy aslakhellesoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work @mrkaiser! I'm impressed how you've managed to navigate the codebase - everything looks very good.

I like to do a manual test within VSCode (as explained here: https://github.com/cucumber/language-service/blob/main/CONTRIBUTING.md#manual-testing)

Do you know of an online repo that would have some behave code (with custom parameter types) I could use as a test subject?

CONTRIBUTING.md Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
src/language/pythonLanguage.ts Outdated Show resolved Hide resolved
src/language/pythonLanguage.ts Outdated Show resolved Hide resolved
src/language/types.ts Outdated Show resolved Hide resolved
test/language/testdata/python/.python-version Outdated Show resolved Hide resolved
@mrkaiser
Copy link
Contributor Author

In hindsight, I should've made this a draft.

@mrkaiser
Copy link
Contributor Author

@aslakhellesoy I am currently working on the PR comments. Something has broken the tests. I am going on a much needed vacation. I will pick this back up next week.

I appreciate the understanding.

* Update CONTRIBUTING.md to include snippet information
* Fixed package.json
* Reordered languages to alphabetical order
* Fixed indentation on tree-sitter queries
* Cleaned up python includes (.python-version and .mypy in .gitignore)
@mrkaiser
Copy link
Contributor Author

Hi @aslakhellesoy , while working on the updates to the PR and trying to test vscode, I noticed that tree-sitter-python is not installed in either my local language-server node_modules or in vscode. I think this has to do with linking and installing. I tried reading the npm-link documentation. Unfortunately I'm fairly lost with the toolkit, since I'm not a particularly seasoned typescript or javascript developer. Any ideas here? Is it a red herring?

@mrkaiser mrkaiser marked this pull request as draft June 30, 2022 23:35
Copy link
Contributor

@aslakhellesoy aslakhellesoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you have been working with the assumption that Cucumber Expressions (and Parameter Types) are supported by Behave. Unfortunately they are not.

Someone has ported the Cucumber Expressions library to Python, but nobody has yet integrated it into Behave.

Until that happens I think it's best if we assume all Behave step definitions use regular expressions.

I'm sorry I didn't catch this before - it would probably have saved you some time.

test/language/testdata/python/ParameterTypes.py Outdated Show resolved Hide resolved
test/language/testdata/python/StepDefinitions.py Outdated Show resolved Hide resolved
src/language/pythonLanguage.ts Outdated Show resolved Hide resolved
src/language/pythonLanguage.ts Outdated Show resolved Hide resolved
test/language/testdata/python/StepDefinitions.py Outdated Show resolved Hide resolved
@aslakhellesoy
Copy link
Contributor

As discussed - here is how Cucumber Expressions for Java decides whether an expression string should be interpreted as CukeExp or RegExp: https://github.com/cucumber/cucumber-expressions/blob/main/java/src/main/java/io/cucumber/cucumberexpressions/ExpressionFactory.java

Removed and Reverted ParameterType support.
Added basic checks for regexes to support _some_ level of "cucumber
expression" support (i.e only plain text) to get some go to definitions
working

Added a better blurb.
@mrkaiser mrkaiser marked this pull request as ready for review July 8, 2022 00:45
@mrkaiser mrkaiser requested a review from aslakhellesoy July 8, 2022 00:46
@mrkaiser
Copy link
Contributor Author

mrkaiser commented Jul 8, 2022

Not sure why there are conflict with package-lock.json

@mrkaiser
Copy link
Contributor Author

mrkaiser commented Jul 8, 2022

@aslakhellesoy As discussed I have migrated to only regexp. In some instances I choose to just return the string. This works well in practice because "plain ol" strings are also always valid Cucumber Expressions. I do basic checks. This allows some level of go to definition functionality. I have tested with my changes in the language-server and the vscode plugin and looks good enough to ship an initial version of Python support.

Thanks

@aslakhellesoy aslakhellesoy merged commit 88b4aee into cucumber:main Jul 14, 2022
@aslakhellesoy
Copy link
Contributor

Hi @mrkaiser,

Thanks for your making your first contribution to Cucumber, and welcome to the Cucumber committers team! You can now push directly to this repo and all other repos under the cucumber organization! 🍾

In return for this generous offer we hope you will:

  • ✅ Continue to use branches and pull requests. When someone on the core team approves a pull request (yours or someone else's), you're welcome to merge it yourself.
  • 💚 Commit to setting a good example by following and upholding our code of conduct in your interactions with other collaborators and users.
  • 💬 Join the community Slack channel to meet the rest of the team and make yourself at home.
  • ℹ️ Don't feel obliged to help, just do what you can if you have the time and the energy.
  • 🙋 Ask if you need anything. We're looking for feedback about how to make the project more welcoming, so please tell us!

On behalf of the Cucumber core team,
Aslak Hellesøy
Creator of Cucumber

@mrkaiser mrkaiser deleted the feature/python_support branch October 4, 2022 01:08
@blaisep
Copy link
Member

blaisep commented Nov 1, 2023

Hi @mrkaiser , I will reach out to you on the cucumber Slack... ping blaise if you have a chance because I didn't find you in the Slack channel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for Python (Behave)
3 participants