From 516d95da4d3bc2e0dfc32b426b22b963caf42a9d Mon Sep 17 00:00:00 2001 From: Ben Rometsch Date: Thu, 18 May 2023 10:38:39 +0100 Subject: [PATCH 1/4] Update versions Reformat --- .github/workflows/publish.yml | 34 ++++++++--------- .github/workflows/pytest.yml | 70 +++++++++++++++++------------------ 2 files changed, 52 insertions(+), 52 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 8c8324f..d327787 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,24 +1,24 @@ name: Publish Pypi Package on: - push: - tags: - - '*' + push: + tags: + - "*" jobs: - package: - runs-on: ubuntu-latest - name: Publish Pypi Package + package: + runs-on: ubuntu-latest + name: Publish Pypi Package - steps: - - name: Cloning repo - uses: actions/checkout@v2 - with: - fetch-depth: 0 + steps: + - name: Cloning repo + uses: actions/checkout@v3 + with: + fetch-depth: 0 - - name: Build and publish to pypi - uses: JRubics/poetry-publish@v1.10 - with: - pypi_token: ${{ secrets.PYPI_API_TOKEN }} - ignore_dev_requirements: "yes" - build_format: "sdist" + - name: Build and publish to pypi + uses: JRubics/poetry-publish@v1.10 + with: + pypi_token: ${{ secrets.PYPI_API_TOKEN }} + ignore_dev_requirements: "yes" + build_format: "sdist" diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 47f38d0..a001656 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -1,40 +1,40 @@ name: Formatting and Tests on: - - pull_request + - pull_request jobs: - test: - runs-on: ubuntu-latest - name: Pytest and Black formatting - - strategy: - max-parallel: 4 - matrix: - python-version: ["3.7", "3.8", "3.9", "3.10"] - - steps: - - name: Cloning repo - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - - name: Install Dependencies - run: | - python -m pip install --upgrade pip - pip install poetry - poetry install - - - name: Check Formatting - run: | - poetry run black --check . - poetry run flake8 . - poetry run isort --check . - - - name: Run Tests - run: poetry run pytest + test: + runs-on: ubuntu-latest + name: Pytest and Black formatting + + strategy: + max-parallel: 4 + matrix: + python-version: ["3.7", "3.8", "3.9", "3.10"] + + steps: + - name: Cloning repo + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Install Dependencies + run: | + python -m pip install --upgrade pip + pip install poetry + poetry install + + - name: Check Formatting + run: | + poetry run black --check . + poetry run flake8 . + poetry run isort --check . + + - name: Run Tests + run: poetry run pytest From 223e71343966f38fbd0f2c4fae6e074db6286dac Mon Sep 17 00:00:00 2001 From: Ben Rometsch Date: Thu, 18 May 2023 10:48:56 +0100 Subject: [PATCH 2/4] Linting / precommit for yaml Added prettir Fixed up some files --- .github/workflows/publish.yml | 6 +++--- .github/workflows/pytest.yml | 2 +- .pre-commit-config.yaml | 9 ++++++++- .prettierignore | 6 ++++++ .prettierrc.json | 21 +++++++++++++++++++++ Readme.md | 15 ++++++++++----- example/readme.md | 14 +++++++------- 7 files changed, 56 insertions(+), 17 deletions(-) create mode 100644 .prettierignore create mode 100644 .prettierrc.json diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index d327787..1ee6bfd 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -3,7 +3,7 @@ name: Publish Pypi Package on: push: tags: - - "*" + - '*' jobs: package: @@ -20,5 +20,5 @@ jobs: uses: JRubics/poetry-publish@v1.10 with: pypi_token: ${{ secrets.PYPI_API_TOKEN }} - ignore_dev_requirements: "yes" - build_format: "sdist" + ignore_dev_requirements: 'yes' + build_format: 'sdist' diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index a001656..dbd2dac 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -11,7 +11,7 @@ jobs: strategy: max-parallel: 4 matrix: - python-version: ["3.7", "3.8", "3.9", "3.10"] + python-version: ['3.7', '3.8', '3.9', '3.10'] steps: - name: Cloning repo diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7a7503d..3f558a5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,4 +12,11 @@ repos: hooks: - id: black language_version: python3 - + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: check-yaml + - repo: https://github.com/pre-commit/mirrors-prettier + rev: v2.7.1 + hooks: + - id: prettier diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..faf3a67 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,6 @@ +# Ignore a bunch of files: +*.html +*.json +*.handlebars +*.css +.bablerc \ No newline at end of file diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000..d60e431 --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,21 @@ +{ + "proseWrap": "always", + "singleQuote": true, + "printWidth": 120, + "trailingComma": "all", + "tabWidth": 4, + "overrides": [ + { + "files": "**/*.md", + "options": { + "tabWidth": 1 + } + }, + { + "files": ["**/*.yml", "**/*.yaml"], + "options": { + "tabWidth": 2 + } + } + ] +} diff --git a/Readme.md b/Readme.md index a87510d..addfa5c 100644 --- a/Readme.md +++ b/Readme.md @@ -2,25 +2,30 @@ # Flagsmith Python SDK -> Flagsmith allows you to manage feature flags and remote config across multiple projects, environments and organisations. +> Flagsmith allows you to manage feature flags and remote config across multiple projects, environments and +> organisations. The SDK for Python applications for [https://www.flagsmith.com/](https://www.flagsmith.com/). ## Adding to your project -For full documentation visit [https://docs.flagsmith.com/clients/server-side](https://docs.flagsmith.com/clients/server-side). +For full documentation visit +[https://docs.flagsmith.com/clients/server-side](https://docs.flagsmith.com/clients/server-side). ## Contributing -Please read [CONTRIBUTING.md](https://gist.github.com/kyle-ssg/c36a03aebe492e45cbd3eefb21cb0486) for details on our code of conduct, and the process for submitting pull requests +Please read [CONTRIBUTING.md](https://gist.github.com/kyle-ssg/c36a03aebe492e45cbd3eefb21cb0486) for details on our code +of conduct, and the process for submitting pull requests ## Getting Help -If you encounter a bug or feature request we would like to hear about it. Before you submit an issue please search existing issues in order to prevent duplicates. +If you encounter a bug or feature request we would like to hear about it. Before you submit an issue please search +existing issues in order to prevent duplicates. ## Get in touch -If you have any questions about our projects you can email support@flagsmith.com. +If you have any questions about our projects you can email +support@flagsmith.com. ## Useful links diff --git a/example/readme.md b/example/readme.md index 7ac5c16..7b61346 100644 --- a/example/readme.md +++ b/example/readme.md @@ -1,22 +1,22 @@ # Flagsmith Basic Python Example -This directory contains a basic Flask application which utilises Flagsmith. To run the example application, you'll -need to go through the following steps: +This directory contains a basic Flask application which utilises Flagsmith. To run the example application, you'll need +to go through the following steps: 1. Create an account, organisation and project on [Flagsmith](https://flagsmith.com) 2. Create a feature in the project called "secret_button" -3. Give the feature a value using the json editor as follows: +3. Give the feature a value using the json editor as follows: ```json -{"colour": "#ababab"} +{ "colour": "#ababab" } ``` -4. Create a .env file from the template located in this directory with the environment key of one of the environments -in flagsmith (This can be found on the 'settings' page accessed from the menu on the left under the chosen environment.) +4. Create a .env file from the template located in this directory with the environment key of one of the environments in + flagsmith (This can be found on the 'settings' page accessed from the menu on the left under the chosen environment.) 5. From a terminal window, export those environment variables (either manually or by using `export $(cat .env)`) 6. Run the app using `flask run` 7. Browse to http://localhost:5000 Now you can play around with the 'secret_button' feature in flagsmith, turn it on to show it and edit the colour in the json value to edit the colour of the button. You can also identify as a given user and then update the settings for the -secret button feature for that user in the flagsmith interface to see the affect that has too. +secret button feature for that user in the flagsmith interface to see the affect that has too. From 498a189f9ae99520636a35e301c32d1e7b580ebc Mon Sep 17 00:00:00 2001 From: Ben Rometsch Date: Thu, 18 May 2023 11:39:10 +0100 Subject: [PATCH 3/4] Removed prettierignore and linted some json and html --- .prettierignore | 6 --- example/templates/home.html | 31 ++++++----- tests/data/environment.json | 102 ++++++++++++++++++------------------ tests/data/flags.json | 2 +- tests/data/identities.json | 2 +- 5 files changed, 68 insertions(+), 75 deletions(-) delete mode 100644 .prettierignore diff --git a/.prettierignore b/.prettierignore deleted file mode 100644 index faf3a67..0000000 --- a/.prettierignore +++ /dev/null @@ -1,6 +0,0 @@ -# Ignore a bunch of files: -*.html -*.json -*.handlebars -*.css -.bablerc \ No newline at end of file diff --git a/example/templates/home.html b/example/templates/home.html index 4744cf0..23f440d 100644 --- a/example/templates/home.html +++ b/example/templates/home.html @@ -1,25 +1,24 @@ - + Flagsmith Example -

Hello, {{ identifier or 'World' }}.

-{% if show_button %} - -{% endif %} +

Hello, {{ identifier or 'World' }}.

+ {% if show_button %} + + {% endif %} -

+

-
-

Identify as a user

-
+ +

Identify as a user

+
-

... with an optional user trait

-
-

+

... with an optional user trait

+
+

- -
- - \ No newline at end of file + + + diff --git a/tests/data/environment.json b/tests/data/environment.json index aa0e060..22d5235 100644 --- a/tests/data/environment.json +++ b/tests/data/environment.json @@ -1,56 +1,56 @@ { - "api_key": "B62qaMZNwfiqT76p38ggrQ", - "project": { - "name": "Test project", - "organisation": { - "feature_analytics": false, - "name": "Test Org", - "id": 1, - "persist_trait_data": true, - "stop_serving_flags": false - }, - "id": 1, - "hide_disabled_flags": false, - "segments": [ - { + "api_key": "B62qaMZNwfiqT76p38ggrQ", + "project": { + "name": "Test project", + "organisation": { + "feature_analytics": false, + "name": "Test Org", + "id": 1, + "persist_trait_data": true, + "stop_serving_flags": false + }, "id": 1, - "name": "Test segment", - "rules": [ - { - "type": "ALL", - "rules": [ - { - "type": "ALL", - "rules": [], - "conditions": [ - { - "operator": "EQUAL", - "property_": "foo", - "value": "bar" - } + "hide_disabled_flags": false, + "segments": [ + { + "id": 1, + "name": "Test segment", + "rules": [ + { + "type": "ALL", + "rules": [ + { + "type": "ALL", + "rules": [], + "conditions": [ + { + "operator": "EQUAL", + "property_": "foo", + "value": "bar" + } + ] + } + ] + } ] - } - ] - } + } ] - } + }, + "segment_overrides": [], + "id": 1, + "feature_states": [ + { + "multivariate_feature_state_values": [], + "feature_state_value": "some-value", + "id": 1, + "featurestate_uuid": "40eb539d-3713-4720-bbd4-829dbef10d51", + "feature": { + "name": "some_feature", + "type": "STANDARD", + "id": 1 + }, + "segment_id": null, + "enabled": true + } ] - }, - "segment_overrides": [], - "id": 1, - "feature_states": [ - { - "multivariate_feature_state_values": [], - "feature_state_value": "some-value", - "id": 1, - "featurestate_uuid": "40eb539d-3713-4720-bbd4-829dbef10d51", - "feature": { - "name": "some_feature", - "type": "STANDARD", - "id": 1 - }, - "segment_id": null, - "enabled": true - } - ] -} \ No newline at end of file +} diff --git a/tests/data/flags.json b/tests/data/flags.json index cf06066..a2f226b 100644 --- a/tests/data/flags.json +++ b/tests/data/flags.json @@ -17,4 +17,4 @@ "identity": null, "feature_segment": null } -] \ No newline at end of file +] diff --git a/tests/data/identities.json b/tests/data/identities.json index 1d9c679..c829bfd 100644 --- a/tests/data/identities.json +++ b/tests/data/identities.json @@ -26,4 +26,4 @@ "feature_segment": null } ] -} \ No newline at end of file +} From f51415bc6f35e6f179b0f2dbad50d8d08a4a2d95 Mon Sep 17 00:00:00 2001 From: Ben Rometsch Date: Thu, 18 May 2023 11:40:04 +0100 Subject: [PATCH 4/4] Remove support for python 3.7 and add 3.11 --- .github/workflows/pytest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index dbd2dac..ac2e3c4 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -11,7 +11,7 @@ jobs: strategy: max-parallel: 4 matrix: - python-version: ['3.7', '3.8', '3.9', '3.10'] + python-version: ['3.8', '3.9', '3.10', '3.11'] steps: - name: Cloning repo