Skip to content

Commit 15ce38f

Browse files
committed
0.2.0 release
- add option "future" as version - don't allow the update command to run if installed via pip or executable. - add github action to publish to pip when pushing to main branch (and updating packscript.py) - move photos to .github folder
1 parent e2256cb commit 15ce38f

9 files changed

Lines changed: 93 additions & 36 deletions

File tree

.github/workflows/publish.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Publish to PyPI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- packscript.py
9+
jobs:
10+
build-and-publish:
11+
name: Build and publish to PyPI
12+
runs-on: ubuntu-latest
13+
permissions:
14+
id-token: write
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: "3.12.2"
23+
24+
- name: Install build dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install build
28+
29+
- name: Build package
30+
run: python -m build
31+
32+
- name: Publish to PyPI
33+
uses: pypa/gh-action-pypi-publish@release/v1

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55

66
/*.mcfunction
77
/PackScript.code-workspace
8+
.venv

.todo.md

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
2-
1. Overlays
3-
2. Create statements with interpolation
4-
3. Cleaning
5-
4. Temporary Directory? (would avoid errors causing partial output)
6-
5. generic zip or dir (make archive without dir at all)
7-
6. highlight backslashes
8-
7. Add more tests for each feature/command
9-
8. make the mod print errors from loading datapack
10-
9. entrypoint?
11-
10. edit/get statement?
12-
11. import via making python files and running them that way
1+
This document is to keep track of potential changes, nothing here is guaranteed to come later.
2+
1. Temporary Directory? (would avoid errors causing partial output)
3+
2. generic zip or dir (make archive without dir at all)
4+
3. Add more tests for each feature/command
5+
4. make the reloader mod print errors from loading datapack
6+
5. entrypoint?
7+
6. import via making python files and running them that way
8+
7. labeled lines/find and replace?

README.md

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ and generate any other kind of file (especially JSON) easily.
2121
There is an associated syntax highlighter for VSCode with this project.
2222
Get it [here](https://marketplace.visualstudio.com/items?itemName=Slackow.ps-support).
2323

24-
![packscript_ex](photos/packscript_ex.png)
24+
![packscript_ex](.github/photos/packscript_ex.png)
2525

2626
# Constructs
2727

@@ -229,9 +229,9 @@ function example_pack:say_something
229229

230230
# Example Usage + PackScript Reloader
231231

232-
![packscript_ex1](photos/packscript_ex2.png)
232+
![packscript_ex1](.github/photos/packscript_ex2.png)
233233

234-
![minecraft_output](photos/in_game_img.png)
234+
![minecraft_output](.github/photos/in_game_img.png)
235235

236236
This was used with the associated [packscript_reloader](https://github.com/Slackow/packscript_reloader) fabric mod.
237237
This mod works on snapshots, and will automatically compile packs under the `dev` directory in the world into the
@@ -244,7 +244,7 @@ replaces to turn your invalid Python code
244244
into valid Python code, and then executing it.
245245
You can see this when you compile in verbose mode:
246246

247-
![packscript_ex2](photos/packscript_ex2.png)
247+
![packscript_ex2](.github/photos/packscript_ex2.png)
248248

249249
turns into
250250

@@ -291,14 +291,15 @@ as the main generated function.
291291

292292
# The CLI
293293
This tool has two main actions it can perform: compiling packs and initializing templates.
294-
- `python3 packscript.py c` (you can also use compile or comp)
295-
- `python3 packscript.py init`
294+
- `packscript c` (you can also use compile or comp)
295+
- `packscript init`
296296

297297
More actions:
298-
- `python3 packscript.py --help` list general help
299-
- `python3 packscript.py --version` print the version of packscript
300-
- `python3 packscript.py c --help` print the help for compiling
301-
- `python3 packscript.py init --help` print the help for initializing a datapack
298+
- `packscript --help` list general help
299+
- `packscript --version` print the version of packscript
300+
- `packscript c --help` print the help for compiling
301+
- `packscript init --help` print the help for initializing a datapack
302+
- `packscript pf` edit and view the pack_format(s) supported by your datapack, you can use recognized version numbers directly
302303
## Compile Options
303304
- `-i/--input <dir>` specify the directory of the pack you are compiling defaults to current dir.
304305
- `-o/--output <dir/zip>` specify the output of the pack (can output zip too) defaults to `output`
@@ -311,11 +312,11 @@ using this action.
311312

312313
You can also specify options using flags
313314

314-
ex: `python3 packscript.py init --output "Datapack" --name "Datapack" --namespace "main" --description "Datapack for version 1.20.4" --pack-format 26`
315+
ex: `packscript init --output "Datapack" --name "Datapack" --namespace "main" --description "Datapack for version 1.20.4" --pack-format 26`
315316

316317
it's preferable to do just call the following instead:
317318

318-
`python3 packscript.py init`
319+
`packscript init`
319320

320321
## Compile Action
321322
When a PackScript file is being compiled it will first print its location to the console, this is so if an error is encountered
@@ -346,12 +347,10 @@ In this case it's because there's a letter before the command line, making it ge
346347
# Get Started
347348
1. **Install Python.** Get [Python3](https://www.python.org/downloads/) and
348349
make sure it's in your path. (You can check by running `python3 -V` in your terminal)
349-
2. **Download PackScript.** You can find `packscript.py`
350-
[here](https://github.com/Slackow/PackScript/releases/latest)
351-
3. **Setup Environment.** Place the `packscript.py` file into your working directory
352-
4. **Create A Datapack.** Run `python3 packscript.py init` in order to create a datapack with
350+
2. **Download/Install PackScript.** run `pip3 install packscript`, or directly use the `packscript.py` file in releases, and use `python3 packscript.py` instead of `packscript`
351+
3. **Create a Datapack.** Run `packscript init` in order to create a datapack with
353352
PackScript. You'll be prompted for information about the datapack.
354353
You should have a new datapack, you can put files in there as usual for them to
355354
be outputted, files in `<pack>/data/*/source/*.dps` and `<pack>/*.fps` will be interpreted as PackScript
356355
on compilation. By default, you will find a main.dps file there.
357-
5. **Compile Datapack.** To compile, run `python3 packscript.py compile -i <datapack directory> -o <output>`
356+
4. **Compile Datapack.** To compile, run `packscript compile -i <datapack directory> -o <output>`

packscript.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
# /// script
44
# requires-python = ">=3.12"
55
# ///
6-
__version__ = '0.1.6'
7-
__v_type__ = 'dev'
6+
__version__ = '0.2.0'
7+
__v_type__ = 'release'
88
__author__ = 'Slackow'
99
__license__ = 'MIT'
1010

@@ -25,6 +25,7 @@ def ver(base_version, start, end, *, pf):
2525

2626

2727
pack_formats = {
28+
'future': 9001,
2829
'1.21.4': 61,
2930
'1.21.3': 57, '1.21.2': 57,
3031
'1.21.1': 48, '1.21': 48,
@@ -147,7 +148,8 @@ def __getattr__(self, attr: str):
147148
return Dp((*self._type, attr))
148149
def __setattr__(self, attr: str, value: dict | list | str | bytes):
149150
if attr == '_type':
150-
return object.__setattr__(self, attr, value)
151+
object.__setattr__(self, attr, value)
152+
return
151153
other.setdefault('/'.join(self._type), {})[n(attr)] = value
152154
def __delattr__(self, item):
153155
other['/'.join(self._type)].pop(n(item))
@@ -230,7 +232,7 @@ def comp_file(parent: Path, filename: Path, globals: dict[str, object], verbose=
230232
create_match = create_statement_re.fullmatch(line)
231233
if create_match:
232234
indent, file_type, name, data = create_match.groups()
233-
name = ns(name, default=globals['ns'])
235+
name = ns(name, default=str(globals['ns']))
234236
code.append(f'{indent}__other__("{file_type}")["{name}"] ={data}')
235237
else:
236238
code.append(line)
@@ -270,7 +272,7 @@ def comp_pack(output_folder, pack_format, source, verbose):
270272
(namespace / 'sources').exists()):
271273
raise ValueError('Legacy "sources" folder detected! Rename your folders to be singular!')
272274

273-
for filename in working_folder.rglob(f'*.{DATA_EXT}'):
275+
for filename in sorted(working_folder.rglob(f'*.{DATA_EXT}')):
274276
comp_file(working_folder, filename, globals, verbose=verbose)
275277

276278
if not source:
@@ -367,7 +369,7 @@ def comp(*, input: str, output: str, verbose: bool, source: bool, **_):
367369
shutil.rmtree(output_folder)
368370

369371
func_files = {}
370-
for f in input.glob(f'*.{FUNC_EXT}'):
372+
for f in sorted(input.glob(f'*.{FUNC_EXT}')):
371373
func_stack = [f.name]
372374
func_files[f.name] = []
373375
globals = build_globals(func_stack, [], func_files, {})
@@ -442,6 +444,7 @@ def update_pack_format(*, input: str, target: str, min: str, max: str, **_):
442444
(input / 'pack.mcmeta').write_text(json.dumps(pack_meta, indent=4))
443445
else:
444446
target, min, max = target_pack_format, min_pack_format, max_pack_format
447+
print('edit these values via the --min, --target, or --max options')
445448

446449
def versions_of(pf):
447450
return f"({', '.join(key for key, value in pack_formats.items() if value == pf)})"
@@ -471,7 +474,7 @@ def get_data_from_url(url: str, default_context=True, max_redirects=10):
471474
headers = {'Accept': '*/*', 'User-Agent': 'packscript.py'}
472475
connection.request('GET', path, headers=headers)
473476
response = connection.getresponse()
474-
if response.status in range(300, 400) and max_redirects > 0:
477+
if 300 <= response.status < 400 and max_redirects > 0:
475478
return get_data_from_url(response.getheader('Location'), default_context, max_redirects - 1)
476479
return response
477480

@@ -504,6 +507,10 @@ def replace_script_with_latest():
504507

505508

506509
def update():
510+
if __package__ is not None or getattr(sys, 'frozen', False):
511+
print('You are using pip or the script is otherwise frozen! Cannot update.')
512+
print('To update the package via pip use "pip install --upgrade packscript"' + ("" if __package__ is not None else "!"))
513+
return
507514
latest = get_latest_version()
508515
if latest == __version__:
509516
print(f"Up to date, PackScript {__version__}")

pyproject.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[build-system]
2+
requires = ["setuptools>=61.0"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "packscript"
7+
dynamic = ["version", "authors", "license"]
8+
requires-python = ">=3.12"
9+
readme = {file = "README.md", content-type = "text/markdown"}
10+
keywords = ["packscript", "mcfunction", "datapack", "pack.mcmeta", "nbt", "templating", "language"]
11+
12+
[project.scripts]
13+
packscript = "packscript:main"
14+
15+
[tool.setuptools]
16+
py-modules = ["packscript"]
17+
18+
[tool.setuptools.dynamic]
19+
version = {attr = "packscript.__version__"}
20+
license = {attr = "packscript.__license__"}
21+
authors = [{name = {attr = "packscript.__author__"}}]

0 commit comments

Comments
 (0)