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

feat: python projects #514

Merged
merged 33 commits into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
b147e95
feat: python project
Chriscbr Jan 23, 2021
9fefeff
add unit test
Chriscbr Jan 23, 2021
145a509
add more tests
Chriscbr Jan 23, 2021
85fcc85
add some tasks
Chriscbr Jan 23, 2021
a02ae10
add docs, addEnvTask
Chriscbr Jan 23, 2021
27e7621
add sample files
Chriscbr Jan 23, 2021
d8a57d9
Add rest of sample files
Chriscbr Jan 24, 2021
6a3e227
simplify error msg
Chriscbr Jan 24, 2021
5b9e820
add some docs
Chriscbr Jan 24, 2021
af1390b
add docs, refactor a bunch of things
Chriscbr Jan 25, 2021
e312744
cleanup
Chriscbr Jan 25, 2021
e3c9a38
Merge branch 'master' into feat/python-project
Chriscbr Jan 28, 2021
13dfe3f
add initial setuptools support
Chriscbr Jan 31, 2021
266fd6b
fix bug
Chriscbr Jan 31, 2021
c9bcfe3
Merge branch 'master' into feat/python-project
Chriscbr Jan 31, 2021
cb7510e
building out poetry component
Chriscbr Jan 31, 2021
13f658c
poetry env and deps basics working
Chriscbr Feb 1, 2021
ddd8717
fix test task not working
Chriscbr Feb 1, 2021
e7771cd
commit suggestions to docs/python.md
Chriscbr Feb 1, 2021
335b1a3
add docs and incorporate other feedback
Chriscbr Feb 2, 2021
3bf98b1
add proper packaging and uploading support for poetry
Chriscbr Feb 2, 2021
02156eb
update docs and some unit tests
Chriscbr Feb 2, 2021
8050ef4
Merge branch 'master' into feat/python-project
Chriscbr Feb 3, 2021
0a6ee72
remove pythonPath option
Chriscbr Feb 3, 2021
729a967
combine packaging options into a single interface
Chriscbr Feb 3, 2021
d33ae44
fix docs
Chriscbr Feb 3, 2021
39cbbcc
revert change to new.test.ts
Chriscbr Feb 3, 2021
16ace94
resolve comments
Chriscbr Feb 4, 2021
6fd9899
add a pytest option as an example
Chriscbr Feb 4, 2021
f327f52
bug fix so users don't have to specify description
Chriscbr Feb 4, 2021
2a0bd5b
remove references to pythonpath
Chriscbr Feb 4, 2021
c8fbe27
more docs edits
Chriscbr Feb 4, 2021
d226bb3
Merge branch 'main' into feat/python-project
mergify[bot] Feb 4, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
building out poetry component
  • Loading branch information
Chriscbr committed Jan 31, 2021
commit cb7510e547c0c0ca89fd91b56c56178c4d9826e7
183 changes: 181 additions & 2 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ Name|Description
[java.Pom](#projen-java-pom)|A Project Object Model or POM is the fundamental unit of work in Maven.
[java.Projenrc](#projen-java-projenrc)|Allows writing projenrc files in java.
[python.Pip](#projen-python-pip)|*No description*
[python.Poetry](#projen-python-poetry)|*No description*
[python.PoetryPyproject](#projen-python-poetrypyproject)|Represents configuration of a pyproject.toml file for a Poetry project.
[python.Pytest](#projen-python-pytest)|*No description*
[python.PythonProject](#projen-python-pythonproject)|Python project.
[python.PythonSample](#projen-python-pythonsample)|Python code sample.
Expand Down Expand Up @@ -159,6 +161,8 @@ Name|Description
[java.ProjenrcCommonOptions](#projen-java-projenrccommonoptions)|Options for `Projenrc`.
[java.ProjenrcOptions](#projen-java-projenrcoptions)|*No description*
[python.PipOptions](#projen-python-pipoptions)|*No description*
[python.PoetryOptions](#projen-python-poetryoptions)|*No description*
[python.PoetryPyprojectOptions](#projen-python-poetrypyprojectoptions)|*No description*
[python.PytestOptions](#projen-python-pytestoptions)|*No description*
[python.PythonProjectOptions](#projen-python-pythonprojectoptions)|Options for `PythonProject`.
[python.PythonSampleOptions](#projen-python-pythonsampleoptions)|Options for python sample code.
Expand Down Expand Up @@ -4770,6 +4774,140 @@ installDependencies(): void



## class Poetry 🔹 <a id="projen-python-poetry"></a>



__Implements__: [python.IPythonDeps](#projen-python-ipythondeps), [python.IPythonEnv](#projen-python-ipythonenv), [python.IPythonPackaging](#projen-python-ipythonpackaging)
__Submodule__: python

__Extends__: [Component](#projen-component)

### Initializer




```ts
new python.Poetry(project: PythonProject, _options: PoetryOptions)
```

* **project** (<code>[python.PythonProject](#projen-python-pythonproject)</code>) *No description*
* **_options** (<code>[python.PoetryOptions](#projen-python-poetryoptions)</code>) *No description*



### Properties


Name | Type | Description
-----|------|-------------
**installTask**🔹 | <code>[tasks.Task](#projen-tasks-task)</code> | <span></span>

### Methods


#### addDependency(spec)🔹 <a id="projen-python-poetry-adddependency"></a>

Adds a runtime dependency.

```ts
addDependency(spec: string): void
```

* **spec** (<code>string</code>) Format `<module>@<semver>`.




#### addDevDependency(spec)🔹 <a id="projen-python-poetry-adddevdependency"></a>

Adds a dev dependency.

```ts
addDevDependency(spec: string): void
```

* **spec** (<code>string</code>) Format `<module>@<semver>`.




#### installDependencies()🔹 <a id="projen-python-poetry-installdependencies"></a>

Installs dependencies (called during post-synthesis).

```ts
installDependencies(): void
```





#### setupEnvironment()🔹 <a id="projen-python-poetry-setupenvironment"></a>

Initializes the virtual environment if it doesn't exist (called during post-synthesis).

```ts
setupEnvironment(): void
```







## class PoetryPyproject 🔹 <a id="projen-python-poetrypyproject"></a>

Represents configuration of a pyproject.toml file for a Poetry project.

__Submodule__: python

__Extends__: [Component](#projen-component)

### Initializer




```ts
new python.PoetryPyproject(project: PythonProject, options: PoetryPyprojectOptions)
```

* **project** (<code>[python.PythonProject](#projen-python-pythonproject)</code>) *No description*
* **options** (<code>[python.PoetryPyprojectOptions](#projen-python-poetrypyprojectoptions)</code>) *No description*
* **dependencies** (<code>Map<string, string></code>) A list of dependencies for the project.
* **description** (<code>string</code>) A short description of the package.
* **devDependencies** (<code>Map<string, string></code>) A list of development dependencies for the project.
* **name** (<code>string</code>) Name of the package.
* **scripts** (<code>Map<string, string></code>) The scripts or executables that will be installed when installing the package.
* **version** (<code>string</code>) Version of the package.
* **authors** (<code>Array<string></code>) The authors of the package. __*Optional*__
* **classifiers** (<code>Array<string></code>) A list of PyPI trove classifiers that describe the project. __*Optional*__
* **documentation** (<code>string</code>) A URL to the documentation of the project. __*Optional*__
* **exclude** (<code>Array<string></code>) A list of patterns that will be excluded in the final package. __*Optional*__
* **homepage** (<code>string</code>) A URL to the website of the project. __*Optional*__
* **include** (<code>Array<string></code>) A list of patterns that will be included in the final package. __*Optional*__
* **keywords** (<code>Array<string></code>) A list of keywords (max: 5) that the package is related to. __*Optional*__
* **license** (<code>string</code>) License of this package as an SPDX identifier. __*Optional*__
* **maintainers** (<code>Array<string></code>) the maintainers of the package. __*Optional*__
* **packages** (<code>Array<string></code>) A list of packages and modules to include in the final distribution. __*Optional*__
* **readme** (<code>string</code>) The name of the readme file of the package. __*Optional*__
* **repository** (<code>string</code>) A URL to the repository of the project. __*Optional*__



### Properties


Name | Type | Description
-----|------|-------------
**file**🔹 | <code>[TomlFile](#projen-tomlfile)</code> | <span></span>



## class Pytest 🔹 <a id="projen-python-pytest"></a>


Expand Down Expand Up @@ -4840,6 +4978,7 @@ new python.PythonProject(options: PythonProjectOptions)
* **homepage** (<code>string</code>) The project's homepage / website. __*Optional*__
* **license** (<code>string</code>) The project license. __*Optional*__
* **pip** (<code>boolean</code>) Use pip with a requirements.txt file to track project dependencies. __*Default*__: true
* **poetry** (<code>boolean</code>) Use poetry to manage your project dependencies, virtual environment, and (optional) packaging. __*Default*__: false
* **pytest** (<code>boolean</code>) Include pytest tests. __*Default*__: true
* **pytestOptions** (<code>[python.PytestOptions](#projen-python-pytestoptions)</code>) pytest options. __*Default*__: defaults
* **sample** (<code>boolean</code>) Include sample code and test if the relevant directories don't exist. __*Optional*__
Expand Down Expand Up @@ -8577,7 +8716,7 @@ Name | Type | Description

## interface IPythonDeps 🔹 <a id="projen-python-ipythondeps"></a>

__Implemented by__: [python.Pip](#projen-python-pip)
__Implemented by__: [python.Pip](#projen-python-pip), [python.Poetry](#projen-python-poetry)


### Methods
Expand Down Expand Up @@ -8625,7 +8764,7 @@ installDependencies(): void

## interface IPythonEnv 🔹 <a id="projen-python-ipythonenv"></a>

__Implemented by__: [python.Venv](#projen-python-venv)
__Implemented by__: [python.Poetry](#projen-python-poetry), [python.Venv](#projen-python-venv)


### Methods
Expand All @@ -8647,6 +8786,7 @@ setupEnvironment(): void

## interface IPythonPackaging 🔹 <a id="projen-python-ipythonpackaging"></a>

__Implemented by__: [python.Poetry](#projen-python-poetry)



Expand All @@ -8657,6 +8797,42 @@ setupEnvironment(): void



## struct PoetryOptions 🔹 <a id="projen-python-poetryoptions"></a>





## struct PoetryPyprojectOptions 🔹 <a id="projen-python-poetrypyprojectoptions"></a>






Name | Type | Description
-----|------|-------------
**dependencies**🔹 | <code>Map<string, string></code> | A list of dependencies for the project.
**description**🔹 | <code>string</code> | A short description of the package.
**devDependencies**🔹 | <code>Map<string, string></code> | A list of development dependencies for the project.
**name**🔹 | <code>string</code> | Name of the package.
**scripts**🔹 | <code>Map<string, string></code> | The scripts or executables that will be installed when installing the package.
**version**🔹 | <code>string</code> | Version of the package.
**authors**?🔹 | <code>Array<string></code> | The authors of the package.<br/>__*Optional*__
**classifiers**?🔹 | <code>Array<string></code> | A list of PyPI trove classifiers that describe the project.<br/>__*Optional*__
**documentation**?🔹 | <code>string</code> | A URL to the documentation of the project.<br/>__*Optional*__
**exclude**?🔹 | <code>Array<string></code> | A list of patterns that will be excluded in the final package.<br/>__*Optional*__
**homepage**?🔹 | <code>string</code> | A URL to the website of the project.<br/>__*Optional*__
**include**?🔹 | <code>Array<string></code> | A list of patterns that will be included in the final package.<br/>__*Optional*__
**keywords**?🔹 | <code>Array<string></code> | A list of keywords (max: 5) that the package is related to.<br/>__*Optional*__
**license**?🔹 | <code>string</code> | License of this package as an SPDX identifier.<br/>__*Optional*__
**maintainers**?🔹 | <code>Array<string></code> | the maintainers of the package.<br/>__*Optional*__
**packages**?🔹 | <code>Array<string></code> | A list of packages and modules to include in the final distribution.<br/>__*Optional*__
**readme**?🔹 | <code>string</code> | The name of the readme file of the package.<br/>__*Optional*__
**repository**?🔹 | <code>string</code> | A URL to the repository of the project.<br/>__*Optional*__



## struct PytestOptions 🔹 <a id="projen-python-pytestoptions"></a>


Expand Down Expand Up @@ -8697,6 +8873,7 @@ Name | Type | Description
**outdir**?🔹 | <code>string</code> | The root directory of the project.<br/>__*Default*__: "."
**parent**?🔹 | <code>[Project](#projen-project)</code> | The parent project, if this project is part of a bigger project.<br/>__*Optional*__
**pip**?🔹 | <code>boolean</code> | Use pip with a requirements.txt file to track project dependencies.<br/>__*Default*__: true
**poetry**?🔹 | <code>boolean</code> | Use poetry to manage your project dependencies, virtual environment, and (optional) packaging.<br/>__*Default*__: false
**projectType**?🔹 | <code>[ProjectType](#projen-projecttype)</code> | Which type of project this is (library/app).<br/>__*Default*__: ProjectType.UNKNOWN
**pytest**?🔹 | <code>boolean</code> | Include pytest tests.<br/>__*Default*__: true
**pytestOptions**?🔹 | <code>[python.PytestOptions](#projen-python-pytestoptions)</code> | pytest options.<br/>__*Default*__: defaults
Expand Down Expand Up @@ -8733,10 +8910,12 @@ Name | Type | Description
-----|------|-------------
**authorEmail**?🔹 | <code>string</code> | Author's e-mail.<br/>__*Optional*__
**authorName**?🔹 | <code>string</code> | Author's name.<br/>__*Optional*__
**classifiers**?🔹 | <code>Array<string></code> | A list of PyPI trove classifiers that describe the project.<br/>__*Optional*__
**description**?🔹 | <code>string</code> | A short project description.<br/>__*Optional*__
**homepage**?🔹 | <code>string</code> | Package's Homepage / Website.<br/>__*Optional*__
**license**?🔹 | <code>string</code> | The project license.<br/>__*Optional*__
**name**?🔹 | <code>string</code> | Name of the package.<br/>__*Optional*__
**packages**?🔹 | <code>Array<string></code> | List of submodules to be packaged.<br/>__*Optional*__
**version**?🔹 | <code>string</code> | Manually specify package version.<br/>__*Optional*__


Expand Down
12 changes: 12 additions & 0 deletions src/__tests__/__snapshots__/inventory.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8075,6 +8075,18 @@ Array [
"switch": "pip",
"type": "boolean",
},
Object {
"default": "false",
"docs": "Use poetry to manage your project dependencies, virtual environment, and (optional) packaging.",
"name": "poetry",
"optional": true,
"parent": "PythonProjectOptions",
"path": Array [
"poetry",
],
"switch": "poetry",
"type": "boolean",
},
Object {
"default": "ProjectType.UNKNOWN",
"docs": "Which type of project this is (library/app).",
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/__snapshots__/new.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,7 @@ const project = new python.PythonProject({
// homepage: undefined, /* The project's homepage / website. */
// license: undefined, /* The project license. */
// pip: true, /* Use pip with a requirements.txt file to track project dependencies. */
// poetry: false, /* Use poetry to manage your project dependencies, virtual environment, and (optional) packaging. */
// pytest: true, /* Include pytest tests. */
// pytestOptions: undefined, /* pytest options. */
// sample: undefined, /* Include sample code and test if the relevant directories don't exist. */
Expand Down
30 changes: 30 additions & 0 deletions src/__tests__/python/poetry.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { LogLevel } from '../../logger';
import { PythonProject, PythonProjectOptions } from '../../python';
import { mkdtemp, synthSnapshot } from '../util';

test('poetry enabled', () => {
const p = new TestPythonProject({
poetry: true,
authorEmail: 'foo@example.com',
authorName: 'Firstname Lastname',
homepage: 'http://www.example.com',
description: 'a short project description',
license: 'Apache Software License',
});

expect(synthSnapshot(p)).toMatchSnapshot();
});

class TestPythonProject extends PythonProject {
constructor(options: Partial<PythonProjectOptions> = { }) {
super({
...options,
clobber: false,
name: 'test-python-project',
pythonPath: '/usr/bin/python',
outdir: mkdtemp(),
logging: { level: LogLevel.OFF },
jsiiFqn: 'projen.python.PythonProject',
});
}
}
1 change: 1 addition & 0 deletions src/python/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './pip';
export * from './poetry';
export * from './pytest';
export * from './python-env';
export * from './python-deps';
Expand Down
Loading