From d0b7f66e9a2ee69cf56c1ba31496d13577a37543 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Thu, 18 Aug 2022 17:06:15 +0200 Subject: [PATCH] example: migrate `python-xhr` to ESM --- .eslintrc.js | 1 + examples/python-xhr/.gitignore | 3 +-- examples/python-xhr/{readme.md => README.md} | 15 +++++++------ examples/python-xhr/index.html | 4 ++-- examples/python-xhr/main.js | 12 +++++++---- examples/python-xhr/package.json | 22 +++++++++----------- examples/python-xhr/server.py | 5 +++-- yarn.lock | 16 ++------------ 8 files changed, 34 insertions(+), 44 deletions(-) rename examples/python-xhr/{readme.md => README.md} (72%) mode change 100644 => 100755 examples/python-xhr/server.py diff --git a/.eslintrc.js b/.eslintrc.js index 0a2e6ea036..b9e1abc235 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -198,6 +198,7 @@ module.exports = { 'examples/multiple-instances/*.js', 'examples/node-xhr/*.js', 'examples/php-xhr/*.js', + 'examples/python-xhr/*.js', 'examples/transloadit-markdown-bin/*.js', 'examples/xhr-bundle/*.js', 'private/dev/*.js', diff --git a/examples/python-xhr/.gitignore b/examples/python-xhr/.gitignore index 4f15b1cceb..8fc0d80271 100644 --- a/examples/python-xhr/.gitignore +++ b/examples/python-xhr/.gitignore @@ -1,2 +1 @@ -uppy.min.css -uploads +uploads/ diff --git a/examples/python-xhr/readme.md b/examples/python-xhr/README.md similarity index 72% rename from examples/python-xhr/readme.md rename to examples/python-xhr/README.md index 71d2a5e30e..4048247a8d 100644 --- a/examples/python-xhr/readme.md +++ b/examples/python-xhr/README.md @@ -6,22 +6,21 @@ This example uses a Python Flask server and `@uppy/xhr-upload` to upload files t To run this example, make sure you've correctly installed the **repository root**: -```bash -npm install -npm run build +```sh +corepack yarn install +corepack yarn build ``` That will also install the npm dependencies for this example. Additionally, this example uses python dependencies. Move into this directory, and install them using pip: -```bash -cd ./examples/python-xhr -pip install -r requirements.txt +```sh +corepack yarn workspace @uppy-example/python-xhr installPythonDeps ``` Then, again in the **repository root**, start this example by doing: -```bash -npm run example python-xhr +```sh +corepack yarn workspace @uppy-example/python-xhr start ``` diff --git a/examples/python-xhr/index.html b/examples/python-xhr/index.html index 9a777c91ff..0e89baa514 100644 --- a/examples/python-xhr/index.html +++ b/examples/python-xhr/index.html @@ -4,9 +4,9 @@ Python + Uppy Example - - + + diff --git a/examples/python-xhr/main.js b/examples/python-xhr/main.js index 670a844cda..2787385c87 100644 --- a/examples/python-xhr/main.js +++ b/examples/python-xhr/main.js @@ -1,7 +1,11 @@ -const Uppy = require('@uppy/core') -const Webcam = require('@uppy/webcam') -const Dashboard = require('@uppy/dashboard') -const XHRUpload = require('@uppy/xhr-upload') +import Uppy from '@uppy/core' +import Webcam from '@uppy/webcam' +import Dashboard from '@uppy/dashboard' +import XHRUpload from '@uppy/xhr-upload' + +import '@uppy/core/dist/style.css' +import '@uppy/webcam/dist/style.css' +import '@uppy/dashboard/dist/style.css' const uppy = new Uppy({ debug: true, diff --git a/examples/python-xhr/package.json b/examples/python-xhr/package.json index 6a2250ea00..8cdeaaa393 100644 --- a/examples/python-xhr/package.json +++ b/examples/python-xhr/package.json @@ -1,24 +1,22 @@ { "name": "@uppy-example/python-xhr", "version": "0.0.0", + "type": "module", "dependencies": { - "@babel/core": "^7.4.4", "@uppy/core": "workspace:*", "@uppy/dashboard": "workspace:*", "@uppy/webcam": "workspace:*", - "@uppy/xhr-upload": "workspace:*", - "babelify": "^10.0.0", - "budo": "^11.3.2", - "cookie-parser": "^1.4.6", - "cors": "^2.8.4", - "formidable": "^1.2.1", - "npm-run-all": "^4.1.3" + "@uppy/xhr-upload": "workspace:*" + }, + "devDependencies": { + "npm-run-all": "^4.1.3", + "vite": "^3.0.0" }, "private": true, "scripts": { - "copy": "cp ../../packages/uppy/dist/uppy.min.css .", - "start": "npm-run-all --serial copy --parallel start:*", - "start:client": "budo main.js:bundle.js -- -t babelify", - "start:server": "mkdir -p uploads && python server.py" + "installPythonDeps": "python3 -m pip install -r requirements.txt", + "start": "npm-run-all --parallel start:server start:client", + "start:client": "vite", + "start:server": "mkdir -p uploads && python3 server.py" } } diff --git a/examples/python-xhr/server.py b/examples/python-xhr/server.py old mode 100644 new mode 100755 index 323495d0f7..4ede8f8129 --- a/examples/python-xhr/server.py +++ b/examples/python-xhr/server.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 import os from flask import Flask, request, jsonify from werkzeug.utils import secure_filename @@ -7,7 +8,7 @@ ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif']) app = Flask(__name__) -app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER +app.config['UPLOAD_FOLDER'] = os.path.join(os.path.dirname(__file__), UPLOAD_FOLDER) CORS(app) def allowed_file(filename): @@ -18,7 +19,7 @@ def allowed_file(filename): def upload_file(): if request.method == 'POST': # check if the post request has the file part - print request.files + print (request.files) if len(request.files) == 0: return jsonify( error="No file n request" diff --git a/yarn.lock b/yarn.lock index a7c877a4fd..18fa56b8bd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8175,17 +8175,12 @@ __metadata: version: 0.0.0-use.local resolution: "@uppy-example/python-xhr@workspace:examples/python-xhr" dependencies: - "@babel/core": ^7.4.4 "@uppy/core": "workspace:*" "@uppy/dashboard": "workspace:*" "@uppy/webcam": "workspace:*" "@uppy/xhr-upload": "workspace:*" - babelify: ^10.0.0 - budo: ^11.3.2 - cookie-parser: ^1.4.6 - cors: ^2.8.4 - formidable: ^1.2.1 npm-run-all: ^4.1.3 + vite: ^3.0.0 languageName: unknown linkType: soft @@ -13695,7 +13690,7 @@ __metadata: languageName: node linkType: hard -"cors@npm:^2.8.4, cors@npm:^2.8.5, cors@npm:latest, cors@npm:~2.8.5": +"cors@npm:^2.8.5, cors@npm:latest, cors@npm:~2.8.5": version: 2.8.5 resolution: "cors@npm:2.8.5" dependencies: @@ -18479,13 +18474,6 @@ __metadata: languageName: node linkType: hard -"formidable@npm:^1.2.1": - version: 1.2.6 - resolution: "formidable@npm:1.2.6" - checksum: 2b68ed07ba88302b9c63f8eda94f19a460cef6017bfda48348f09f41d2a36660c9353137991618e0e4c3db115b41e4b8f6fa63bc973b7a7c91dec66acdd02a56 - languageName: node - linkType: hard - "formidable@npm:^2.0.1": version: 2.0.1 resolution: "formidable@npm:2.0.1"